Título: Averiguar el Menu desplegado.
Publicado por: LeandroA en 29 Octubre 2008, 21:31 pm
buenas estoy intentado averiguar si es que hay un menú desplegado cual es osea...
tengo un form sublcasificado y tengo 3 menú _________________________ Archivo | Edición | Ayuda _________________ |----------------------| |----------------------| |----------------------| |----------------------| |----------------------| |________________|
y el menú Edición esta desplegado como puedo saber si el menú que esta desplegado es el de edición.
Saludos
Título: Re: Averiguar el Menu desplegado.
Publicado por: aaronduran2 en 29 Octubre 2008, 21:49 pm
Si el formulario lo hiciste tú, puedes usar variables de tipo boolean.
Saludos.
Título: Re: Averiguar el Menu desplegado.
Publicado por: LeandroA en 29 Octubre 2008, 21:54 pm
mm no me sirve, gracias
Título: Re: Averiguar el Menu desplegado.
Publicado por: Dessa en 30 Octubre 2008, 01:59 am
Hola Leandro, si no encontraste nada directo tal vez podrias usar GetWindowRect para reconocer el tamańo de cada uno (no creo que sean iguales) tendrias que calcular tambien la resolucion de pantalla. saludos
Título: Re: Averiguar el Menu desplegado.
Publicado por: LeandroA en 30 Octubre 2008, 02:38 am
que haces Dessa tanto tiempo, mm pero debe haber alguna manera con apis
Saludos
Título: Re: Averiguar el Menu desplegado.
Publicado por: seba123neo en 30 Octubre 2008, 02:56 am
o algun mensaje de windows que detecte cuando se despliega el menu...busque y hay un monton...pero no se cual podria ser...
Título: Re: Averiguar el Menu desplegado.
Publicado por: Dessa en 30 Octubre 2008, 03:42 am
Viste Leandro ... resucité , si no encuentran nada directo, a mi me parece que con un IF en un timer que busque la classe (si no es #32768 pega en el palo), y que busque el Left de cada menú con respecto al formulario contenedor (calculado en porcentaje por si hay cambio de resolucion) tendria que ir , por lo menos como plan "B".
Super saludos a ambos.
Título: Re: Averiguar el Menu desplegado.
Publicado por: el_c0c0 en 30 Octubre 2008, 04:33 am
che leandro y con algun mensaje de estos? Private Const WM_MENUCHAR As Long = &H120 Private Const WM_MENUCOMMAND As Long = &H126 Private Const WM_MENUDRAG As Long = &H123 Private Const WM_MENUGETOBJECT As Long = &H124 Private Const WM_MENURBUTTONUP As Long = &H122 Private Const WM_MENUSELECT As Long = &H11F
saludos
Título: Re: Averiguar el Menu desplegado.
Publicado por: Dessa en 30 Octubre 2008, 04:47 am
Siguiendo la pista de el_c0c0 tal vez ayude esto
http://winapi.conclase.net/curso/index.php?men=WM_MENUSELECT
Saludos
Título: Re: Averiguar el Menu desplegado.
Publicado por: el_c0c0 en 30 Octubre 2008, 04:52 am
nose si con esos mensajes funciona, mira cobein me recomendo que le pegara una leidita al codigo de NeoCaption de VBAccelerator: http://www.vbaccelerator.com/home/VB/Code/Controls/Skins/VB6_NeoCaption_Full_Source.asp (http://www.vbaccelerator.com/home/VB/Code/Controls/Skins/VB6_NeoCaption_Full_Source.asp), ahi fijate en el modulo "cMenuBar.cls", desde ya te digo que es un quilombo porque tenes que manejar todos los eventos como el alt para que muestre el foco en un menu, los aceleradores de tecla, etc... pero ahi en ese modulo esta lo que buscas.. esta en las funciones MenuHitTest y HitTest.. es facil para eso solo, pero viendo ese modulo te das cuenta que tenes que implementar todo lo demas para que funcione bien :/...
en fin, saludos!
Título: Re: Averiguar el Menu desplegado.
Publicado por: Dessa en 3 Noviembre 2008, 04:34 am
Laendro, fijate si podes adaptar este code: Option Explicit
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function FindWindow _ Lib "user32" _ Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32" _ (ByVal Hwnd As Long, lpRect As RECT) As Long
Private Type RECT left As Long Top As Long Right As Long Bottom As Long End Type
Private Declare Function SetCursorPos Lib "user32" _ (ByVal X As Long, ByVal Y As Long) As Long
Private Declare Sub mouse_event Lib "user32" _ (ByVal dwFlags As Long, ByVal dx As Long, _ ByVal dy As Long, ByVal cButtons As Long, _ ByVal dwExtraInfo As Long)
Private Const MOUSEEVENTF_LEFTDOWN = &H2 Private Const MOUSEEVENTF_LEFTUP = &H4 Private Const MOUSEEVENTF_RIGHTDOWN = &H8 Private Const MOUSEEVENTF_RIGHTUP = &H10
Dim Hndl As String _
Private Sub Form_Load()
Shell "notepad", vbNormalFocus Timer1.Interval = 50 End Sub
Private Sub Timer1_Timer()
Dim TR As RECT Dim left_notepad As Integer Dim left_contexo As Integer
Hndl = FindWindow("notepad", vbNullString)
If Hndl <> 0 Then If Hndl = GetForegroundWindow() Then Call GetWindowRect(Hndl, TR) left_notepad = TR.left Hndl = FindWindow("#32768", vbNullString) If Hndl = 65562 Then Me.Caption = "menu de notepad cerrado" Else Call GetWindowRect(Hndl, TR) left_contexo = TR.left Me.Caption = "Left " & left_contexo - left_notepad End If End If
Else
Me.Caption = "notepad cerrado"
End If
End Sub
PD: si encontraste el mensaje directo pasame el code, saludos
Título: Re: Averiguar el Menu desplegado.
Publicado por: LeandroA en 3 Noviembre 2008, 17:47 pm
Hola si encontre la solucion,pero bueno me colgue y no lo postie, pero aca va. hay otras formas mas, pero esta es la que mejor se adaptaba a mi nesesidad. Option Explicit Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function GetMenuItemInfo Lib "user32.dll" Alias "GetMenuItemInfoA" (ByVal hMenu As Long, ByVal un As Long, ByVal b As Boolean, ByRef lpMenuItemInfo As MENUITEMINFO) As Long Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long 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 Const WM_MENUSELECT As Long = &H11F Private Const GWL_WNDPROC = (-4) Private Const MF_ENABLED As Long = &H0& Private Const MF_HILITE As Long = &H80& Private Const MF_DISABLED As Long = &H3& Private Const MIIM_STATE As Long = &H1 Dim hMenu As Long Dim PrevProc As Long Public Sub HookForm(hWnd As Long) hMenu = GetMenu(hWnd) PrevProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc) End Sub Public Sub UnHookForm(hWnd As Long) SetWindowLong hWnd, GWL_WNDPROC, PrevProc End Sub Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long WindowProc = CallWindowProc(PrevProc, hWnd, uMsg, wParam, lParam) If uMsg = WM_MENUSELECT Then Debug.Print GetIdMenuSelected() End If End Function Private Function GetIdMenuSelected() As Long Dim MnuCount As Long Dim i As Long Dim ItemState As Long MnuCount = GetMenuItemCount(hMenu) For i = 0 To MnuCount - 1 ItemState = GetMenuState(i) If ItemState = (MF_HILITE Or MF_ENABLED) Or ItemState = (MF_HILITE Or MF_DISABLED) Then GetIdMenuSelected = i Exit Function End If Next GetIdMenuSelected = -1 End Function Private Function GetMenuState(ID As Long) As Long Dim MII As MENUITEMINFO MII.cbSize = Len(MII) MII.fMask = MIIM_STATE Call GetMenuItemInfo(hMenu, ID, True, MII) GetMenuState = MII.fState End Function
Form Option Explicit Private Sub Form_Load() HookForm Me.hWnd End Sub Private Sub Form_Unload(Cancel As Integer) UnHookForm Me.hWnd End Sub
Saludos
|