开发者

MFC's GetClientRect and MoveWindow don't preserve size?

开发者 https://www.devze.com 2022-12-14 15:17 出处:网络
I\'m using MFC for Visual Studio 2003. I have an Edit Control with ID IDC_COMMENT_EDIT. In the following code, after my first call to GetClientRect, I don\'t expect the value of rc to change.

I'm using MFC for Visual Studio 2003. I have an Edit Control with ID IDC_COMMENT_EDIT. In the following code, after my first call to GetClientRect, I don't expect the value of rc to change.

CWnd* pWnd = GetDlgItem(IDC_COMMENT_EDIT);
if (pWnd != NULL)
{
  RECT rc;
  pWnd->GetClientRect(&rc);
  pWnd->MoveWindow(&rc, TRUE);
  pWnd->GetClientRect(&rc);
}

rc.top and rc.left are 0 all the way through, as expected. However:

After the first call to GetClientRect, I get rc.bottom == 52, and rc.right == 575.

开发者_JAVA技巧 After the second call to GetClientRect, I get rc.bottom == 48, and rc.right == 571.

Does anyone have any idea what is going on?


Your call to MoveWindow is resizing. You need to use GetWindowRect instead of GetClientRect.

The client rect only includes the client area which is the non windows elements (such as border) of the window.


The client rect doesn't include the window borders, but MoveRect expects a rectangle that includes the borders. Use GetWindowRect instead.

0

精彩评论

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