SnapDialog

Description

This sample uses native subclassing to monitor WM_WINDOWPOSCHANGING notifications, and demonstrates how simple it is to "snap" a dialog to the edge of the screen as the user drags it around. You've probably seen this effect in numerous little utilities like WinAmp. It's so subtle, many users wouldn't even notice it, but it definitely adds a touch of polish to nearly any application.

CSnapDialog is implementated as a drop-in ready class which hooks any given form in your app and completely handles all the "messy" details. You set it up, quite simply, like this:

Color-coded with vbMarkUp - try it today!
Private m_Snap As CSnapDialog

Private Sub Form_Load()
   ' Setting up is a snap!
   Set m_Snap = New CSnapDialog
   m_Snap.hWnd = Me.hWnd
   m_Snap.SnapGap = 20 '(optional)
End Sub

The optional SnapGap property (default: 15) sets the "snap tolerance" in pixels. Anytime your user drags the form within this many pixels of the edge of any monitor on their system, CSnapDialog snaps the form to the nearest edge or corner. No teardown is required, as that's completely encapsulated within the class.

Published

This sample, or the one from which it originally derived, was published (or at least peripherally mentioned) in the following article(s):

APIs Usage

This sample uses the following API calls:

Module Library Function
CSnapDialog.cls kernel32
user32



RtlMoveMemory
GetMonitorInfo
GetSystemMetrics
IsWindow
MonitorFromWindow
SystemParametersInfo
MHookMe.bas kernel32

user32



OutputDebugString
RtlMoveMemory
CallWindowProc
GetProp
GetWindowLong
SetProp
SetWindowLong

Don't see what you're looking for? Here's a complete API cross-reference.

Download

Download SnapDialog.zip   Please, enjoy and learn from this sample. Include its code within your own projects, if you wish. But, in order to insure only the most recent code is available to all, I ask that you don't share the sample by any form of mass distribution.

Download SnapDialog.zip, 12Kb, Last Updated: Friday, March 28, 2008

See Also

The following resources may also be of interest: