ARCHIVE ...

상태바 (Status Bar) 본문

MFC

상태바 (Status Bar)

냐옹이. 2010. 3. 1. 21:39

선언

// CMainFrame
protected:
	CStatusBar           m_wndStatusBar;   // vs 6
	CMFCStatusBar     m_wndStatusBar;

indicator(상태바 아이템)

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

생성

// int CMainFrame::OnCreate()
if (!m_wndStatusBar.Create(this))
{
	TRACE0("Failed to create status bar\n");
	return -1;      // fail to create
}
m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));

메소드

  • void SetPaneInfo(int nIndex, UINT nID, UINT nStyle, int cxWidth);
    <indicator Styles>
    SBPS_NOBORDERSNo 3-D border around the pane.
    SBPS_POPOUTReverse border so that text "pops out."
    SBPS_DISABLEDDo not draw text.
    SBPS_STRETCHStretch pane to fill unused space. Only one pane per status bar can have this style.
    SBPS_NORMALNo stretch, borders, or pop-out.
  • BOOL SetPaneText(int nIndex, LPCTSTR lpszNewText, BOOL bUpdate = TRUE);
  • void SetPaneStyle(int nIndex, UINT nStyle);
  • int CommandToIndex(UINT nIDFind) const;
    Gets the indicator index for a given ID.

예제

  1. String Table에 String을 하나 만듦(ID_PARSE_TIME)
  2. indicator에 등록(CMainFrame)
    static UINT indicators[] =
    {
    	ID_SEPARATOR,           // status line indicator
    	ID_PARSE_TIME,	// parsing time
    	ID_INDICATOR_CAPS,
    	ID_INDICATOR_NUM,
    	ID_INDICATOR_SCRL,
    };
    
  3. 텍스트 크기가 잘릴 것을 대비해 OnCreate()에서 길이를 늘려줌.
    m_wndStatusBar.SetPaneInfo(1, ID_PARSE_TIME, SBPS_NORMAL, 50);
    
  4. m_wndStatusBar가 protected로 선언했기 때문에 Statusbar 텍스트를 변경하는 함수를 만듦. public으로 변수를 만들어서 함수를 만들지 않고 직접 변수에 접근하여 컨트롤 할 수 있음
    BOOL CMainFrame::SetPaneText(int nIndex, LPCTSTR lpszNewText)
    {
    	return m_wndStatusBar.SetPaneText(nIndex, lpszNewText);
    }
    
  5. 텍스트 변환
    CMainFrame* pMainFrame = (CMainFrame*) ::AfxGetMainWnd();
    // CMFCStatusBar* pStatus = &pMainFrame->m_wndStatusBar;
    
    CString tmp;
    float t = m_htmlFile.get_parse_time();
    tmp.Format(L"%5.3f sec", t);
    
    pMainFrame->SetPaneText(1, tmp);
    // pStatus->SetPaneText(1, tmp);
    
  6. 활성 상태로 변환(Message map 연결)
    • afx_msg void OnUpdateParseTime(CCmdUI* pCmdUI);
      
    • ON_UPDATE_COMMAND_UI(ID_PARSE_TIME, OnUpdateParseTime)
      
    • void CMainFrame::OnUpdateParseTime(CCmdUI* pCmdUI)
      {
      	pCmdUI->Enable();
      }
      

Reference

Comments