USUÁRIO:      SENHA:        SALVAR LOGIN ?    Adicione o VBWEB na sua lista de favoritos   Fale conosco 

 

  Dicas

  Visual Basic    (Miscelâneas)

Título da Dica:  Emular clique no menu de um executável - SendMessage
Postada em 9/3/2004 por Josefh Hennyere         
'Insira um Botão de Comando e cole este código no Form. Para testá-lo abra o bloco de notas

Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function GetMenuState Lib "user32" (ByVal hMenu As Long, ByVal wID As Long, ByVal wFlags As Long) As Long
Private Declare Function GetMenuString Lib "user32" Alias "GetMenuStringA" (ByVal hMenu As Long, ByVal wIDItem As Long, ByVal lpString As String, ByVal nMaxCount As Long, ByVal wFlag As Long) As Long
Private Declare Function GetMenuDefaultItem Lib "user32" (ByVal hMenu As Long, ByVal fByPos As Long, ByVal gmdiFlags As Long) As Long
Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_COMMAND = &H111

Private Sub Command1_Click()
  Dim hwnd As Long
  Dim hMainMenu As Long
  Dim hMenu As Long
  Dim MenuID As Long
  
  hwnd = FindWindow("NotePad", vbNullString)
  If hwnd = 0 Then Exit Sub
  
  hMainMenu = GetMenu(hwnd)
  hMenu = GetSubMenu(hMainMenu, 0&)
  MenuID = GetMenuItemID(hMenu, 1)
  
  AppActivate "Sem nome - Bloco de Notas" 'Este deve ser o nome que estará no documento do bloco de notas
  
  SendMessage hwnd, WM_COMMAND, MenuID, 0&
End Sub


'Josefh Hennyere
 


CyberWEB Network Ltda.    © Copyright 2000-2024   -   Todos os direitos reservados.
Powered by HostingZone - A melhor hospedagem para seu site
Topo da página