Recent

Author Topic: Emptying message queue without processing  (Read 781 times)

simone

  • Full Member
  • ***
  • Posts: 123
Emptying message queue without processing
« on: March 08, 2018, 11:34:40 pm »
Dear all, is it possible to empty the message queue in a GUI application without processing the waiting messages? Thanks in advance.

ASerge

  • Hero Member
  • *****
  • Posts: 998
Re: Emptying message queue without processing
« Reply #1 on: March 09, 2018, 12:26:25 am »
Dear all, is it possible to empty the message queue in a GUI application without processing the waiting messages? Thanks in advance.
In Windows, the Application.ProcessMessages procedure first calls MsgWaitForMultipleObjects with Timeout = 0, and if there are messages, it performs a message queue clearing cycle:
Code: Pascal  [Select]
  1.       while PeekMessage(AMessage, HWnd(nil), 0, 0, PM_REMOVE) do
  2.       begin
  3.         if AMessage.message = WM_QUIT then
  4.         begin
  5.           PostQuitMessage(AMessage.wParam);
  6.           break;
  7.         end;
  8.         TranslateMessage(@AMessage);
  9.         DispatchMessageW(@AMessage);
  10.       end;
  11.