vb 用api函数getmenu和getsubmenu获取vmware菜单返回值为0

图片说明
Option Explicit
Private Declare Function GetMenu Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetMenuItemID Lib "user32.dll" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetSubMenu Lib "user32.dll" (ByVal hMenu As Long, ByVal nPos As Long) As Long

Private Const WM_COMMAND As Long = &H111

Private Sub Command1_Click()

   Dim h1 As Long, h2   As Long, id  As Long
   h1 = FindWindow(vbNullString, "Windows XP Professional - VMware Workstation")

   h2 = GetMenu(h1)          '到这里就不行了,h2返回值是0
   h2 = GetSubMenu(h2, 2)
   id = GetMenuItemID(h2, 1)
   SendMessage h1, WM_COMMAND, id, ByVal 0&

End Sub

1个回答

说明它的菜单不是windows标准的菜单,而是自己实现的,所以用GetWindow而不是用GetMenu/GetSubMenu

weixin_44866220
weixin_44866220 回复weixin_44866220: Private Sub Command1_Click() Dim h1 As Long, h2 As Long, id As Long h1 = FindWindow(vbNullString, "Windows XP Professional - VMware Workstation") h1 = FindWindowEx(h1, 0, "vmware.fullScreenToolbar", "") h1 = FindWindowEx(h1, 0, "wui.unibar.Bar", "vmFullScreenUnibar") h1 = FindWindowEx(h1, 0, "wui.unibar.Toolbar", "") h2 = GetWindow(h1, GW_CHILD) '到这里还不行,h2返回值是0 'h2 = GetMenu(h1) '到这里就不行了,h2返回值是0 'SendMessage h1, WM_COMMAND, id, ByVal 0& MsgBox h2 End Sub
一年多之前 回复
weixin_44866220
weixin_44866220 我的声明:Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long Private Const GW_CHILD As Long = &H5
一年多之前 回复
weixin_44866220
weixin_44866220 我用getwindows一层层找进去,查得目标菜单栏的名句柄是00131818,但我用“抓抓”查的目标菜单栏句柄是00131810。还是没法获得菜单里的选项。还请多指教,谢谢!
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐