Click here to Skip to main content
15,881,281 members
Articles / Desktop Programming / MFC

MFC Snapping Windows

Rate me:
Please Sign up or sign in to vote.
4.68/5 (17 votes)
27 May 2014GPL34 min read 44.4K   2.7K   56  
Easily create windows that snap to each other.
// ChildSnapper.cpp : implementation file
//

#include "stdafx.h"
#include "SampleSnapper.h"
#include "ChildSnapper.h"
#include "afxdialogex.h"


// CChildSnapper dialog

IMPLEMENT_DYNAMIC(CChildSnapper, CDialogEx)

CChildSnapper::CChildSnapper(CWnd* pParent /*=NULL*/)
	: CExtCS < CDialogEx >(CChildSnapper::IDD, pParent)
{

}

CChildSnapper::~CChildSnapper()
{
}

void CChildSnapper::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CChildSnapper, CDialogEx)
END_MESSAGE_MAP()


// CChildSnapper message handlers


void CChildSnapper::OnCancel()
{
	// TODO: Add your specialized code here and/or call the base class
	DestroyWindow();
	//CExtCS::OnCancel();
}


void CChildSnapper::OnOK()
{
	// TODO: Add your specialized code here and/or call the base class
	DestroyWindow();
	//CExtCS::OnOK();
}


BOOL CChildSnapper::DestroyWindow()
{
	// TODO: Add your specialized code here and/or call the base class
	TRACE(_T("CChildSnapper::DestroyWindow\n"));
	::PostMessage(m_hwndParent, WM_DESTROY_CHILD, (WPARAM)GetSafeHwnd(), 0L);
	return CExtCS::DestroyWindow();
}

void CChildSnapper::SetParentHwnd(HWND hwndParent)
{
	m_hwndParent = hwndParent;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Systems / Hardware Administrator
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions