读书人

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

发布时间: 2013-02-24 17:58:56 作者: rapoo

VC获取窗口句柄!求大神解惑!
程序中调用另一个窗口的控件单击等操作
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"28个有效句柄
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);//"" * 161个有效句柄
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);



请大家指导或提供思路,谢谢大家!新年快乐~
[解决办法]
推荐楼主使用Spy4Win软件。
[解决办法]
FindWindowEx 找出来的顺序跟spy++是一样的。我都是用这个的
[解决办法]
查找窗口内部组件得用GetWindowEx函数
[解决办法]
http://www.autohotkey.com

读书人网 >C++

热点推荐