Determinar la prioridad de un mensaje de ventana

Is there any way to programmatically check the priority of a window messages in its message queue?

For example: Some of window messages, WM_PAINT y WM_TIMER are known have the lowest priority and be placed after messages with highest priority.

I'm looking for something by which you can confirm that which one of two messages will have the lowest or highest priority or which message will be sent first or last?

preguntado el 27 de agosto de 11 a las 17:08

Regardless of whether that's possible, by depending on the order of messages you're using something that's not covered by the API contract. And that makes your program vulnerable to breaking in the future version of Windows (or another implementation like WINE). Don't do it. -

2 Respuestas

That's just not how it works, Windows messages don't have a priority attached. It is mostly determined by how the message is generated. A message loop dispatches messages in this order:

  • first any messages generated with SendMessage() are dispatched in the order in which the calls were made
  • next, any messages generated with PostMessage() and stored in the message queue, in queue order
  • next, any messages that are synthesized from the window state. WM_TIMER, WM_PAINT and WM_MOUSEMOVE fit this category.

The 'synthesized from the window state' clause is what makes WM_PAINT and WM_TIMER appear to have a low priority. And why moving the mouse rapidly doesn't flood the message queue with mouse messages. That is however not exclusive, you can for example call UpdateWindow() to force a WM_PAINT message to be sent, making it being dispatched with a 'high priority'.

Respondido el 12 de junio de 13 a las 01:06

I didn't know about the concept of synthesised messages. Do you know where I could find out more? I have read Petzold but I don't recall such nuances being discussed. - David Heffernan

@David - sorry, this is an amalgam of stuff I read over a decade and a half ago. I don't remember what magazines this was published in, they are long gone. - Hans Passant

@David: for WM_TIMER, MSDN docs msdn.microsoft.com/en-us/library/ms644902(v=vs.85).aspx - "the message is posted by the GetMessage or PeekMessage function" implies that it's generated on demand, rather than being posted to the queue directly as a result of an actual timer expiring. Similar wording seems to exist with WM_PAINT, though it's less explicit there. Also, support.microsoft.com/kb/96006 adds: "The WM_TIMER and WM_PAINT messages can be thought of as boolean toggles", hinting at this. I don't think it's in Petzold, but it comes up on Raymond Chen's blog once in a while. - BrendanMcK

A question to this answer: Is WM_KEYDOWN also lower rated than a WM_COMMAND message sent wth PostMessage? - xMRi

The order is defined in Getmessage / Peekmessage documentación:

If no filter is specified, messages are processed in the following order:

  • Mensajes enviados
  • Mensajes publicados
  • Mensajes de entrada (hardware) y eventos internos del sistema
  • Mensajes enviados (nuevamente)
  • WM_PAINT messages
  • Mensajes WM_TIMER

Respondido el 29 de enero de 19 a las 20:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.