Window message a com object dialog

N

nt8jbwu02

I have some vb code which calls a com object. The com object displays
a dialog for the user
and the user then presses the OK button to dismiss the dialog and the
code continues and
returns control to me. I now have to change the code so that it work
autonomous.

The only way I can think of is to send a windows message, from another
thread, to the dialog
box to simulate the OK button press. Is this possible? If not, other
suggestions?

If I do not have access to the com object code, where should I start?

Thanks.
 
N

nt8jbwu02

in case someone else wants to do the same thing, here is my solution:

Public Class Form1
Private Declare Auto Function FindWindow Lib "user32" ( _
ByVal lpClassWindow As String, _
ByVal lpWindowName As String _
) As IntPtr
Private Declare Auto Function FindWindowEx Lib "user32.dll" ( _
ByVal hwndParent As IntPtr, _
ByVal hwndChildAfter As IntPtr, _
ByVal lpszClass As String, _
ByVal lpszWindow As String _
) As IntPtr
Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32
Const WM_LBUTTONDOWN As Int32 = &H201
Const WM_LBUTTONUP As Int32 = &H202
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim hWinWnd As IntPtr, hWndBtn As IntPtr, RetVal As Long
Dim lpClassName As New System.Text.StringBuilder(255)
Try
hWinWnd = FindWindow("<class name of window found with spy++>",
vbNullString)
If hWinWnd = 0 Then Exit Sub ' Could not find the window
hWndBtn = FindWindowEx(hWinWnd, IntPtr.Zero, "<class name of
control found with spy++>", "&OK")
If hWndBtn = 0 Then Exit Sub ' could not find the control

' emulate mouse click
SendMessage(hWndBtn, WM_LBUTTONDOWN, 0, 0&)
SendMessage(hWndBtn, WM_LBUTTONUP, 0, 0&)
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top