VC获取窗口句柄!求大神解惑!

moon5284 2013-02-05 12:03:42
程序中调用另一个窗口的控件单击等操作
1.使用spy++等工具检测窗格布局如下:
[桌面Desktop]
--1窗格“有信”
----2窗格“”
--------3窗格“”
----------------4窗格“”
---------------------按钮1
---------------------按钮2
---------------------...(所需要获取的16个控件)
----------------4窗格"UXTab"
--------3窗格“”
--7个按钮
--------3窗格“”
--四个子窗格

2.使用GW_CHILD、GW_HWNDNEXT获取窗口句柄(但与spy++中显示的层次结构不一样)
hMain = (HWND)FindWindow(NULL, L"有信");
//SendMessage(hMain, WM_CLOSE, 0, 0); //居然关闭不了 汗= =!
//DestroyWindow(hMain);

HWND hChild = GetWindow(hMain,GW_CHILD);//"" 3个有效句柄
HWND step0_1 = GetWindow(hChild,GW_HWNDFIRST);
HWND step0_2 = GetWindow(step0_1,GW_HWNDNEXT);
HWND step0_3 = GetWindow(step0_2,GW_HWNDNEXT);

HWND hChild1 = GetWindow(hChild,GW_CHILD);//"" "" "" 4个有效句柄
HWND step1_1 = GetWindow(hChild1,GW_HWNDFIRST);
HWND step1_2 = GetWindow(step1_1,GW_HWNDNEXT);
HWND step1_3 = GetWindow(step1_2,GW_HWNDNEXT);
HWND step1_4 = GetWindow(step1_3,GW_HWNDNEXT);
HWND step1_5 = GetWindow(step1_4,GW_HWNDNEXT);

HWND hChild2 = GetWindow(hChild1,GW_CHILD);//"" "UXTab" 2 8个有效句柄
HWND step2_1 = GetWindow(hChild2,GW_HWNDFIRST);
HWND step2_2 = GetWindow(step2_1,GW_HWNDNEXT);
HWND step2_3 = GetWindow(step2_2,GW_HWNDNEXT);
HWND step2_4 = GetWindow(step2_3,GW_HWNDNEXT);
HWND step2_5 = GetWindow(step2_4,GW_HWNDNEXT);
HWND step2_6 = GetWindow(step2_5,GW_HWNDNEXT);
HWND step2_7 = GetWindow(step2_6,GW_HWNDNEXT);
HWND step2_8 = GetWindow(step2_7,GW_HWNDNEXT);
HWND step2_9 = GetWindow(step2_8,GW_HWNDNEXT);
HWND step2_10 = GetWindow(step2_9,GW_HWNDNEXT);
HWND step2_11 = GetWindow(step2_10,GW_HWNDNEXT);
HWND step2_12 = GetWindow(step2_11,GW_HWNDNEXT);
HWND step2_13 = GetWindow(step2_12,GW_HWNDNEXT);
HWND step2_14 = GetWindow(step2_13,GW_HWNDNEXT);
HWND step2_15 = GetWindow(step2_14,GW_HWNDNEXT);
HWND step2_16 = GetWindow(step2_15,GW_HWNDNEXT);
HWND step2_17 = GetWindow(step2_16,GW_HWNDNEXT);
HWND step2_18 = GetWindow(step2_17,GW_HWNDNEXT);

HWND hChild3 = GetWindow(hChild2,GW_CHILD);//"" * 16 1个有效句柄
HWND step3_1 = GetWindow(hChild3,GW_HWNDFIRST);
HWND step3_2 = GetWindow(step3_1,GW_HWNDNEXT);
HWND step3_3 = GetWindow(step3_2,GW_HWNDNEXT);
HWND step3_4 = GetWindow(step3_3,GW_HWNDNEXT);
HWND step3_5 = GetWindow(step3_4,GW_HWNDNEXT);
HWND step3_6 = GetWindow(step3_5,GW_HWNDNEXT);
HWND step3_7 = GetWindow(step3_6,GW_HWNDNEXT);
HWND step3_8 = GetWindow(step3_7,GW_HWNDNEXT);
HWND step3_9 = GetWindow(step3_8,GW_HWNDNEXT);
HWND step3_10 = GetWindow(step3_9,GW_HWNDNEXT);
HWND step3_11 = GetWindow(step3_10,GW_HWNDNEXT);
HWND step3_12 = GetWindow(step3_11,GW_HWNDNEXT);
HWND step3_13 = GetWindow(step3_12,GW_HWNDNEXT);
HWND step3_14 = GetWindow(step3_13,GW_HWNDNEXT);
HWND step3_15 = GetWindow(step3_14,GW_HWNDNEXT);
HWND step3_16 = GetWindow(step3_15,GW_HWNDNEXT);


请大家指导或提供思路,谢谢大家!新年快乐~
...全文
693 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
moon5284 2013-02-19
  • 打赏
  • 举报
回复
引用 8 楼 zhao4zhong1 的回复:
引用 6 楼 moon5284 的回复:引用 5 楼 zhao4zhong1 的回复:http://www.autohotkey.com 可以用,但是想自己做~ autohotkey是开放源代码的。
你又回复了 我在看教程 这个能用VC调用么 比如传个CString参数给它 .
赵4老师 2013-02-08
  • 打赏
  • 举报
回复
引用 6 楼 moon5284 的回复:
引用 5 楼 zhao4zhong1 的回复:http://www.autohotkey.com 可以用,但是想自己做~
autohotkey是开放源代码的。
「已注销」 2013-02-07
  • 打赏
  • 举报
回复
PostMessage 先发送 WM_LBUTTONDOWN 然后再发送 WM_LBUTTONUP 。
moon5284 2013-02-06
  • 打赏
  • 举报
回复
引用 5 楼 zhao4zhong1 的回复:
http://www.autohotkey.com
可以用,但是想自己做~
赵4老师 2013-02-06
  • 打赏
  • 举报
回复
moon5284 2013-02-05
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
推荐楼主使用Spy4Win软件。
引用 2 楼 jha334201553 的回复:
FindWindowEx 找出来的顺序跟spy++是一样的。我都是用这个的
引用 3 楼 980333 的回复:
查找窗口内部组件得用GetWindowEx函数
感谢楼上三位的回答,非常有用!但是确定句柄后,按钮无法单击,这是为什么呢?
HWND step3_5 = GetWindow(step3_4,GW_HWNDNEXT);//4060e 句柄完全正确的
	CWnd *pWnd=CWnd::FromHandle(hChild);         //下面三行我是网上看到的(需要窗口置顶才能进行控件点击操作 但窗口置顶好像没起作用 我手动激活了窗口 调用单击命令也没反映)
	BringWindowToTop(hChild);
	pWnd->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
	::PostMessage(step3_5,BM_CLICK,0,0);
_菜菜 2013-02-05
  • 打赏
  • 举报
回复
查找窗口内部组件得用GetWindowEx函数
「已注销」 2013-02-05
  • 打赏
  • 举报
回复
FindWindowEx 找出来的顺序跟spy++是一样的。我都是用这个的
赵4老师 2013-02-05
  • 打赏
  • 举报
回复
推荐楼主使用Spy4Win软件。

24,855

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧