// SampleProjectFrame.h
#pragma once
class CSampleProjectFrame :
public CFrameWindowImpl<CSampleProjectFrame>,
public CUpdateUI<CSampleProjectFrame>,
public CAppWindow<CSampleProjectFrame>,
public CMessageFilter, public CIdleHandler
{
public:
DECLARE_APP_FRAME_CLASS(NULL, IDR_MAINFRAME, L"Software\\WTL")
CMultiPaneStatusBarCtrl m_statusbar;
virtual BOOL PreTranslateMessage(MSG* pMsg){
return CFrameWindowImpl<CSampleProjectFrame>::PreTranslateMessage(pMsg);
}
virtual BOOL OnIdle(){
return FALSE;
}
BEGIN_UPDATE_UI_MAP(CSampleProjectFrame)
END_UPDATE_UI_MAP()
BEGIN_MSG_MAP(CSampleProjectFrame)
MSG_WM_LBUTTONDOWN(OnLButtonDown)
MSG_WM_CREATE(OnCreate)
MSG_WM_DESTROY(OnDestroy)
COMMAND_ID_HANDLER_EX(ID_APP_EXIT, OnAppExit)
CHAIN_MSG_MAP(CAppWindow<CSampleProjectFrame>)
CHAIN_MSG_MAP(CUpdateUI<CSampleProjectFrame>)
CHAIN_MSG_MAP(CFrameWindowImpl<CSampleProjectFrame>)
END_MSG_MAP()
void OnLButtonDown(UINT nFlags, CPoint point){
SHRGINFO info;
info.cbSize = sizeof(SHRGINFO);
info.hwndClient = m_hWnd;
info.ptDown.x = point.x;
info.ptDown.y = point.y;
info.dwFlags = SHRG_RETURNCMD;
if(SHRecognizeGesture(&info) == GN_CONTEXTMENU){
CString strPos;
strPos.Format(_T("X: %d, Y: %d"), point.x, point.y);
m_statusbar.SetPaneText(IDS_PANE_POS, strPos);
}
}
int OnCreate(LPCREATESTRUCT lpCreateStruct){
// メニューバー作成
CreateSimpleCEMenuBar(IDR_MAINFRAME, SHCMBF_HMENU);
// ステータスバー作成
m_hWndStatusBar = m_statusbar.Create(m_hWnd, _T("レディ"),
WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
// ステータスバーにペインを設定
int nPanes[] = {ID_DEFAULT_PANE, IDS_PANE_POS};
m_statusbar.SetPanes(nPanes, sizeof(nPanes)/sizeof(nPanes[0]));
// メッセージループにメッセージフィルタとアイドルハンドラを追加
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 OnAppExit(UINT uNotifyCode, int nID, CWindow wndCtl){
PostMessage(WM_CLOSE);
}
};
|