// MainWindow.h
#pragma once
class CMainWindow : public CWindowImpl<CMainWindow>,
public CMessageFilter, public CIdleHandler
{
public:
// ウィンドウクラス名、メニューバーを登録
static CWndClassInfo& GetWndClassInfo()
{
static CWndClassInfo wc =
{
{
sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS,
StartWindowProc, 0, 0, NULL, NULL, NULL, (HBRUSH)(COLOR_WINDOW + 1),
MAKEINTRESOURCE(IDR_MAINFRAME), // メニューバー
_T("Hello"), NULL
},
NULL, NULL, IDC_ARROW, TRUE, 0, _T("")
};
return wc;
}
virtual BOOL PreTranslateMessage(MSG* pMsg){
return FALSE;
}
virtual BOOL OnIdle(){
return FALSE;
}
BEGIN_MSG_MAP(CMainWindow)
MSG_WM_PAINT(OnPaint)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
COMMAND_ID_HANDLER_EX(ID_APP_EXIT, OnFileExit)
END_MSG_MAP()
void OnPaint(CDCHandle /*dc*/){
CPaintDC dc(m_hWnd);
CRect rect;
GetClientRect(rect);
dc.DrawText(_T("Hello, ATL/WTL"), -1,
rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
int OnCreate(LPCREATESTRUCT lpCreateStruct){
// メッセージループにメッセージフィルタとアイドルハンドラを追加
CMessageLoop* pLoop = _Module.GetMessageLoop();
pLoop->AddMessageFilter(this);
pLoop->AddIdleHandler(this);
return 0;
}
void OnDestroy(){
// メッセージループからメッセージフィルタとアイドルハンドラを削除
CMessageLoop* pLoop = _Module.GetMessageLoop();
pLoop->RemoveMessageFilter(this);
pLoop->RemoveIdleHandler(this);
PostQuitMessage(0);
}
void OnFileExit(UINT uNotifyCode, int nID, CWindow wndCtl){
PostMessage(WM_CLOSE);
}
};
|