简体   繁体   中英

non-MFC CalcWindowRect()?

does anybody know if there is a non-MFC version of this API?

CalcWindowRect()

thanks

There's no exact one-to-one replacement function for it, but AdjustWindowRectEx is pretty close. If using the CWnd::adjustOutside flag to account for scroll bars, you'll need to do that adjustment yourself.

For example:

// MFC version
RECT desiredClientRect = {0, 0, 640, 480};
myCwnd->CalcWindowRect(&desiredClientRect,
    ignoreScrollBars ? CWnd::adjustBorder : CWnd::adjustOutside);

// Win32 version
RECT desiredClientRect = {0, 0, 640, 480};
DWORD dwStyle = GetWindowLong(myHwnd, GWL_STYLE);
AdjustWindowRectEx(&desiredClientRect,
    dwStyle,
    (GetMenu(myHwnd) != NULL),           // bMenu
    GetWindowLong(myHwnd, GWL_EXSTYLE)); // dwExStyle
if(!ignoreScrollBars)
{
    if(dwStyle & WS_HSCROLL)
        desiredClientRect.right += GetSystemMetrics(SM_CXHSCROLL);
    if(dwStyle & WS_VSCROLL)
        desiredClientRect.bottom += GetSystemMetrics(SM_CXVSCROLL);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM