CWindowImpl sample

簡単なサンプル

#include <windows.h>
#include <atlbase.h>
CComModule _Module;
#include <atlwin.h>

class CMyWindow : public CWindowImpl<CMyWindow>
{
	BEGIN_MSG_MAP(CMyWindow)
		MESSAGE_HANDLER(WM_DESTROY,OnDestroy)
	END_MSG_MAP()

//背景を変更する
	CMyWindow()
	{
		CWndClassInfo& wci = GetWndClassInfo();
		if (!wci.m_atom)
		{
			wci.m_wc.hbrBackground = CreateHatchBrush(HS_DIAGCROSS,RGB(0,0,255));
		}
	}

	
	LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		PostQuitMessage(0);
		return 0;
	}
};



int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR lpszCmd,int nCmdShow)
{
	_Module.Init(NULL,hInstance);

	CMyWindow mw;
	mw.Create(NULL,CWindow::rcDefault,_T("MyWindow"),
		WS_OVERLAPPEDWINDOW | WS_VISIBLE);
	
	MSG msg;
	while(GetMessage(&msg,NULL,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	
	_Module.Term();
	return msg.wParam;
}