|
-
Aug 7th, 2002, 08:45 AM
#1
Thread Starter
Junior Member
send click event to an other App
I must send the click evet to the OK button from an other application.
Please help me.
I know that I know nothing
-
Aug 7th, 2002, 10:01 AM
#2
Lively Member
!
try to use API f:SendMessage
-
Aug 8th, 2002, 02:18 AM
#3
Thread Starter
Junior Member
My API Literay are bad. Please could you halp me 
VB Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) 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_NCLBUTTONDOWN = &HA1
Private Sub cmdCloseApp_Click()
Dim CloseIt As Long
CloseIt = FindWindow(vbNullString, "Microsoft Outlook")
SendMessage CloseIt, WM_NCLBUTTONDOWN, CLng(0), CLng(0)
End Sub
Thank you very mouch!
Last edited by headache; Aug 8th, 2002 at 02:24 AM.
I know that I know nothing
-
Aug 8th, 2002, 07:35 AM
#4
Software Eng.
Send the BM_CLICK message to the window.
-
Aug 8th, 2002, 08:25 AM
#5
Thread Starter
Junior Member
Thank you
How can i tell him which button? 
It send something but not to the OK button.
VB Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) 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 BM_CLICK = &HF5
Private Sub cmdCloseApp_Click()
Dim CloseIt As Long
CloseIt = FindWindow(vbNullString, "Microsoft Outlook")
SendMessage CloseIt, BM_CLICK, CLng(0), CLng(0)
End Sub
I know that I know nothing
-
Aug 8th, 2002, 08:43 AM
#6
Software Eng.
Send BM_CLICK to the actual button (not the parent window).
To get the handle of the button, use the FindWindowEx function. e.g.
hwndButton = FindWindowEx(hwndParent, 0, "Button", "Button Text")
-
Aug 8th, 2002, 08:48 AM
#7
Fanatic Member
I've had to do this before. Once you find the windows using find window, you'll have to use use the EnumChildWindows API.
you'll hva
Here's some code to get you started.
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessageByStr& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String)
Private Function GetChildControls(apphwnd As Long)
EnumChildWindows apphwnd, AddressOf EnumChildProc, ByVal 0&
End Function
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim sSave As String
Dim sClassName As String
Dim sWindowText As String
Dim lControlId As Long
'// Get window class name
ReDim Preserve Wlist(UBound(Wlist) + 1)
sClassName = String(255, Chr(0))
GetClassName hwnd, sClassName, 255
sClassName = Left(sClassName, InStr(1, sClassName, Chr(0), vbTextCompare) - 1)
sWindowText = String(255, Chr(0))
SendMessageByStr hwnd, WM_GETTEXT, 255, sWindowText
'if the text is &OK or whatever you're looking for, use sendmessage to click the button.
sWindowText = Left(sWindowText, InStr(1, sWindowText, Chr(0), vbTextCompare) - 1)
lControlId = GetWindowLong(hwnd, GWL_ID)
'// continue enumeration
EnumChildProc = 1
End Function
-
Aug 8th, 2002, 09:01 AM
#8
Software Eng.
Another way to go about this is to use FindWindowEx again; but this time, start at the previous window e.g.
hChild = FindWindowEx(hParent, hChild, "Button", vbNullstring)
This will enumerate all buttons.
But again, you'd only need to do this if the button does not have a caption. If it does, then you should get it on the first try.
-
Aug 8th, 2002, 09:25 AM
#9
Thread Starter
Junior Member
I have only the capion of the bottom and only the caption from the window.
Please help
I know that I know nothing
-
Aug 8th, 2002, 11:00 AM
#10
Lively Member
!
try this :
CloseIt = FindWindow(vbNullString, "Microsoft Outlook")
hwndButton = FindWindowEx(CloseIt, 0, "Button", "OK")
SendMessage hwndButton, BM_CLICK, CLng(0), CLng(0)
and tell me if it works becouse i forgot how it works i mean this functions FindWindowEx, i want to refresh my memory
-
Aug 9th, 2002, 01:27 AM
#11
Thread Starter
Junior Member
It Works!!!!!!!!!!!
 It Works!!!!!!!!!!! 
Thank you all for the great help.
hire is my current code
VB Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) 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 Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const BM_CLICK = &HF5
Private Sub cmdCloseApp_Click()
Dim CloseIt As Long
Dim hwndbutton As Long
CloseIt = FindWindow(vbNullString, "Microsoft Outlook")
hwndbutton = FindWindowEx(CloseIt, 0, vbNullString, "OK")
SendMessage hwndbutton, BM_CLICK, CLng(0), CLng(0)
End Sub
Last edited by headache; Aug 9th, 2002 at 01:45 AM.
-
Aug 9th, 2002, 09:44 AM
#12
Software Eng.
You're welcome 
It's usually a good idea to specify the classname as well e.g.
Code:
hwndbutton = FindWindowEx(CloseIt, 0, "Button", "OK")
It just helps narrow your search down a little more.
-
Aug 13th, 2002, 12:58 PM
#13
Junior Member
What's the parameter if it's a dropdown menu or combo box?
-Roy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|