August 13th, 2003

Scrollbars part 8 – Integral interactive resizing

Enforcing integrality solves the fractional-line problem, but notice that when you grab the top or bottom edge and resize the window, the resize feedback doesn’t match the actual window you get back if you drag the window to a non-integral size. (You may need to turn off full window drag to see this effect more clearly.)

The WM_SIZING message lets us adjust the feedback during window resizing. We will adjust the rectangle to match the rectangle that will result when you let go of the mouse.

void OnSizing(HWND hwnd, WPARAM wmsz, LPRECT prc)
{
    AdjustSizeRectangle(hwnd, wmsz, prc);
}
    /* Add to WndProc */
    case WM_SIZING: OnSizing(hwnd, wParam, (LPRECT)lParam); return TRUE;

Observe that now, when you resize the window, the resizing feedback accurately represents the resulting size of the window. As you drag the mouse vertically or horizontally, the rectangle skips in integral units.

Exercise: If we are enforcing integrality during resizing, why do we also need to enforce integrality in WM_WINDOWPOSCHANGING, too?

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.