Programming/MFC

Example 7 : StatusBar

부풍 2009. 8. 24. 16:26

1. Resrouce에 String table 추가

  • ID_INDICATOR : LEFT
  • ID_INDICATOR_RIGHT : RIGHT

2. MainFrm.cpp 수정

static UINT indicators[] =
{
	ID_SEPARATOR,           // 상태 줄 표시기
	ID_INDICATOR_LEFT,
	ID_INDICATOR_RIGHT,
};

3. CEx7View

#include "MainFrm.h"
 
void CEx7View::OnMouseMove(UINT nFlags, CPoint point)
{
	CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
	pFrame->OutMPos(point);
}

4. MainFrm.cpp

void CMainFrame::OutMPos(CPoint p)
{
	CString str;
	str.Format("(%d, %d)", p.x, p.y);
	m_wndStatusBar.SetPaneText(0, str);
}

5. Update Command UI (직접 작성)

protected:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnUpdateLeft(CCmdUI *pCmdUI);
	afx_msg void OnUpdateRight(CCmdUI *pCmdUI);
	DECLARE_MESSAGE_MAP()
public:
	void OutMPos(CPoint p);
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	ON_WM_CREATE()
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_LEFT, OnUpdateLeft)
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_RIGHT, OnUpdateRight)
END_MESSAGE_MAP()
 
void CMainFrame::OnUpdateLeft(CCmdUI *pCmdUI)
{
	pCmdUI->Enable(GetKeyState(VK_LBUTTON) < 0);
}
 
void CMainFrame::OnUpdateRight(CCmdUI *pCmdUI)
{
	pCmdUI->Enable(GetKeyState(VK_RBUTTON) < 0);
}

6. DialogBar 작성 : MainFrame에 다음 추가

private:
	CDialogBar m_wndDialogBar;
 
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	// ~~~~
 
	if (!m_wndDialogBar.Create(this, IDD_DIALOGBAR, CBRS_LEFT, IDD_DIALOGBAR))
		return -1;
 
	return 0;
}