Ver Mensaje Individual
  #5 (permalink)  
Antiguo 01/06/2007, 15:16
boluart
 
Fecha de Ingreso: enero-2007
Ubicación: Tingo María - Perú
Mensajes: 399
Antigüedad: 18 años, 3 meses
Puntos: 13
Re: Editor de Menus

Seria un poco mas faci si los menus tendrian algun identificador (Hwnd) accesible asi como lo tienen los formularios,botones, etc
pero haber si te sirve de algo:


Código:
 
Option Explicit
Private Const MF_STRING = &H0&
Private Const MIIM_ID = &H2&
Private Const MIIM_SUBMENU = &H4&
Private Const MIIM_TYPE = &H10&
Private Const MIIM_DATA = &H20&
Private Type MENUITEMINFO
    cbSize As Long
    fMask As Long
    fType As Long
    fState As Long
    wID As Long
    hSubMenu As Long
    hbmpChecked As Long
    hbmpUnchecked As Long
    dwItemData As Long
    dwTypeData As String
    cch As Long
End Type
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetMenuItemInfo Lib "user32" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal uItem As Long, ByVal fByPosition As Boolean, lpMenuItemInfo As MENUITEMINFO) As Long
Private Declare Function SetMenuItemInfo Lib "user32" Alias "SetMenuItemInfoA" (ByVal hMenu As Long, ByVal uItem As Long, ByVal fByPosition As Boolean, lpcMenuItemInfo As MENUITEMINFO) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
Private Sub Command1_Click()
    Dim hMenu As Long
    hMenu = GetMenu(Me.hWnd)
    ShowSubMenu hMenu
End Sub
Public Sub ShowSubMenu(hwndMenu As Long)
    Dim tMenuItemInfo As MENUITEMINFO
    Dim strCaption As String, Count As Long, i As Integer, hSubMenu As Long
    Count = GetMenuItemCount(hwndMenu)
    For i = 0 To Count - 1
        tMenuItemInfo.cbSize = Len(tMenuItemInfo)
        tMenuItemInfo.fMask = MIIM_DATA Or MIIM_ID Or MIIM_TYPE
        tMenuItemInfo.fType = MF_STRING
        tMenuItemInfo.cch = 50
        tMenuItemInfo.dwTypeData = String$(tMenuItemInfo.cch, Chr$(0))
        Call GetMenuItemInfo(hwndMenu, i, True, tMenuItemInfo)
        strCaption = Left$(tMenuItemInfo.dwTypeData, tMenuItemInfo.cch)
        MsgBox strCaption
        hSubMenu = GetSubMenu(hwndMenu, i)
        If hSubMenu > 0 Then
            Call ShowSubMenu(hSubMenu)
        End If
    Next
End Sub
__________________
Vivir para ser buenos y ser buenos para servir mejor.