I've got a specific window with the window style WS_CHILDWINDOW. It's the child window of a window of which I've got the handle already. This window is the second-last one. How do I get it?
It's C++ by the way.
I've got a specific window with the window style WS_CHILDWINDOW. It's the child window of a window of which I've got the handle already. This window is the second-last one. How do I get it?
It's C++ by the way.
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.
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. :)