如何将鼠标点击发送到最小化窗口?

时间:2022-11-28 20:52:54

Heres my code that does not work:

继承我的代码不起作用:

Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Dim wHandle As Long = FindWindow(vbNullString, "Ultima Online")

PostMessage(wHandle, MOUSEEVENTF_LEFTDOWN, 0, 0)
PostMessage(wHandle, MOUSEEVENTF_LEFTUP, 0, 0)

1 个解决方案

#1


I'm not sure why this code should work - it seems you're just clicking on the window, not on a specific button.
To minimize windows you could use another api function: SetWindowPlacement, see: http://www.codeproject.com/KB/dialog/Minimizewindow.aspx

我不确定为什么这个代码应该工作 - 看起来你只是点击窗口而不是特定按钮。要最小化窗口,您可以使用另一个api函数:SetWindowPlacement,请参阅:http://www.codeproject.com/KB/dialog/Minimizewindow.aspx

Another idea: If you want a hacky solution you can send the keys Alt+Space n to minimize a window, but this is very hacky, and works only for English machines:

另一个想法:如果你想要一个hacky解决方案,你可以发送键Alt + Space n来最小化窗口,但这非常hacky,只适用于英语机器:

SendKeys ("% n") ''//in vb6
SendKeys.Send("% n") ''//in vb.net

#1


I'm not sure why this code should work - it seems you're just clicking on the window, not on a specific button.
To minimize windows you could use another api function: SetWindowPlacement, see: http://www.codeproject.com/KB/dialog/Minimizewindow.aspx

我不确定为什么这个代码应该工作 - 看起来你只是点击窗口而不是特定按钮。要最小化窗口,您可以使用另一个api函数:SetWindowPlacement,请参阅:http://www.codeproject.com/KB/dialog/Minimizewindow.aspx

Another idea: If you want a hacky solution you can send the keys Alt+Space n to minimize a window, but this is very hacky, and works only for English machines:

另一个想法:如果你想要一个hacky解决方案,你可以发送键Alt + Space n来最小化窗口,但这非常hacky,只适用于英语机器:

SendKeys ("% n") ''//in vb6
SendKeys.Send("% n") ''//in vb.net