在多桌面的情况下,如何知道一个窗口在哪儿个桌面?
虚拟桌面中,有多个桌面,在某桌面中运行一个程序,现在知道这个程序的句柄,怎么知道该程序在哪儿个窗口?
VB如何判断窗口所在桌面的句柄?
答案:2 悬赏:80 手机版
解决时间 2021-03-07 18:27
- 提问者网友:萌卜娃娃
- 2021-03-06 20:12
最佳答案
- 五星知识达人网友:几近狂妄
- 2021-03-06 21:14
使用 api GetThreadDesktop 获取当前程序的所在虚拟桌面
全部回答
- 1楼网友:北城痞子
- 2021-03-06 21:43
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函数.
private declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long,lparam as any) as long '这句是定义向获得窗口句柄发送按键消息的api函数.
例子:你先建一个工程
form1.caption="12345
画一个command1 名字为 "确定1"
事件
private sub command1_click()
msgbox me.hwnd '显示确定按钮的句柄
end sub
生成12345.exe
关闭vb6
打开vb6
再建一个工程 代码如下:
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
private declare function postmessage& lib "user32" alias "postmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any)
private declare function setforegroundwindow lib "user32" (byval hwnd as long) as long
private declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long
private const wm_lbuttondown = &h201
private const wm_lbuttonup = &h202
private const mk_lbutton = &h1
dim hpwnd as long, hcwnd as long
dim iresult as long
private sub command1_click()
hpwnd = findwindow(vbnullstring, "12345")
hcwnd = findwindowex(hpwnd, 0, vbnullstring, "确定")
setforegroundwindow hcwnd
iresult = sendmessage(hcwnd, wm_lbuttondown, 0, 0&)
iresult = sendmessage(hcwnd, wm_lbuttonup, 0, 0&)
end sub
然后先运行 事先生成好的12345.exe
再运行后建的那个
你单击确定 就会使12345.exe的确定按钮被单击 返回它的hwnd
我的方法是先找到12345.exe的主窗口 然后根据主窗口的句柄获得其确定按钮的句柄 再使用sendmessage 发送模拟鼠标左键单击
vb控件的句柄 一般可用me.hwnd 方法获得
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯