How to retrieve the menu option name? For this example make sure that notepad is open and write the below code in a new test in QTP and run the test.
Const MF_BYPOSITION = 1024
'API Functions Declarations
'The GetMenu function retrieves a handle to the menu assigned to the specified window. It takes one input parameter i.e. Handle to the window whose 'menu handle is to be retrieved. The return value is a handle to the menu. If the specified window has no menu, the return value is NULL.
Extern.Declare micHwnd,"GetMenu","user32.dll","GetMenu",micHwnd
'The GetSubMenu function retrieves a handle to the drop-down menu or submenu activated by the specified menu item. It takes two input parameters, one 'is Handle to the menu, second is the int value which specifies the zero-based relative position in the specified menu of an item that activates a drop-down 'menu or submenu. If the function succeeds, the return value is a handle to the drop-down menu or submenu activated by the menu item.
Extern.Declare micHwnd,"GetSubMenu","user32.dll","GetSubMenu",micHwnd,micInteger
'The GetMenuString function copies the text string of the specified menu item into the specified buffer.
Extern.DeclaremicInteger,"GetMenuString","user32.dll","GetMenuString",micHwnd,micInteger,micString+
micByRef,micInteger, micInteger
'Get Windows handle (Win_Hand), pass it to get Menu handle (menu_hwnd), pass it to get submenu handle (submen_hwnd), pass the submenu handle to get the resultant string.
Win_Hand = Window("text:=Untitled - Notepad").GetROProperty ("hwnd")
menu_hwnd = Extern.GetMenu(Win_Hand)
submen_hwnd = Extern.GetSubMenu(menu_hwnd,0) rc=Extern.GetMenuString(submen_hwnd,0,value,20 ,MF_BYPOSITION)
MsgBox value