【问题标题】:SendMessage to minimized windowSendMessage 到最小化窗口
【发布时间】:2014-03-22 16:08:14
【问题描述】:

我正在尝试单击最小化应用程序中的按钮,我使用此代码

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

但它仍然只是“标记”按钮而不点击它,有人知道我应该改变什么吗?

【问题讨论】:

    标签: vb.net sendmessage


    【解决方案1】:

    我认为某些 Windows 应用程序在最小化 gui 线程时会冻结它。我知道 sendMessage 和 postMessage 能够将键发送到未聚焦或仍在后台的窗口。 所以你需要做一个解决方法,比如

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

    【讨论】:

    • 我按照该教程进行操作,但这不是问题,valter 为我解决了问题,不过感谢您的期待!
    【解决方案2】:

    试试

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

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

    变态

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-21
      • 2011-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      相关资源
      最近更新 更多