Hola a todos.
Tengo un formulario en Visual basic con unos menus y submenús agregados desde el editor de menus. Mi problema es el siguiente:
¿Como puedo saber por código si un menu tiene un submenu dentro de él?
Gracias
| |||
Re: Editor de Menus Eso lo debes de saber por el name e index del menú. Cuando creas el menú tienes: Captión Name Index Bueno hay mas pero no me meto mas afondo. En el captión es el nombre que se muestra visualmente. El Name es el grupo al que pertenece. El Index es el indice que tiene dentro del grupo. Espero que me entiendas. Un saludo.
__________________ Aprende a programar desde cero !!! |
| ||||
Re: Editor de Menus El problema es que estoy trabajando sobre una aplicación ya desarrollada a la que se le van añadiendo modulos, y necesitaría obtener mediante código aquellas opciones del menú que van a un programa y cuales son padres del menú. |
| |||
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. |
| ||||
Re: Editor de Menus Gracias Boluart por el esfuerzo, pero así sólo recorro el menú, pero no me dice si la opción del menú es un submenú o tiene un código asociado en el form, ya sea para realizar algún bloque de código o para ir a otro formulario. De todas formas muchas gracias de verdad. Llevo ya una semana intentando encontrar algo que me pueda ayudar y es lo primero que encuentro. ![]() |
| ||||
Re: Editor de Menus Bueno retiro lo dicho en el anterior mensaje ![]() ![]() ![]() ![]() De mayor a ver si puedo hacer lo mismo :P |