Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Click OK or press Enter on a Dialog box 1

Status
Not open for further replies.

LJA520

Programmer
Nov 3, 2003
65
US
I am using USER32 to SetForegroundWindow to make it the active window and SendMessage to do a keydown of Enter. I am able to see that I have the handle on it, but the "ENTER" is not working!!! Any idea's???

Please help!!
THANKS!
 

LJA520, have you read FAQ222-2244 yet?

Have you searched this site in your forums for SendMessage? Last 30 days? You would have found this thread713-744609 that I belive will help you in your quest.

Good Luck

 
Thank you, this is what I am looking for. I am able to get the handle of the window. The defaulted button on the form is "OK", so I want to hit enter so that it follows the defaulted procedure. But it returns a zero. Any idea why this isn't working???


hwnd = GetForegroundWindow()

iret = SendMessage(hwnd, WM_KEYDOWN, 13, 0)
Debug.Print iret

iret = SendMessage(hwnd, WM_KEYUP, 13, 0)
Debug.Print iret


THANKS!!!!!!!!!
 

You need to get the handle of the child window. Specifically the handle to the command button you want to click. So you will need to use something like the EnumChildWindows API.

Good Luck

 
Okay, I am able to get the handle of the "OK" button window by doing:

hwnd = GetWindow(hwnd, GW_HWNDNEXT)

when I do a post message:

iret = postMessage(hwnd, WM_LBUTTONDOWN, 0, 0)
iret = postMessage(hwnd, WM_LBUTTONUP, 0, 0)

it return's 1, but when I change it to sendMessage it return's 0. But nothing happens for either of them.

Any ideas??

Thank you so much for your help!!!



 

Use all 4 SendMessages as I show in the above posted thread. But, I think that you need to use the EnumChildWindows instead of the GetWindow API because of the following from the remarks section about GetWindow...
[tt]
The EnumChildWindows function is more reliable than calling GetWindow in a loop. An application that calls GetWindow to perform this task risks being caught in an infinite loop or referencing a handle to a window that has been destroyed.
[/tt]
And then to make sure that you have the correct window you should check its caption(text) with something like GetWindowText

Good Luck

 
Okay, I am able to get the handle of a button and do:

Dim str1 As String
str1 = "hello"
iret = SendMessage(hwnd, WM_SETTEXT, 0, ByVal str1)

and it changes the text of the button. But whenever I try to do a sendmessage of clicking a button, nothing works.. do you know what the correct command is for having it click that button?

Thanks!!!!!
You have been very helpful


 

click on this > Thread713-744609 and goto the last entry of mine where I use 4 different sendmessages to click a button and try them in that order with those constants and values.

Good Luck

 
THANK YOU vb5Prgrmr!!!

It works, I am able to click all the dialog boxes to download the file.

Thank you for all your help!!

-LJA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top