Interrogate Applications for Menu Entries and extract Short Cut Keys?

S

Siegfried Heintze

Let's pretend I have a touch sensitve LCD display and I want to draw the
outline of a standard QWERTY keyboard on it.

How would I write a C# program that would
(1) Detect the application that a main window that has focus
(2) Detect the path and file name of the exe of the program running that
window
(3) Enumerate the menu entries and extract the short cut keys so I may
dynamically display them on my key caps?

Are menu entries just windows? If so, there is a great book called
"Effective GUI Test Automation" that shows how to enumerate all the buttons
and other controls on another running application so you simulate pressing
them. But the author does not address menu entries. Can someone help me
write a program that will interrogate another application for all the menu
entries and extract the short cut keys?

Now how about accelerator keys? Can I write a program to get all the
accellerator keys of another running applications?

Thanks,
Siegfried
 
F

Family Tree Mike

Siegfried Heintze said:
Let's pretend I have a touch sensitve LCD display and I want to draw the
outline of a standard QWERTY keyboard on it.

How would I write a C# program that would
(1) Detect the application that a main window that has focus
(2) Detect the path and file name of the exe of the program running that
window
(3) Enumerate the menu entries and extract the short cut keys so I may
dynamically display them on my key caps?

Are menu entries just windows? If so, there is a great book called
"Effective GUI Test Automation" that shows how to enumerate all the buttons
and other controls on another running application so you simulate pressing
them. But the author does not address menu entries. Can someone help me
write a program that will interrogate another application for all the menu
entries and extract the short cut keys?

Now how about accelerator keys? Can I write a program to get all the
accellerator keys of another running applications?

Thanks,
Siegfried

(1) http://www.pinvoke.net/default.aspx/user32/GetForegroundWindow.html
(2) The sample code at the same url finds the process. After that, you can
use the properties of the process to get the path and executable name
depending on access rights.
(3) No clue, but probably requires p/invoke as above.
 
K

Kenneth Cochran

Siegfried said:
Let's pretend I have a touch sensitve LCD display and I want to draw the
outline of a standard QWERTY keyboard on it.

How would I write a C# program that would
(1) Detect the application that a main window that has focus
GetTopWindow(null)

(2) Detect the path and file name of the exe of the program running that
window
(3) Enumerate the menu entries and extract the short cut keys so I may
dynamically display them on my key caps?

EnumChildWindows() will get you all visible UI elements, including
top-level menu items. I don't know if this includes sub menus. I haven't
tried this. My guess is they don't exist until their parent menu is
clicked. Same would go for Nth level menus.

Then GetWindowText() should be able to capture the menu text.
Are menu entries just windows? If so, there is a great book called
"Effective GUI Test Automation" that shows how to enumerate all the buttons
and other controls on another running application so you simulate pressing
them. But the author does not address menu entries. Can someone help me
write a program that will interrogate another application for all the menu
entries and extract the short cut keys?

Now how about accelerator keys? Can I write a program to get all the
accellerator keys of another running applications?

I don't know about this one. You should be able to get some from the
menu text but not all accellerator keys are associated with menu items.
Thanks,
Siegfried

These are all low level WinAPI calls. To my knowledge there are no
existing .NET classes to help you with this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top