// MainFrm.h
#pragma once
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(CMainFrame)
MSG_WM_MOUSEMOVE(OnMouseMove)
MSG_WM_SIZE(OnSize)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
COMMAND_ID_HANDLER_EX(ID_APP_EXIT, OnFileExit)
CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
END_MSG_MAP()
int OnCreate(LPCREATESTRUCT lpCreateStruct){
// ステータスバーを作成
CreateSimpleStatusBar();
UIAddStatusBar(m_hWndStatusBar);
// メッセージループにメッセージフィルタとアイドルハンドラを追加
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 OnSize(UINT nType, 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 nFlags, CPoint point){
CString strPos;
strPos.Format(_T("X:%d, Y:%d"), point.x, point.y);
CStatusBarCtrl bar = m_hWndStatusBar;
bar.SetText(1, strPos);
}
void OnFileExit(UINT uNotifyCode, int nID, CWindow wndCtl){
PostMessage(WM_CLOSE);
}
};
|