CStatic 不会在每次更改其文本时都失效 [英] CStatic does not invalidate every time its text is changed

查看:16
本文介绍了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 不会在每次更改其文本时都失效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆