Window message a com object dialog

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nt8jbwu02@sneakemail.com

    #1

    Window message a com object dialog

    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.

  • nt8jbwu02@sneakemail.com

    #2
    Re: Window message a com object dialog


    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(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Dim hWinWnd As IntPtr, hWndBtn As IntPtr, RetVal As Long
    Dim lpClassName As New System.Text.Str ingBuilder(255)
    Try
    hWinWnd = FindWindow("<cl ass name of window found with spy++>",
    vbNullString)
    If hWinWnd = 0 Then Exit Sub ' Could not find the window
    hWndBtn = FindWindowEx(hW inWnd, 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(hWn dBtn, WM_LBUTTONDOWN, 0, 0&)
    SendMessage(hWn dBtn, WM_LBUTTONUP, 0, 0&)
    Catch ex As Exception
    MsgBox(ex.Messa ge)
    End Try

    End Sub
    End Class

    Comment

    Working...