Use Sendmessage to simulate click on "OK" button
Posted on 2009-06-29
I am using VB.Net 2005. I would like to use API Sendmessage to close a dialog popup window that will wait till you close it or click on the OK button to make it go away.
I have enumerated all the windows and know the handle of the "OK" button and the parent window. I have used spy++ to verify that the info I have in my code is correct.
Spy++ reports that the class of this window is "Button" and that the caption is "OK"
I am using this declare statement
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal handle As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, _
ByVal lParam As String) As Integer
I am trying to simulate a click on the "OK" button with the following code.
SendMessage(OK_Button_Handle, &H2, Int(0), "") ' Performs button click
Of course it's not working. I would appreciate some help.