向某个特定的画面发送SHIFT+F12命令,如何实现
本帖最后由 lixuelong 于 2012-11-01 15:04:58 编辑 获得某个画面的句柄,然后向该画面发送组合键SHIFT+F12,如何用vb实现
[最优解释]
对于当前活动的界面,不需要获取句柄,直接用 SendKeys 方法向系统发送键码。
SendKeys "+{F12}"
否则就需要句柄。
如果能够人工发送快捷键,则必然是一个 Window,会有句柄。
用下面两个 API 找到窗口:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
用下面的 API 使窗口获得焦点:
Public Declare Function SendMessageCallback Lib "user32" Alias "SendMessageCallbackA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal lpResultCallBack As Long, ByVal dwData As Long) As Long
Public Const WM_SETFOCUS = &H7
SendMessage hWnd2, WM_SETFOCUS, 0, ByVal 0&
[其他解释]
如果是活动窗口,为什么不用SendKeys?
SendKeys "+{F12}", True
按键 代码
SHIFT +
CTRL ^
ALT %
F12 {F12}
[其他解释]
画面的句柄?你根据什么知道“画面”有“句柄”的?
[其他解释]
当前活动的画面
[其他解释]
SendKeys 需要是进程内吧?
[其他解释]
问题已解决,谢谢各位。