哦,不!我的文字闪烁?
基本上,我正在尝试创建一个应用程序,该应用程序具有一堆彩色矩形,上面写有文本,您可以单击这些矩形,使其执行一些操作。它运行得很好,除了每个按钮上的文本(使用 DrawText() 创建)不断闪烁。我能做些什么来解决这个问题吗?
Basically, I'm trying to create an application that features a bunch of colored rectangles with text written on them that you can click, making it doing stuff. It runs pretty well, except for the fact that the text on each of the buttons (Created using DrawText()) is constantly flickering. Is there anything I can do to potentially fix this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从上面的评论中,您描述了从主消息循环中调用应用程序对象的绘制过程。这几乎肯定是您问题的根源。它不仅会导致闪烁,而且听起来您的应用程序正在以 100% CPU 利用率运行,这并不好。
您应该做的是处理
WM_PAINT
消息,并且仅根据该消息进行绘制。这就是 Windows GUI 应用程序的工作原理。我建议您阅读任何介绍性 Windows GUI 书籍。此类经典书籍是 Petzold 的《Programming Windows》。From your comment above, you describe calling the draw procedure of your application object form your main message loop. This is almost certainly the source of your problem. Not only will it lead to flickering, it sounds like you are running your application at 100% CPU utilization which is not good.
What you should do is handle the
WM_PAINT
message and only paint in response to that message. That is how Windows GUI apps are meant to work. I recommend you read up in any introductory Windows GUI book. The canonical such book is Petzold's Programming Windows.