在Dialog中添加状态栏

参考:http://www.cppblog.com/besterChen/archive/2009/04/03/78846.aspx

 

  1. 创建字符资源:ID_INDICATOR_1、ID_INDICATOR_2
  2. CMyDialog.h中,添加类成员变量 CStatusBar m_wndStatusBar;
  3. CMyDialog.cpp中,添加全局变量:
static UINT indicators[] =
{
     ID_SEPARATOR,  //  status line indicator
 
     ID_INDICATOR_1,
     ID_INDICATOR_2
};

      初始化函数中,添加:

CRect rect;
this->GetClientRect(rect);
if(!m_wndStatusBar.Create( this)|| !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/ sizeof(UINT)))
{
    TRACE0( " Can't create status bar\n ");
     return FALSE;
}
m_wndStatusBar.MoveWindow( 0, rect.bottom- 20, rect.right,  20);  //  调整状态栏的位置和大小  

 

    在状态栏中显示信息

int nIndex = m_wndStatusBar.CommandToIndex(nID);
// m_wndStatusBar.SetPaneInfo(nIndex, nID, SBPS_NORMAL, 50);  //  调整显示栏宽度
m_wndStatusBar.SetPaneText(nIndex, wszText);

 

也可以这样显示:

SetMessageText(L"status bar msg."); // Call this function to place a string in the status-bar pane that has an ID of 0.

GetMessageBar()->SetWindowText(L"status bar msg.");

你可能感兴趣的:(dialog)