// mainfrm.h内
class CMainFrame : public CFrameWindowImpl<CMainFrame>,
public CUpdateUI<CMainFrame>, public CMessageFilter, public CIdleHandler
{
public:
DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)
virtual BOOL PreTranslateMessage(MSG* pMsg){
return CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg);
}
virtual BOOL OnIdle(){
UIUpdateStatusBar();
return FALSE;
}
BEGIN_UPDATE_UI_MAP(CMainFrame)
// エントリなし
END_UPDATE_UI_MAP()
BEGIN_MSG_MAP_EX(CMainFrame)
MSG_WM_MOUSEMOVE(OnMouseMove)
MSG_WM_SIZE(OnSize)
MSG_WM_CREATE(OnCreate)
COMMAND_ID_HANDLER_EX(ID_APP_EXIT, OnMenuExit)
CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
END_MSG_MAP()
LRESULT OnCreate(LPCREATESTRUCT lpcs){
// ステータスバーを作成
CreateSimpleStatusBar();
UIAddStatusBar(m_hWndStatusBar);
// メッセージループにメッセージフィルタとアイドルハンドラを追加
CMessageLoop* pLoop = _Module.GetMessageLoop();
pLoop->AddMessageFilter(this);
pLoop->AddIdleHandler(this);
return 0;
}
void OnSize(UINT uType, CSize size){
// マウス座標を表示するペインの幅
int cxPosPane = 90;
// デフォルトペインの幅
CRect rcClient;
GetClientRect(rcClient);
int cxDefaultPane = rcClient.right - cxPosPane
- ::GetSystemMetrics(SM_CXVSCROLL) - ::GetSystemMetrics(SM_CXEDGE);
// ステータスバーにペインを設定
CStatusBarCtrl bar = m_hWndStatusBar;
int nPanes[] = {cxDefaultPane, cxDefaultPane + cxPosPane};
bar.SetParts(sizeof(nPanes)/sizeof(nPanes[0]), nPanes);
// 基底クラスのWM_SIZEメッセージハンドラも呼び出すため
SetMsgHandled(false);
}
void OnMouseMove(UINT uFlags, CPoint ptClient){
CString strPos;
strPos.Format(_T("X:%d, Y:%d"), ptClient.x, ptClient.y);
CStatusBarCtrl bar = m_hWndStatusBar;
bar.SetText(1, strPos);
}
void OnMenuExit(UINT uNotifyCode, int nID, HWND hWndCtl){
PostMessage(WM_CLOSE);
}
};
|