给StatusBar发送消息,来更改状态栏的显示信息

转自:http://joeblackzqq.blog.163.com/blog/static/16259543220109100224481/

新建一个单文档的MFC程序,在菜单的最后添加一个菜单项:

ID: IDM_TEST

Caption: test

去掉separator前面的“钩”,结果如下:

给StatusBar发送消息,来更改状态栏的显示信息 - Joe Black - 未来还有我
 
通过向导,给test菜单项添加点击事件,添加代码:
void CMainFrame::OnTest()  
{
 TCHAR* szText;
 static int count = 0;
 CString temp;
 count++;
 temp.Format("Hello world %d", count);
 szText = temp.GetBuffer(temp.GetLength());
  ::SendMessage(m_wndStatusBar, SB_SETTEXT, (WPARAM)0, (LPARAM)szText); // 第三个参数用来控制状态的第几栏(索引以0开始)
 temp.ReleaseBuffer(); // 在调用CString.GetBuffer()后,一般要调用CString.ReleaseBuffer()来释放空间
/*
 CString::ReleaseBuffer
 void ReleaseBuffer( int nNewLength = -1 );
 [Parameters]
   
 nNewLength
 
 The new length of the string in characters, not counting a null terminator.  
 If the string is null-terminated, the -1 default value sets the CString size to the current length of the string.
    
 [Remarks]
  
 Use ReleaseBuffer to end use of a buffer allocated by GetBuffer.  
 If you know that the string in the buffer is null-terminated, you can omit the nNewLength argument.  
 If your string is not null-terminated, then use nNewLength to specify its length.  
 The address returned by GetBuffer is invalid after the call to ReleaseBuffer or any other CString operation.
     
  */
}
快运行看看吧,达到了给状态栏发送消息的目的。
 
注:在子线程中一般是不可以直接修改状态栏上的文本信息的,所以最好的方法是通过发送消息的方法来实现。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值