Send message
I have code under 2 events FormLoad and Command1Click
'--It works--
Private Sub Form_Load()
Do While flHWnd = 0
DoEvents
flHWnd = FindWindowWild("Window Name", False)
Loop
End Sub
Private Sub Command1_Click()
AppActivate GetWindowTitle(flHWnd), True 'where flHWnd is the window handle
Call SendMessage(flOKHnd, WM_SETFOCUS, 0, 0) 'flOKHnd is a handle of the OK button on window flHWnd
SendKeys "{ENTER}"
Unload Me
End Sub
'------
When form is loaded I find the window and and by clicking on the Command1 I am sending a click to the OK button of the found window.
That works fine. But if I want to do it without clicking on the Command1 button by including call to command1 into the form load event program does not work.
Here the example:
'--It does not work--
Private Sub Form_Load()
Do While flHWnd = 0
DoEvents
flHWnd = FindWindowWild("Window Name", False)
Loop
Command1_Click
End Sub
Program also does not work if I include code for command1 click to the form load event.
Can somebody solve this mistery?
Iouri Boutchkine
iouri@hotsheet.com
[1215 byte] By [
Iouri] at [2007-11-15 16:16:34]

# 1 Re: Send message
You cannot have "Unload Me" in any code triggered by the form_load - something MS missed with their ODBC login window templtae.
Try putting the code in a timere set with a tiny interval and then set the Timer.Enabled = True as the last command in your form_load
HTH,
Duncan
---------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.
# 2 Re: Send message
Problem is not with Unload Me. It works fine.
I found the solution. I think the problem was caused by Send Keys (I hate it!!!)
I changed it to SendMessage with BM_Click parameter
Anyway, if somebody is interested here is the solution that works
Private Sub Form_Load()
Do While flHWnd = 0
DoEvents
flHWnd = FindWindowWild("MyWindow", False)
Loop
Call SendMessage(flOKHnd, BM_CLICK, 0, ByVal 0&)
Unload Me
End Sub
Iouri Boutchkine
iouri@hotsheet.com
Iouri at 2007-11-10 1:00:14 >

# 3 Re: Send message
Just my two cents. When the Form_Load event is executed, the form is not yet fully developed. You can't execute a .SetFocus method in Form_Load because of this. "SendKeys" likely depends on the control to be available at the time of execution.
Try putting the code in the Form_Activate event to see if it works there (With SendKeys).
John G
# 5 Re: Send message
Perhaps put a debug.print statement in the click event to see if it is being called.
I'm guessing that when the form is loading it doesn't yet have the default control assigned so it recieves the Return key press but doesn't have anything to do with that keypress.
HTH,
Duncan
---------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Check out the new downloads - ImageMap.ocx is the VB control that emulates an HTML image map, EventVB.OCX for adding new events to your VB form and adding System Tray support simply, MCL Hotkey for implemenmting system-wide hotkeys in your application...all with source code included.