vb语言,已知一窗体的句柄,如何通过句柄激活当前窗体并向他发送信息?求大神指教。
4个回答
展开全部
使用ShowWindow这个api向句柄发送show属性就可以了.比如这个HWND是句柄
ShowWindow(HWND,SW_SHOW)
当然使用前要先声明
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
一般获取句柄的时候就已经需要声明这个了.看你的需要把.如果声明过就直接调用.就可以了
ShowWindow(HWND,SW_SHOW)
当然使用前要先声明
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
一般获取句柄的时候就已经需要声明这个了.看你的需要把.如果声明过就直接调用.就可以了
更多追问追答
追问
我如何才能向这个把柄发送 鼠标右键这个命令啊?这个问题对我很重要,我百度了很久和问了很多大神都没有得到答案,大神能否帮忙聚个例子!万分感谢
追答
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
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Command1_Click()
Dim dHwnd As Long, tHwnd As Long
tHwnd = FindWindow("WindowsForms10.Window.8.app.0.378734a", "标题"
If tHwnd > 0 Then
PoPostMessage Gwnd, WM_LBUTTONDOWN, 0, ByVal (1 + 1 * 65536)
PostMessage Gwnd, WM_LBUTTONUP, 0, ByVal (1 +1 * 65536)
End If
End Sub
不同的窗体用不同的api当然.有很多窗体都屏蔽外部接收命令.特别是游戏.基本上都没办法实现.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询