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:
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.