[win32] Messages

[win32] Messages


source #

  • Every window class has an associated message handling function (Window Proc)
  • All messages towards windows of a window class go to its window proc
  • If an application does not respond to messages for a few seconds it is counted as not responding.
  • There are two kinds of messages:
    • Unqueued messages : Windows calls the window proc directly with messages. This happens for example for WM_ACTIVATE, WM_SETFOCUS and WM_SETCURSOR.

      [I believe this can happen whenever we yield back to the system. These functions yield:

      • WaitMessage (explicit yield)
      • DialogBox
      • DialogBoxIndirect
      • DialogBoxIndirectParam
      • DialogBoxParam
      • GetMessage
      • MessageBox
      • PeekMessage
      • SendMessage

      ]

    • Queued messages: Are posted to a FIFO message queue. It is the application’s responsibility to pull messages off the queue via GetMessage or PeekMessage, and dispatch them to their corresponding window proc via DispatchMessage. Not all queued messages are processed in FIFO though. WM_PAINT, WM_TIMER, and WM_QUIT are kept in the queue until there are no other messages left. Also, multiple WM_PAINT messages are combined into one WM_PAINT message, that covers the union of all the to-be-redrawn area.

  • You can send your own messages in two ways
    • PostMessage: Creates a queued message
    • SendMessage: Create an unqueued message
  • The system does not automatically create a message queue for each thread. Instead, the system creates a message queue only for threads that perform operations which require a message queue. [source ]
Calendar October 22, 2023