以非常高的速率设置cbutton文本 [英] Setting cbutton text at very high rates

查看:69
本文介绍了以非常高的速率设置cbutton文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 CButton 派生类,它是从一个独立的线程以非常高的速率写入的(通过 PostMessage ,处理程序执行 SetWindowText )。在某些情况下,独立线程比UI更新工作得更快,因此其 PostMessage 调用会导致冻结UI。



这在Windows中不是一个大问题,它只在某些情况下发生,而且我已经找到一个让它一直工作的补丁,但它会导致Linux中的主要问题(通过WINE运行)。



我想知道是否有办法基本上做什么 SetWindowText()没有实际调用该调用(我可以加载成员变量)?问题是调用同步工作,并且在一个甚至看不到的窗口上调用时非常无效(即使没有绘图也很慢,是的,我知道它是 SendMssage with WM_SETTEXT )。自己检查窗口状态会更快,但是如果你这样做,你可能会错过在关闭时更新窗口。



我想我可以用加载变量替换处理程序在自定义绘制/绘制例程中解释。只是想知道是否有其他人建议对 CButton 对象进行高速文本更新(在多线程环境中)。

I have a CButton derived class that's being written to at a very high rate from an independent thread (does it through a PostMessage, the handler does SetWindowText). Under some circumstances, the independent thread works faster than the UI updates, so its PostMessage calls result in freezing the UI.

This isn't a huge problem in Windows, it only happens under certain circumstances and I already figured out a patch that makes it work all the time, but it causes major headaches in Linux (being run through WINE).

I was wondering if there's a way to essentially do what SetWindowText() does without actually calling that call (member variable I can load)? Problem is the call works synchronously and is very ineffective when being called on a window that isn't even visible (slow even though there's no drawing occurring, and yes, I know it's a SendMssage with WM_SETTEXT). It's faster to check the window status yourself but if you do that you may miss updating the window when it's closed.

I guess I can replace the handler with just loading variables that are interpreted on a custom paint/draw routine. Just want to know if anyone else has suggestions for high-speed text updates to a CButton object (in a multithreaded environment).

推荐答案

而不是发送消息和/或调用按钮编写代码很多,为什么不只是以你想要的速率写入一个值并让按钮每500毫秒更新一次?您可以使用具有固定间隔的计时器,也可以让按钮更新代码在完成当前更新任务时自行发送一次性计时器。这样消息循环就不会陷入困境,如果系统繁忙,按钮更新会稍微退一步。



我在这里所说的适用于更新号码。如果数据很复杂或者是文本,则创建一个新数据项并(原子地)更新指向当前数据的指针。确保正确处理过时数据的内存管理(不要泄漏)。如果数据更新只有一个逻辑路径,则可以使用双缓冲和当前值指针(修复泄漏问题)。如果有多个更新路径,则需要更复杂的缓冲方案。
Instead of sending messages and/or calling the button write code a lot, why don't you just write to a value at whatever rate you want and have the button update itself every 500 milliseconds or so? You could either use a timer with a fixed interval, or have the button update code send itself a "one-off" timer when it completes the current update task. That way the message loop doesn't get bogged down, and the button updates will back off a little if the system otherwise gets busy.

What I said here applies to updating a number. If the data instead is complex or is text, create a new data item and update (atomically) the pointer to the "current" data. Be sure to properly handle memory management for the stale data (don't leak). If there is only one logic path for the data updates, you could use double buffering and a "current value" pointer (which fixes the leak problem). If there is more than one update path, you will need a more complicated buffering scheme.


您必须控制更新有用的频率。我想每秒超过50次更新真的没意义。使用PostMessage(仅填充消息队列)和WM_SETTEXT。



运行自己的线程,通过读取准备好的变量来更新文本。只有更改才能更新。



Mantra:避免做不需要的东西来加速。
You have to have control how often an update is useful. I guess at more than 50 update per second makes really no sense. Use PostMessage (only fills the message queue) and WM_SETTEXT.

Run a own thread which updates the text by reading a prepared variable. Only update if changed.

Mantra: Avoid doing unneeded stuff to speed up.


这篇关于以非常高的速率设置cbutton文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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