开发者

Troubles with ::MoveWindow - leaving blank space

I am quite desperate to resolve this very annoying issue :( I am trying to display a child window on parent window. Some time the window need to be resized. But for some reason, when I using MoveWindow function it leaves blank space on the top of the parent window. I would like to present a picture here but I can not post a picture.

Here is the code example:

HWND hwnd  // Comes from external function. Was defined as WS_CHILD previously
HWND hwndParent     = ::GetParent(hwnd);  
RECT parentRect     = {0,0,0,0};  
RECT childRect      = {0,0,0,0};  
::GetClientRect(hwndParent, &parentRect);  // Suppose it returns {0,0,600,300}  

BOOL ok = ::MoveWindow(hwnd, 0, 0, 600, 300, true);  
::GetClientRect(hwnd, &childRect);  // Will return {0,0,584,297}  

WHY ?????

What am I doing wrong? Did I forgot some fl开发者_如何转开发ags with window initialization?!


Rather than use GetClientRect, use GetWindowRect and MapWindowPoints(NULL,hwndParent,&parentRect,2) to adjust it to the parent window coordinates. GetWindowRect will include the non-client area that MoveWindow requires.

Edit: If you want a window that doesn't have a non-client area so the window rect and the client rect are the same size, you need to trim the window styles that you apply to the window. Avoid the WS_BORDER, WS_CAPTION, WS_DLGFRAME, WS_OVERLAPPED, WS_SIZEBOX, and WS_THICKFRAME styles.


MoveWindow updates window position, while GetClientRect gets a client-area part of the window, which does not have to be the same. If your window has non-client area, then everything is fine and works as expected.

If you are still under impression that child window does not fully cover parent's client area, then the spacing belongs to the child control/window, and you need to look for ways to remove it there (control flags, parameters etc).


MoveWindow operates on window coordinates -- including non-client area (borders, title bar, etc).

GetClientRect gets the area of the client portion of the window, ignoring borders, title bar, etc.

This is where the mismatch is. If you want to MoveWindow to a desired client size, you need to just AdjustWindowRect to try and predict what to pass into MoveWindow. Note that it's not always possible, and not always accurate. For example minimum / maximum sizes of windows, menus (which can wrap to multiple lines), etc.


The problem was WS_POPUP flag to the parent window. Very strange. As far as I know it was not suppose to have such an effect.

Thanks for everyone!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜