Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MenuItem Click Event with API

Status
Not open for further replies.

mbu

Technical User
Apr 10, 2004
13
US
So far I can find the exact MenuItem ("&Close") from the "File" menu using the GetMenu, GetSubMenu, GetMenuItemCount and loop through the content of a "File" SubMenu. Now that I found the "&Close" MenuItem (confirmes by the GetMenuString, I want to "simulate" a "Click."

Since the MenuItem has it's ID from GetMenuItemID, how can I find the handle so that I can SendMessage or PostMessage.

Thank you for your time,
Mark
 
Code:
SendMessage(
				hWnd /*Owner of menu*/,
				WM_COMMAND, /*Windows receive this on a menu click*/
				(WPARAM)MAKEWPARAM(menuID,0), /*Make with the menu ID as the low word*/
				(LPARAM)NULL
			);
 
Thank you for your kind reply!!!

The program that I am trying to control has the handel hMainProg. The main Menu has hMenu handle and the Menu ID# 0 is the "File" menu with the handle hFile = GetSubMenu(hMenu, 0). MenuItem ID# 2 in the "File" which has the string "&Close". So, when I want to open the "File" menu, the SendMessage is;

SendMessage(hMainProg, WM_COMMAND, (WPARAM)MAKEWPARAM(0,0), (LPARAM)NULL)

Is it correct?

Mark

What if I want to press the "&Close" MenuItem directly?
 
I forget to mention that I am writing the code in Visual Basic 6.0. I think the code you gave me to try is not in VB and it is not working.

Mark
 
What I posted was Windows API, you'll need to VB-ify it in order to use that. I don't use VB so can't help with that. :-(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top