Sending a Mouse Click to "OnTime"I need to send a mouse click to a program called "OnTime" from a Visual Basic program, to select an item from a list box, since OnTime will not allow using a SendKeys statement with shortcut keys to select an item from the listbox. OnTime will only accept a mouse click. I have done the following but it does not work properly. I need some advice.....
Sub Form_Load ()
OnTime = "OnTime" ' Application title
DoOnTimeCommands:
On Error Resume Next
AppActivate OnTime ' Activate application
DoEvents ' Let Windows do its thing
If Err > 0 Then ' Check Error Return
MsgBox "Ontime Activate Error"
GoTo EndProgram
End IF
SendKeys "%U,s", True ' alt-u, menu select
SendKeys "ansell", True ' Point to correct item
xpos = 103: ypos = 114 ' Cursor coordinates
Call SetCursorPos(xpos, ypos) ' Put cursor on top of item
' to be selected
MsgReturn = SendMessage(GetFocus(), WM_LButtonDown , 0, WM_null)
' Send
Click
MsgBox Str$(MsgReturn) ' Display return
EndProgram:
End
I have been trying for days to get an answer to this question, through various avenues. Any information would be greatly appreciated.
Thanks,
From: Richard Stuemke.
Email: rstuemk@ccgate.sos.state.il.us
Organization: Illinois Secretary of State, Central Systems Services.
I'm not sure exactly what is going wrong here, it's hard to tell without viewing the actual application that you are trying to communicate with.
There are two other things you might try:
Use the SendMessage API to send the keystrokes via a more direct method. This will involve one call for every keystroke but it is a very direct method. SendKeys (by comparison) does a few more weird things on the way through.
As far as getting your current code to work, I would make a couple of suggestions:
Check the declarations you are using for SendMessage. I always tend to declare it twice to get the correct declaration for both lParam types (longs and strings). Try the following:
Declare Function SendMessageString Lib "User"
(ByVal hWnd As Integer, ByVal wMsg As Integer,
ByVal wParam As Integer,
ByVal lParam As String) As Long
Declare Function SendMessageLong Lib "User"
(ByVal hWnd As Integer, ByVal wMsg As Integer,
ByVal wParam As Integer,
ByVal lParam As Long) As Long
The lParam parameter is where you specify the position of the mouse click. The LOWORD specifies the x position and the HIWORD specifies the y position. You might want to try passing the hex value &H30003 for x,y of 3,3 instead of 0. This is just to make sure that you are well inside the control's border region.
That's all that comes to mind at the moment. Let me know if you still have problems and I will try to replicate the problem. Hopefully, however, you now have some things to try which will either help directly or will unearth the answer indirectly.
Good Luck. Code long and prosper.