CStatus类更新状态条上的现实内容 访问冲突 问题

    一直想使用状态条动态显示文字。程序采用SDI不带Doc/View支持的架构。m_wndStatusBar可以访问,而且我就在MainFrm.cpp内使用。但是,我在使用GetPaneText()或者SetPaneText()总是出现访问冲突错误,其他相关的方法也是如此。一直觉得奇怪,这些方法都是属于CStatusBar类的,怎么就不能用了,不能用的话,什么方法用来达到同样的目的?

   终于找到有关的资料,提到CStatusBar类创建后,面板的默认值是禁用的。真觉得vc++怎么故意在制造障碍。搜到相关的描述如下:

 

  By default, a CStatusBar pane is not enabled when the pane is created. To activate a pane, you must call the ON_UPDATE_COMMAND_UI() macro for each pane on the status bar and update the panes. Because panes do not send WM_COMMAND messages, you cannot use ClassWizard to activate panes; you must type the code manually. For example, suppose one pane has ID_INDICATOR_PAGE as its identifier and that it contains the current page number in a document. To make the ID_INDICATOR_PAGE pane display text, add the following to a header file (probably the MAINFRM.H file):

afx_msg void OnUpdatePage(CCmdUI *pCmdUI);

//Add the following to the application message map:
ON_UPDATE_COMMAND_UI(ID_INDICATOR_PAGE, OnUpdatePage)

//Add the following to a source code file (probably MAINFRM.CPP):
void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
    pCmdUI->Enable();
}

To display text in the panes, either call SetPaneText() or call CCmdUI::SetText() in the OnUpdate() function. For example, you might want to set up an integer variable m_nPage that contains the current page number. Then, the OnUpdatePage() function might read as follows:

void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
    pCmdUI->Enable();
    char szPage[16];
    wsprintf((LPSTR)szPage, "Page %d", m_nPage);
    pCmdUI->SetText((LPSTR)szPage);
}

This technique causes the page number to appear in the pane during idle processing in the same manner that the application updates other indicators.

 

照着上面的描述,算是把问题解决了。状态栏内自已定义的面板可以动态显示文本了。不过还是觉得VC++跟VB比较起来,做同样的事情,代码书写繁琐多了,而且代码的错误提示让人坠入迷雾,如果不去搜索引擎,很难找到问题的根本原因!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值