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 不会在每次更改其文本时都失效
基础教程推荐
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- c++ STL设置差异 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
