是否有像PeekMessage这样的函数不处理消息?

时间:2009-07-15 19:37:28

标签: windows windows-vista peekmessage

我试图无辜地打电话

PeekMessage(&msg, 0, WM_KEYDOWN, WM_KEYUP, PM_NOREMOVE | PM_NOYIELD);
在PeekMessage调用中,

和Windows Vista 64是处理消息。结果是我将重新加入我的绘画调用以及各种其他代码。

绘画在我们的应用程序中可能需要几秒钟,因此我们添加了PeekMessage调用以查看用户是否按下了某个键,因此我们可以中断该绘制并启动下一个绘制。我们几乎没有意识到Windows可以开始处理我们的消息。将绘画的真实作品放在一个单独的线程中是一个重大的重构...我们试图看看是否按下了特定键,或者是否旋转了鼠标滚轮或鼠标按钮来中断渲染。 / p>

我已经尝试专门添加代码以防止重新入侵,然后将绘制消息重新注入队列等等。这些都是非常危险的,并且有些情况下它不能正常工作。

我可以在PeekMessage调用中添加一些标志吗?我在MSDN上的文档中没有看到任何新内容。我真的需要一个不处理消息的PeekMessage。救命啊!

5 个答案:

答案 0 :(得分:5)

也许我错过了显而易见的事情,但是{em>它会{/ 3>} {/ 3>} :

  

PeekMessage函数调度   传入发送消息,检查   发布的线程消息队列   消息,并检索消息(如果   任何存在的。)

...

  

在此通话期间,系统会发送   待处理的非排队消息,即   邮件发送到Windows所拥有的   使用SendMessage调用线程,   SendMessageCallback,   SendMessageTimeout,或   SendNotifyMessage函数。那么   第一个排队的消息匹配   检索指定的过滤器。的的   系统也可以处理内部   事件即可。如果未指定过滤器,   消息在处理中   以下顺序:

     
      
  • 已发送消息
  •   
  • 已发布消息
  •   
  • 输入(硬件)消息和系统内部事件
  •   
  • 已发送消息(再次)
  •   
  • WM_PAINT 消息
  •   
  • WM_TIMER消息
  •   
     

之前检索输入消息   发布消息,使用wMsgFilterMin   和wMsgFilterMax参数。

答案 1 :(得分:2)

我认为这就是PeekMessage应该做的事情。它与GetMessage之间的唯一区别是GetMessage阻塞直到消息到达,而PeekMessage将返回TRUE或FALSE,具体取决于是否找到与筛选器匹配的消息。如果找到这些消息,它仍将处理消息。

答案 2 :(得分:1)

GetQueueStatus是检查是否有可用消息的最快方法。与5个peekmessage参数相比,它只会检查几个标志,只需要1个参数。如果有可用的消息,它会给出快速提示,它不会以任何方式处理消息。

GetQueueStatus和GetInputStatus是相关的函数。

答案 3 :(得分:0)

PeekMessage处理消息,因为PeekMessage就是这样做的。

可能它的命名很糟糕,但是如果有可用的话,PeekMessage会从队列中删除该消息。

答案 4 :(得分:-1)

Just modified the PM_REMOVE flag for the PM_NOREMOVE





using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PROJECT_NAME
{
    class cUtil
    {
        //===============================
        cUtil()
        {
        }
        //================================
        ~cUtil()
        {
        }
        //=================================
        public struct Message
        {
            public IntPtr handle;
            public uint msg;
            public IntPtr wParam;
            public IntPtr lParam;
            public uint time;
            public System.Drawing.Point p;
        }

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool PeekMessage(out Message lpMsg, Int32 hwnd, Int32 wMsgFilterMin, Int32 wMsgFilterMax, uint wRemoveMsg);
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern bool TranslateMessage(out Message lpMsg); //(ref Message lpMsg);
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        private static extern Int32 DispatchMessage(out Message lpMsg); //(ref Message lpMsg);

        //private static uint PM_NOREMOVE = 0x0000;
        private static uint PM_REMOVE = 0x0001;
        //private static uint PM_NOYIELD = 0x0002;
        public static void Peek()
        {
            Message winMsg;
            while (PeekMessage(out winMsg, (Int32)0, (Int32)0, (Int32)0, PM_REMOVE))
            {
                TranslateMessage(out winMsg);
                DispatchMessage(out winMsg);
            }

        }
    }
}


//================================
//================================
//===============================

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PROJECT_NAME
{
    public partial class foNAME : Form
    {
        //===================================
        public foRAMQ()
        {
            InitializeComponent();
        }
        //===================================
        private void Job()
        {
            int cnt = 0;

            while( reading_DBMS() )
            {
                cUtil.Peek();

                .
                .
                .
                .
                .
                cnt++;
                lable_count.Text = string.Format("Count: {0}", cnt )            
            }
    }


    }
}
相关问题