SendMessage最小化窗口

时间:2014-03-22 16:08:15

标签: vb.net sendmessage

我试图点击最小化应用程序中的按钮,我使用此代码

Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Dim ParenthWnd As New IntPtr(0)
Dim hWnd As New IntPtr(0)
ParenthWnd = FindWindow(Nothing, "Title of application")

If ParenthWnd.Equals(IntPtr.Zero) Then
    Debug.WriteLine(""Title of application" is not running")
Else
    hWnd = FindWindowEx(ParenthWnd, hWnd, "Button", "Login")
    If hWnd.Equals(IntPtr.Zero) Then
        Debug.WriteLine(""Title of application" doesn't have a 'Login' button, how strange!")
    Else
        Debug.WriteLine(""Title of application" Window: " & ParenthWnd.ToString())
        Debug.WriteLine("Button Control: " & hWnd.ToString())
        SendMessage(hWnd, WM_LBUTTONDOWN, 1, 0)
        SendMessage(hWnd, WM_LBUTTONUP, 0, 0)

    End If
End If

我在调试窗口中得到了一个真实的结果:

"title of window" Window: 2492018
Button Control: 1836764

但它仍然只是"标记"按钮并没有点击它,任何人都知道我应该改变什么?

2 个答案:

答案 0 :(得分:0)

我认为一些Windows应用程序会冻结gui线程,如果它被最小化。我知道sendMessage和postMessage能够将密钥发送到没有聚焦或仍在后台的窗口。 所以你需要做一个像

这样的解决方法

http://sim0n.wordpress.com/2009/03/27/vbnet-q-sending-mouseclickskeystrokes-into-minimized-window/

答案 1 :(得分:0)

尝试

SendMessage(hWnd, &HF5, New IntPtr(0), New IntPtr(0))

其中hWnd是按钮句柄,BM_CLICK = 0x00F5。

瓦尔特