CStatic does not invalidate every time its text is changed(CStatic 不会在每次更改其文本时都失效)
问题描述
我正在尝试动态更改 CStatic 控件的文本.我的成员变量名为 mStatic,类型为 CStatic.我已将 ID 更改为 IDC_MYSTATIC 而不是 IDC_STATIC.
I am trying to dynamically change the text of a CStatic control. My member variable is called mStatic of the type CStatic. I have changed the ID to IDC_MYSTATIC instead of IDC_STATIC.
当我想更改控件的文本时,我正在调用 mStatic.SetWindowText("asdfasdf").我会定期在计时器中执行此操作.
I am calling mStatic.SetWindowText("asdfasdf") when I want to change the text of the control. I do this periodically in a timer.
现在我遇到的问题是调用 SetWindowText() 后之前的文本没有被删除.它只是不断堆积,直到我在屏幕上弄得一团糟.
Now I have the problem that the previous text is not erased after I call the SetWindowText(). It just keeps piling up until I get a mess on the screen.
父窗口具有带位图背景的分层属性.我还设置了 color_key 属性,因此位图的某种颜色被视为透明(即它不会被绘制,并且会让鼠标消息通过).mStatic 控件绘制在具有位图背景的不透明部分上.
The parent window has the layered property with a bitmap background. I have also set the color_key property so a certain color of the bitmap is viewed as transparent (I.e. It will not be drawn and will let mouse messages through). The mStatic control is drawn on the parts not transparent, that have a bitmap background.
为什么窗口没有失效?
推荐答案
遇到了同样的问题.以下代码修复了它:
Had the same issue. The following code fixed it:
mStatic.SetWindowText("New text");
CRect rect;
mStatic.GetWindowRect(&rect);
ScreenToClient(&rect);
InvalidateRect(&rect);
UpdateWindow();
这篇关于CStatic 不会在每次更改其文本时都失效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CStatic 不会在每次更改其文本时都失效
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- CString 到 char* 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
