Public Function FindMenu(hMenu As Long, strMenuCaption As String, lpParent As Long, lpPosition As Long) As Boolean ' 函数: FindMenu(),通过menu.caption来识别菜单 ' 目的: 递归寻找一个菜单项 ' 出口: lpParent -- 上级菜单 ' lpPosition -- 菜单项的位置 ' 返回: True -- 找到了 ' False -- 找不到 ' 用法: ' Dim lngParent as long,lngPosition as long ' FindMenu GetMenu(me.hwnd),"Open",lngParent,lngPosition ' debug.print "位置:" ,lngPosition
Dim nCount As Long, i As Long, lngID As Long Dim strFound As String
nCount = GetMenuItemCount(hMenu)
For i = 0 To nCount - 1 strFound = Space(256) GetMenuString hMenu, i, strFound, 256, MF_BYPOSITION strFound = Trim(strFound) strFound = Left(strFound, Len(strFound) - 1)
If strFound = strMenuCaption Then lpParent = hMenu lpPosition = i FindMenu = True Exit Function Else If FindMenu(GetSubMenu(hMenu, i), strMenuCaption, lpParent, lpPosition) Then FindMenu = True Exit Function End If End If Next i End Function
http://topic.csdn.net/t/20020611/13/794545.html所缺的API声明自已加进去,不知道这个函数合不合题意?
Public Function FindMenu(hMenu As Long, strMenuCaption As String, lpParent As Long, lpPosition As Long) As Boolean
' 函数: FindMenu(),通过menu.caption来识别菜单
' 目的: 递归寻找一个菜单项
' 出口: lpParent -- 上级菜单
' lpPosition -- 菜单项的位置
' 返回: True -- 找到了
' False -- 找不到
' 用法:
' Dim lngParent as long,lngPosition as long
' FindMenu GetMenu(me.hwnd),"Open",lngParent,lngPosition
' debug.print "位置:" ,lngPosition
Dim nCount As Long, i As Long, lngID As Long
Dim strFound As String
nCount = GetMenuItemCount(hMenu)
For i = 0 To nCount - 1
strFound = Space(256)
GetMenuString hMenu, i, strFound, 256, MF_BYPOSITION
strFound = Trim(strFound)
strFound = Left(strFound, Len(strFound) - 1)
If strFound = strMenuCaption Then
lpParent = hMenu
lpPosition = i
FindMenu = True
Exit Function
Else
If FindMenu(GetSubMenu(hMenu, i), strMenuCaption, lpParent, lpPosition) Then
FindMenu = True
Exit Function
End If
End If
Next i
End Function