Snapping Windows


How to Help Your Business Become an AI Early Adopter

Environment: VC6 SP4, W2K SP2

In the process of creating my own shell for Windows I found that having all of the individual elements snap to the edge of the screen very useful. To make this process much easier I put together a small class that provides drop in window snapping. It uses a MFC like class so modifying it to use MFC should be easy. NOTE: For dialog windows use the CSnapDlg instead.

The Features

  • Snaps to the edge of the desktop
  • Adjusts to screen resolution changes

How it Works

When the mouse is pressed in the non-client area of the window, the position is saved as an offset from the top left corner of the window. Then when the WM_MOVING message is sent it modifies the windows position based on the precalculated offset.

It is quite simple to use. Here is how to use it.

// register class
CTestWnd twWnd;

// Perform application initialization:
           "CSnapWnd Test",


Download demo project and source - 30.6 KB


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date