PDA

View Full Version : Enabling menu item in delphi target ?


MrSmith
December 3rd, 2001, 08:35
Hi,

I'm working on a program, written in Delphi4, where I would like to enable a disabled menu item (printing).
First I used Restorator to look into the resources. There the menu item was not marked as disabled and so I thought it must be disabled somewhere in the program code.
Therefore I used Dede to disassemble the Delphi program. I found the formCreate event for the form, which defines the menu and disassembled it. But unfortunately I didn't find a call which disables the menu item :-(

I'm not a Delphi expert, so how would the menu item be disabled in Delphi ?
Has it do be inside the formCreate event or can it be somewhere else ?
Is there a recommended way for enabling disabled menu items ?

Cheers,

MrSmith

4oh4
December 4th, 2001, 15:14
Just in case you didn't see it, I replied to your dup post in the newbies forum. I'm not sure how informative it is though.

I wish I had a delphi example (or could code one) with runtime menu disabling, but the closest thing I can give you is a link (hxxp://www.undu.com/DN961101/00000015.htm) which is really to the point and gives you a nice short example of this. I'm not exactly sure how delphi code gets translated into api calls and what not, if it's similar to vb or whatever. But I'd imagine that a "mniUndo.Enabled" translates into a call to EnableMenuItem or one of the other menu apis. Per the win32api help file:
"The CreateMenu, InsertMenu, InsertMenuItem, LoadMenuIndirect, ModifyMenu, and SetMenuItemInfo functions can also set the state (enabled, disabled, or grayed) of a menu item."

So what I'd suggest is to fire up apispy and filter on all the menu apis. It's a LOT quicker than sice to spy on runtime menu handling believe me. Then find out which of the apis is used to disable the menu item(s) in question and look up the params of that api. Then handle it from there. For example, if it uses EnableMenuItem, check the uEnable param for MF_DISABLED and/or MF_GRAYED (some people use both flags even though MF_GRAYED disables AND grays it....weird) and patch it out with an MF_ENABLED (0h I believe) and don't forget to add the constant of BY_COMMAND/BY_POSITION if the program uses one of those flags as well. I think kayaker or maybe it was Lord Soth wrote an excellent essay on menu reversing. If you can't find it I'll grab it off the rce cd and ul it for you.

Man, I didn't intend to type all of that but I got tired of seeing your post with lots of views but no replies. If I wasn't so unsure of my knowledge of delphi, I'd have gotten off my ass and given you a better reply the first time.

Shit, now we've got two threads in two forums..... Ah hell, I'll leave that for the mods to deal with.