WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Menu String


Question:

Can you help me? I use Window XP and want to read Menu and Submenu Text from Notepad.

Answer:

This gets the &Open item from the File menu.
Editor = '~Notepad'
User32 = StrCat(DirWindows(1), 'User32.dll')
If !WinExist(Editor) Then Run('Notepad', '')
TimeDelay(1)
hEdit = DllHwnd(Editor)

hMenu = DllCall(User32, long:"GetMenu", long:hEdit)
Pause(`DEBUG PAUSE`, StrCat(`hEdit = `, hEdit, @CRLF, `hMenu = `, hMenu, @CRLF)) ;***DEBUG LINE***

Cnts = DllCall(User32, long:"GetMenuItemCount", long:hMenu)-1
hSubs = ''
For Cnt = 0 To Cnts
hSub = DllCall(User32, long:"GetSubMenu", long:hMenu, long:Cnt)
hSubs = ItemInsert(hSub, -1, hSubs, @TAB)
Next
Pause(`DEBUG PAUSE`, StrCat(`hSubs = `, @CRLF, StrReplace(hSubs, @TAB, @CRLF)))

bb = BinaryAlloc(64)
; MF_BYPOSITION = &H400& = 1024
; int GetMenuString(
; HMENU hMenu, // handle to the menu
; UINT uIDItem, // menu item identifier
; LPTSTR lpString, // pointer to the buffer for the string
; int nMaxCount, // maximum length of the string
; UINT uFlag // menu flags
; );
hFile = ItemExtract(1, hSubs, @TAB)
Len = DllCall(User32, long:"GetMenuStringA", long:hFile, long:1, lpbinary:bb, long:64, long:1024)
BinaryEodSet(bb, Len)
Str = BinaryPeekStr(bb, 0, Len)
BinaryFree(bb)
Pause(`DEBUG PAUSE`, StrCat(`hFile = `, hFile, @CRLF, `Len = `, Len, @CRLF, `Str = `, Str, @CRLF)) ;***DEBUG LINE***

Exit

Article ID:   W17001
File Created: 2007:07:03:14:27:32
Last Updated: 2007:07:03:14:27:32