GetMenuString fails with Photoshop Menus - any Idea?

Hi folks,

I'm searching a way to get photoshop menu texts with their associated ID, to later call them via PostMessage.

I'm using a scripting language with DllCall abilities, and tried GetMenuString() and GetMenuItemInfo() - neither does work. IDs are retrieved, though. (via GetMenuItemID())

Does someone have an idea or could point me in the right direction?

#476537

I see two problems here:

1.

As with almost all plain vanilla Windows API calls, you must allocate Strings yourself beforehand, e.g. in vb script:

dim s

s=space(256)

Call NiftyObj.DllCall.GetMenuString(hMenu, uiItem, s, len(s))

2.

Unless you don't code a photoshop plugin that runs inside the photoshop process, you can't probably get anything like that because GetMenuString internally boils down to:

LoadResource(GetCurrentProcess(), RT_MENU, ...)

This would be pointless because a resource Handle of some other process is of no use in the scripting engines process.

Obvious exit would be to call LoadResource yourself with the correct process handle, but what do you do when you try to read other process's memory? Yes. Insufficient rights. Access Violation. You name it.

I'm afraid, trying this kinda stuff requires hooking techniques not available to scripting engines or managed runtimes.

Just get the Resource IDs & texts manually with Spy++ or WinSpy (these have the hooks implemented) and invoke them as you planned. Do not try to retrieve alien resource strings -- it is not worth the hassle. The Logging feature of those apps will spill out what to post easily.

hth,

herd

#476731

Thanks for the answer and insights, yes that helped.

I'm trying to put together a little quicksilver-esque program which lets you search incrementally

through the active windows' menu and send a WM_COMMAND message with the associated menu id.

This works flawlessly with standard windows applications, but fails with certain fancy menus.

For Photoshop I went the extra mile and exported the default menu structure via Photoshop itself as a .htm file,

read out the menu IDs and put all this together in a text file which serves as a kind of plugin.

The downside off this is the amount of work to put this file together (and maintain it for different languages),

and the inability to determine the state of menu item (eg. menu items appearing in the list which are MFS_DISABLED or/and MFS_GRAYED)

I'm using AHK, which offers some ways to hook into windows, but I agree that it is not worth the hassle. (I really should get around to actually learn a higher level language.)

Anyways, thanks :)

#476869

Are you doing this in Visual Basic? I've got some code I did a while back for a finderbar clone that can read photoshop menus along with almost every other kind of menu.

For those windows that does have proper handles to the menu or that just return ID's, you can code it to load a custom def file with the strings per application title or class title. So say Photoshop isn't supported,but you see the proc. Load the def file associated with that proc. It's how I was handlig menus not supported by my code.

Anyway, if you need anymore help, I can lend a hand.

#486980