Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: LeandroA en 29 Octubre 2008, 21:31 pm



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?

Código
  1. Private Const WM_MENUCHAR As Long = &H120
  2. Private Const WM_MENUCOMMAND As Long = &H126
  3. Private Const WM_MENUDRAG As Long = &H123
  4. Private Const WM_MENUGETOBJECT As Long = &H124
  5. Private Const WM_MENURBUTTONUP As Long = &H122
  6. Private Const WM_MENUSELECT As Long = &H11F
  7.  

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:

Código:

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.

Código
  1. Option Explicit
  2. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  3. 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
  4. 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
  5. Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
  6. Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
  7.  
  8. Private Type MENUITEMINFO
  9.    cbSize As Long
  10.    fMask As Long
  11.    fType As Long
  12.    fState As Long
  13.    wID As Long
  14.    hSubMenu As Long
  15.    hbmpChecked As Long
  16.    hbmpUnchecked As Long
  17.    dwItemData As Long
  18.    dwTypeData As String
  19.    cch As Long
  20. End Type
  21.  
  22. Private Const WM_MENUSELECT     As Long = &H11F
  23. Private Const GWL_WNDPROC = (-4)
  24.  
  25. Private Const MF_ENABLED As Long = &H0&
  26. Private Const MF_HILITE As Long = &H80&
  27. Private Const MF_DISABLED As Long = &H3&
  28. Private Const MIIM_STATE As Long = &H1
  29.  
  30. Dim hMenu As Long
  31. Dim PrevProc As Long
  32.  
  33. Public Sub HookForm(hWnd As Long)
  34.    hMenu = GetMenu(hWnd)
  35.    PrevProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
  36. End Sub
  37. Public Sub UnHookForm(hWnd As Long)
  38.    SetWindowLong hWnd, GWL_WNDPROC, PrevProc
  39. End Sub
  40.  
  41. Public Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  42.    WindowProc = CallWindowProc(PrevProc, hWnd, uMsg, wParam, lParam)
  43.    If uMsg = WM_MENUSELECT Then
  44.        Debug.Print GetIdMenuSelected()
  45.    End If
  46. End Function
  47.  
  48. Private Function GetIdMenuSelected() As Long
  49.  
  50. Dim MnuCount As Long
  51. Dim i As Long
  52. Dim ItemState As Long
  53. MnuCount = GetMenuItemCount(hMenu)
  54.  
  55. For i = 0 To MnuCount - 1
  56.    ItemState = GetMenuState(i)
  57.    If ItemState = (MF_HILITE Or MF_ENABLED) Or ItemState = (MF_HILITE Or MF_DISABLED) Then
  58.        GetIdMenuSelected = i
  59.        Exit Function
  60.    End If
  61. Next
  62.  
  63. GetIdMenuSelected = -1
  64.  
  65. End Function
  66.  
  67.  
  68. Private Function GetMenuState(ID As Long) As Long
  69.    Dim MII As MENUITEMINFO
  70.    MII.cbSize = Len(MII)
  71.    MII.fMask = MIIM_STATE
  72.    Call GetMenuItemInfo(hMenu, ID, True, MII)
  73.    GetMenuState = MII.fState
  74. End Function

Form
Código
  1. Option Explicit
  2.  
  3. Private Sub Form_Load()
  4.    HookForm Me.hWnd
  5. End Sub
  6. Private Sub Form_Unload(Cancel As Integer)
  7.    UnHookForm Me.hWnd
  8. End Sub


Saludos