Jump to content

  • Log In with Google      Sign In   
  • Create Account

Problems with SetParent() and window frames


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Aressera   Members   -  Reputation: 1425

Like
0Likes
Like

Posted 07 September 2012 - 10:56 PM

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:
  • 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.
  • 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.
  • Call SetParent() to make the GL view a child of the normal window.
  • 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.

Attached Thumbnails

  • broken.png


Sponsor:

#2 Eliad Moshe   Members   -  Reputation: 806

Like
0Likes
Like

Posted 08 September 2012 - 05:05 PM

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?

Edited by Eliad Moshe, 08 September 2012 - 05:06 PM.


#3 Endurion   Crossbones+   -  Reputation: 3586

Like
0Likes
Like

Posted 08 September 2012 - 11:19 PM

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)

Edited by Endurion, 08 September 2012 - 11:21 PM.

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

#4 Aressera   Members   -  Reputation: 1425

Like
0Likes
Like

Posted 09 September 2012 - 12:29 AM

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.

#5 Aressera   Members   -  Reputation: 1425

Like
0Likes
Like

Posted 10 September 2012 - 08:55 PM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS