// MainWindow.h
#pragma once
class CMainWindow : public CFrameWindowImpl<CMainWindow>,
public CMessageFilter, public CIdleHandler
{
public:
// ウィンドウクラス名、共通リソースID、スタイル、背景色を登録
DECLARE_FRAME_WND_CLASS_EX(_T("Hello"), IDR_MAINFRAME,
CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, COLOR_WINDOW)
virtual BOOL PreTranslateMessage(MSG* pMsg){
return CFrameWindowImpl<CMainWindow>::PreTranslateMessage(pMsg);
}
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_ABOUT, OnAbout)
COMMAND_ID_HANDLER_EX(ID_APP_EXIT, OnFileExit)
CHAIN_MSG_MAP(CFrameWindowImpl<CMainWindow>) // CFrameWindowImplへチェイン
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){
// リバーを作成
CreateSimpleReBar();
// ツールバーを作成してバンドに追加
HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd,
IDR_MAINFRAME, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
AddSimpleReBarBand(hWndToolBar);
// ステータスバーを作成
CreateSimpleStatusBar();
// メッセージループにメッセージフィルタとアイドルハンドラを追加
CMessageLoop* pLoop = _Module.GetMessageLoop();
pLoop->AddMessageFilter(this);
pLoop->AddIdleHandler(this);
return 0;
}
void OnDestroy(){
// メッセージループからメッセージフィルタとアイドルハンドラを削除
CMessageLoop* pLoop = _Module.GetMessageLoop();
pLoop->RemoveMessageFilter(this);
pLoop->RemoveIdleHandler(this);
SetMsgHandled(false);
}
void OnAbout(UINT uNotifyCode, int nID, CWindow wndCtl){
MessageBox(_T("ATL/WTLプログラミング 第2版"));
}
void OnFileExit(UINT uNotifyCode, int nID, CWindow wndCtl){
PostMessage(WM_CLOSE);
}
};
|