// MainWindow.h
#pragma once
class CMainWindow : public CFrameWindowImpl<CMainWindow>,
public CMessageFilter, public CIdleHandler
{
public:
// ウィンドウクラス名、共通リソースID、スタイル、背景色を登録
DECLARE_FRAME_WND_CLASS_EX(_T("SampleProject"), IDR_MAINFRAME,
CS_HREDRAW | CS_VREDRAW, COLOR_WINDOW)
virtual BOOL PreTranslateMessage(MSG* pMsg){
// 基底クラスのPreTranslateMessageを呼び出す
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_RMENU_VERSION, OnRMenuVersion)
COMMAND_ID_HANDLER_EX(ID_LMENU_CLOSE, OnLMenuClose)
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){
// メニューバー作成
CreateSimpleCEMenuBar(IDR_MAINFRAME, SHCMBF_HMENU);
// ツールバー作成
CreateSimpleCEToolBar();
// メッセージループにメッセージフィルタとアイドルハンドラを追加
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 OnRMenuVersion(UINT uNotifyCode, int nID, CWindow wndCtl){
MessageBox(_T("SampleProject"));
}
void OnLMenuClose(UINT uNotifyCode, int nID, CWindow wndCtl){
PostMessage(WM_CLOSE);
}
};
|