Richard Kreidl
asked on
How to use "SendKeys" with FindWindow with a DropDown control?
I have an application that I'd like to automate the process in using FindWindow to SendKeys to a DropDown control to pick an item from the list in the dropdown.
The X & Y coordinates for the mouse are: 145, 200
Here is what I have so far...
Public Class Form1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetActiveWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hWnd As Long) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myTest As Long
myTest = FindWindow(Nothing, "CSS - New Search - Windows Internet Explorer")
SetActiveWindow(myTest)
' SendKeys.Send ???????
End Sub
I attached two screen prints to show you the dropdown..
Initial-screen.JPG
DropDown---Personal-Name.jpg
The X & Y coordinates for the mouse are: 145, 200
Here is what I have so far...
Public Class Form1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetActiveWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hWnd As Long) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myTest As Long
myTest = FindWindow(Nothing, "CSS - New Search - Windows Internet Explorer")
SetActiveWindow(myTest)
' SendKeys.Send ???????
End Sub
I attached two screen prints to show you the dropdown..
Initial-screen.JPG
DropDown---Personal-Name.jpg
ASKER
Not Working...
Here's what I got with your code and mine:
Public Class Form1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetActiveWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hWnd As Long) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myTest As Long
myTest = FindWindow(Nothing, "CSS - New Search - Windows Internet Explorer")
SetActiveWindow(myTest)
PerformMouseClick("LClick" , 145, 200)
End Sub
Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As IntPtr)
Private Sub PerformMouseClick(ByVal LClick_RClick_DClick As String, ByVal x As Int32, ByVal y As Int32)
Const MOUSEEVENTF_LEFTDOWN As Integer = 2
Const MOUSEEVENTF_LEFTUP As Integer = 4
Const MOUSEEVENTF_RIGHTDOWN As Integer = 6
Const MOUSEEVENTF_RIGHTUP As Integer = 8
If LClick_RClick_DClick = "RClick" Then
mouse_event(MOUSEEVENTF_RI GHTDOWN, x, y, 0, IntPtr.Zero)
mouse_event(MOUSEEVENTF_RI GHTUP, x, y, 0, IntPtr.Zero)
ElseIf LClick_RClick_DClick = "LClick" Then
mouse_event(MOUSEEVENTF_LE FTDOWN, x, y, 0, IntPtr.Zero)
mouse_event(MOUSEEVENTF_LE FTUP, x, y, 0, IntPtr.Zero)
ElseIf LClick_RClick_DClick = "DClick" Then
mouse_event(MOUSEEVENTF_LE FTDOWN, x, y, 0, IntPtr.Zero)
mouse_event(MOUSEEVENTF_LE FTUP, x, y, 0, IntPtr.Zero)
mouse_event(MOUSEEVENTF_LE FTDOWN, x, y, 0, IntPtr.Zero)
mouse_event(MOUSEEVENTF_LE FTUP, x, y, 0, IntPtr.Zero)
End If
End Sub
End Class
Here's what I got with your code and mine:
Public Class Form1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetActiveWindow Lib "user32" Alias "SetForegroundWindow" (ByVal hWnd As Long) As Long
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myTest As Long
myTest = FindWindow(Nothing, "CSS - New Search - Windows Internet Explorer")
SetActiveWindow(myTest)
PerformMouseClick("LClick"
End Sub
Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As IntPtr)
Private Sub PerformMouseClick(ByVal LClick_RClick_DClick As String, ByVal x As Int32, ByVal y As Int32)
Const MOUSEEVENTF_LEFTDOWN As Integer = 2
Const MOUSEEVENTF_LEFTUP As Integer = 4
Const MOUSEEVENTF_RIGHTDOWN As Integer = 6
Const MOUSEEVENTF_RIGHTUP As Integer = 8
If LClick_RClick_DClick = "RClick" Then
mouse_event(MOUSEEVENTF_RI
mouse_event(MOUSEEVENTF_RI
ElseIf LClick_RClick_DClick = "LClick" Then
mouse_event(MOUSEEVENTF_LE
mouse_event(MOUSEEVENTF_LE
ElseIf LClick_RClick_DClick = "DClick" Then
mouse_event(MOUSEEVENTF_LE
mouse_event(MOUSEEVENTF_LE
mouse_event(MOUSEEVENTF_LE
mouse_event(MOUSEEVENTF_LE
End If
End Sub
End Class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!!!! Quick Question could I use the same routine: PerformMouseClick for events on Right click mouse???
yes ... I implemented right , left and double click
ASKER
Thanks again for all your help.
Open in new window
and use it with
PerformMouseClick("LClick"