由于其他窗口消息不起作用,循环中的postmessage很长时间 [英] Postmessage in loop for long due to which other window messages are not working

查看:302
本文介绍了由于其他窗口消息不起作用,循环中的postmessage很长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

这次我的问题没有以代码的形式进行总结。但是我用不同的方式问它。

我正在研究mfc应用程序,并且有一个条件我使用

 PostMessage <发布窗口消息/ pre>它正在循环中执行 

现在过了一段时间后如果我按左上角的关闭按钮不接受它,原因是消息循环正在处理循环生成的其他窗口消息。我知道它的直接问题..我有办法 关闭窗口(WM_CLOSE)的优先级高于其他窗口消息。

注意:我不能跳过发布你可以假设循环为30000的消息。



任何建议或链接将是有益的..



提前感谢



在您的回复后延长都感谢大家的回答。是的可以重新设计可能让我先告诉你我有一个视频录像说1天。我正在基于事件提取帧。假设它每秒给出一帧,因此数据非常大。在这种情况下我在做什么。我正在提取框架并​​进行postmessage以显示在listcontrol中。原因我为什么要进行postmessage,因为我不需要阻止对话框(无模型),并且线程数据中发生的事情不断发生。需求:如果有任何解决方案,我可以避免消息循环将有益。

解决方案

看看 PostQuitMessage [ ^ ]尝试使用此消息循环。



它还说

Quote:

每个消息队列的发布消息数限制为10,000。这个限制应该足够大。如果您的应用程序超出限制,则应该重新设计以避免消耗这么多系统资源。要调整此限制,请修改以下注册表项。


您的问题的答案基本上是:不,没有办法给予消息比其他消息更高的优先级。对于Windows设计者来说,尽可能高效地实现消息队列更为重要,他们自愿放弃优先消息处理等奢侈品。



有一个例外规则:WM_PAINT消息是专门处理的,并且总是最后处理,即当队列中没有其他消息时;同一个窗口的几个WM_PAINT被组合在一起以进一步减少绘制开销。



正如SA已经指出的那样:将大约30000条消息发送到您的消息队列可能不是最明智的事情。因此,请重新考虑您的应用并找到限制消息发布数量的方法,例如:通过使用一个简单的中间类来计算未完成的帖子的数量并将海报阻止在合理的阈值 - 只要消费方处理了其中一些消息。



并且SA也说:如果你告诉我们你实际想要完成什么,我们或许可以提供一些更具体的提示。


你可以做的一件事就是您的消息处理循环,定期执行PeekMessage()并查找终止消息。这将对消息产生优先级提升效果。不要经常这样做,因为这是要求查看整个消息列表,直到找到所需的消息(即整个列表,如果它不存在)。


Hi guys
well this time my question is not summarized in form of code. but i am asking it in different way.
I am working on mfc application and there is a condition in which i am posting window messages by using

PostMessage

it is executing in a loop
Now after some time if i press close button at upper left corner that is not accepting it as the reason is message loop is processing other window messages which are generated in loop. I know its straight question..is there is way that i can do that the priority of the close window (WM_CLOSE) will be high than the other window messages.
Note: i cannot skip from posting the messages you can assume that is in loop of 30000.

any suggestion or link will be beneficial..

thanks in advance

Extended after your response Hi all first of all thanks everyone for answering. Yes there can be redesigned possible let me first tell you i do have a video recording of say 1 day. i am extracting frames on the basis of events.Suppose it is giving one frame at each second so data is extremely large. In this case what i am doing. i am extracting frame and do postmessage to display in listcontrol. Reason Why i am doing postmessage because i do not need to block the dialog(modelless) and it happening in thread data is coming continuously. Requirment: if there is any solution that i can avoid message loop will beneficial.

解决方案

Have a look at PostQuitMessage[^] try this to comeout of the message loop.

It also says

Quote:

There is a limit of 10,000 posted messages per message queue. This limit should be sufficiently large. If your application exceeds the limit, it should be redesigned to avoid consuming so many system resources. To adjust this limit, modify the following registry key.


The answer to your question is basically: No, there is no way of giving a message a higher priority than others. For the Windows designers it was more important to implement the message queue as efficiently as possible and they voluntarily abstained from "luxuries" like prioritized message handling.

There is one exception to the rule: WM_PAINT message are treated specially and are always processed last, i.e. when no other message remain in the queue; several WM_PAINTs to the same window are combined to reduce the painting overhead even further.

As SA already pointed out: Blowing some 30000 messages onto your message queue is probably not the wisest thing to do. So re-think your application and find a way to limit the number of message posts, e.g. by using a simple intermediate class that counts the number of outstanding posts and blocks the poster at a reasonable threshold -- for as long as the consuming side has processed some of those messages.

And as SA also said: If you tell us what you are actually trying to accomplish we could perhaps help with some more concrete hints.


One of the things you can do is in your message processing loop, do a PeekMessage() periodically and look for a termination message. This will have the effect of a priority boost to the message. Don''t do this frequently since this is a request to look through the entire message list until the desired message is found (ie. the entire list if it is not there).


这篇关于由于其他窗口消息不起作用,循环中的postmessage很长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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