开发者

How can I find a window with a specific window style? (WS_CHILDWINDOW)

I've got a specific window with the window style WS_CHILDWINDOW. It's the child window of a window of which I'开发者_JS百科ve got the handle already. This window is the second-last one. How do I get it?

It's C++ by the way.


As an alternative to EnumChildWindows posted above, you can use this:

HWND first_child = GetWindow(parent_hwnd, GW_CHILD);
HWND last_child = GetWindow(first_child, GW_HWNDLAST);
HWND prev_to_last_child = GetWindow(last_child, GW_HWNDPREV);

A drawback of this approach is a possibility of a race if a new child window is added at the end of Z-order between steps 2 and 3. Though in practice it shouldn't be a problem. :)


Well, there's a specific Windows API function for enumerating child windows: EnumChildWindows(). Pass the parent window handle and a callback. There has to be some "special" about the child window you want to find. Counting them down in the callback could suffice. "Previous-to-last" is very possible too, just needs two variables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜