December 10th, 2010

How do I limit the size of the preview window used by Aero Snap?

A customer reported that the translucent preview shows by Aero Snap showed the wrong dimensions for their application window. “As you can see in the screen shot, the preview is too wide. Our application window has a maximum width, but the preview is fully half the width of the screen. How can we disable the Aero Snap feature?”

Whoa there, giving up so easily? Sounds like you’re throwing the baby out with the bathwater.

To control the size of the preview window used by Aero Snap, you respond to the same message you’ve already been responding to in order to tell Windows the valid range of sizes for your window: WM_GET­MIN­MAX­INFO.

Start with our scratch program and make the following changes:

void OnGetMinMaxInfo(HWND hwnd, LPMINMAXINFO pmmi)
{
  pmmi->ptMaxTrackSize.x = 400;
}
// add to WndProc
    HANDLE_MSG(hwnd, WM_GETMINMAXINFO, OnGetMinMaxInfo);

We specify in the On­Get­Min­Max­Info function that the maximum width for the window is 400 pixels. (In real life, of course, you wouldn’t hard-code the width, but this is just a proof of concept program.) Since we don’t touch ptMaxTrackSize.y, we impose no additional constraints on the window height beyond what comes with Windows by default.

Run this program, and use Aero Snap to shove it against the edges of the screen. Observe that the Aero Snap preview respects our maximum window width.

I never heard back from the customer, so I assume this simple solution worked for them. The fact that they had to ask this question tells me that they hadn’t been handling the WM_GET­MIN­MAX­INFO message at all; instead, they were enforcing their window size procedurally after the window manager already decided on the wrong size. Either they didn’t seem to mind that the maximize and restore animations showed the window animating to the wrong size, or they couldn’t figure out how to fix that problem either.

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.