Windows消息停止进入我的窗口 [英] Windows messages stop come to my window

查看:88
本文介绍了Windows消息停止进入我的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个显示视频图像但有时会停止画框的应用程序.
遇到此问题后,我对spy ++进行了一些调试,发现Windows消息不会出现在我的窗口中,因此它不会重新绘制,除非我在窗口上使用了鼠标指针并且在这种情况下消息出现了.
此行为在exe版本上也会发生,并且也会进行调试.
系统是intel i7 8核,cpu并未真正最大加载50-60%,有时会更少,我感到问题与cpu无关,因为有时我已经看到问题仅在15%的cpu负载下发生.
有没有人遇到过这样的问题,并且知道如何应对?
谢谢.

附加信息和问题

我需要定期接收WM_PAINT消息,如何强制从队列中定期检索此消息?

Hello to everybody,

I have an application that show video images but sometimes stop paint frames.
After experienced this problem I did some debug with spy++ and found that windows messages don''t come to my window therefore it doesn''t repaint, unless I go with mousepointer on the window and in this case messages come.
This behaviour happen on exe release and debug also.
System is intel i7 8 cores and cpu is not really loaded 50-60% max, sometimes less and I have the feel that the problem is not correlated to the cpu because sometimes I''ve seen the problem happen just with 15% cpu load.
Did anyone experience problem like this and have any idea how can I face it?
thank you.

ADDED INFO AND QUESTION

I need receive WM_PAINT message regularly, how can I force to regularly retrieve this message from the queue?

推荐答案

如果Windows不知道您的窗口需要重新粉刷,则不会发送WM_PAINT消息.

这不是您应该用来驱动动画的消息.您不能在需要时依靠Windows猜测.

在这种情况下,您可以尝试两种选择.

使用WM_TIMER消息调用Invalidate(FALSE);这将强制WM_PAINT消息.

或将OnPaint函数变成一个空调用以进行普通绘制,并以固定间隔在后台线程中进行绘制.如果这样做,则不要将两者混在一起.如果您的后台线程和OnPaint同时绘制,则会发生不好的事情.
If windows doesn''t know that your window needs to be repainted, then it won''t send a WM_PAINT message.

This isn''t a message that you should use to drive animation. You can''t depend on Windows guessing when you''ll need it.

You have two options that you may try for this scenario.

Use the WM_TIMER Message to call Invalidate(FALSE); This will force a WM_PAINT message.

Or turn the OnPaint function into an empty call for normal drawing and do your painting in a background thread at a regular interval. If you do this, do not mix the two. If your background thread and the the OnPaint are drawing at the same time, bad things will happen.


我遇到WM_TIMER消息无法进入窗口的问题.也许不一样.我通过使用PeekMessage而不是GetMessage函数解决了它.如果PeekMessage不起作用,则表示该消息未发布在您的消息队列中.在这种情况下,您必须在计时器上重绘,或者使窗口矩形无效.
通过使用Spy ++,您不会看到消息队列.您只会看到已经调度到窗口的消息.
I had problems with WM_TIMER messages not coming to window. Maybe it is not the same. I solved it by using PeekMessage instead of GetMessage function. If PeekMessage does not work, then it means the message is not posted in your message queue. In this case you have to do redraw on timer, or invalidate the window rect.
By using Spy++ you don''t see the message queue. You see only messages which are already dispatched to the window.


较低的CPU使用率似乎只是结果,而并非原因.您能否提供有关此问题的更多详细信息,例如处理窗口更新所需的消息以及程序停止工作时发生的情况.

您可以从一本名为《为什么程序失败》的书中看到更多的调试技术.

在Richard看来,似乎并非所有类型的消息都需要激活目标窗口.以我的经验,即使没有激活窗口,该程序仍然可以正常工作.
The lower CPU usage seems just the result, but not the reason. Could you give more details about this issue, such as what message you need to handle window update, and what happened when the program stop working.

You could see more debugging technique with a book named Why Programs Fail.

To Richard, it seems that not all type messages need the target window is actived. And in my experience, the program could still work even through the window is not actived.


这篇关于Windows消息停止进入我的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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