Problems with SetParent() and window frames

Started by
3 comments, last by Aressera 11 years, 7 months ago
I'm trying to implement a cross-platform wrapper for basic window management and OpenGL rendering. I've gotten the OS X version working well. To create an OpenGL rendering view I create an NSOpenGLView (on mac) or an HWND with the WS_CHILD style, then attach the view to a normal window, allowing the user to position the view anywhere in the window.

However, there is something weird that happens whenever I call SetParent() to make the GL view a child window of a normal window - the GL view is resized so that it fits inside in the parent window, but the strange thing is that it is reduced in size by the same amount as if it had a title bar/frame. The result is that there is now a border around the GL view between it and the parent window. This happens even if the client rectangle of the GL view and the normal window should be the same size. (I've attached an image of the behavior).

I should note that it does work as expected unless I call SetWindowPos() to update the frame. SetWindowPos() shouldn't move or size the window if I specify the flags SWP_NOMOVE and SWP_NOSIZE, but it does anyway.

As far as I'm aware, a window with the WS_CHILD style shouldn't have any title bar or frame but it seems like somewhere the windows API treats them as such.

I've spent several hours trying to find a workaround to this apparent problem. Does anyone have any idea what I could be doing wrong, or is there no way I can do what I'm trying to do?

Here is a rundown of the API calls I'm making that cause the problem:

  1. CreateWindowEx() for the GL view with the WS_POPUP style. I use that style because I can't seem to create a window with the WS_CHILD style without specifying a parent window at creation. This also allows me to switch the GL view to fullscreen when running in non-windowed mode. I use a size of 800x600 for the window.
  2. Change the style of the window from WS_POPUP to WS_CHILD using SetWindowLongPtr() in order to prepare it to be a child of another window.
  3. Call SetParent() to make the GL view a child of the normal window.
  4. If I call SetWindowPos() at any point after making the GL view a child, it resizes the GL view's client rectangle as described above. The resulting client area rectangle is 780x560, even though the window was created with a client size of 800x600. This makes the invisible frame of the GL view fit within the original 800x600 size.
Advertisement

I should note that it does work as expected unless I call SetWindowPos() to update the frame. SetWindowPos() shouldn't move or size the window if I specify the flags SWP_NOMOVE and SWP_NOSIZE, but it does anyway.


Can you please specify the arguments assigned to SetWindowPos parameters + full list of GlView styles?
Also, of course child windows can also have a border. What style parameters are you setting when calling CreateWindow(Ex) on the child window?

Show the creation code, message pump and window procs (both parent and child)

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

I'll work up a minimal code example tomorrow demonstrating the issue. I create the child window with the WS_POPUP and WS_CLIP_SIBLINGS style flags. When I make the child window a child of the normal window, I remove the WS_POPUP style and set the WS_CHILD style.

I am calling SetWindowPos( childHandle, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED ) which should just make sure that the cached window frame state is up to date but instead displays the problematic behavior.
I did some more digging and realized that if I handle the WM_NCCALCSIZE message and return 0, the call to SetWindowPos that previously caused the problem worked as expected. It preserves the size of the client rectangle.

The bizarre thing is that before this change, if I added a menu bar to the parent window, that blank frame around the GL view was sized to fit a menu and title bar. I guess if you don't handle that message, the parent window provides the default behavior which obviously wasn't what I wanted...

Everything works great now!

This topic is closed to new replies.

Advertisement