elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Averiguar el Menu desplegado.
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: 1 [2] Ir Abajo Respuesta Imprimir
Autor Tema: Averiguar el Menu desplegado.  (Leído 3,269 veces)
Dessa


Desconectado Desconectado

Mensajes: 624



Ver Perfil
Re: Averiguar el Menu desplegado.
« Respuesta #10 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


En línea

Adrian Desanti
LeandroA
Moderador
***
Desconectado Desconectado

Mensajes: 760


www.leandroascierto.com


Ver Perfil WWW
Re: Averiguar el Menu desplegado.
« Respuesta #11 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


En línea

Páginas: 1 [2] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Div desplegable como hacer para que se vea desplegado
Desarrollo Web
Alarkon_88 2 1,434 Último mensaje 6 Agosto 2018, 04:20 am
por #!drvy
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines