Message loop in Microsoft Windows

The message loop is an obligatory section of code in every program that uses a graphical user interface under Microsoft Windows.

To accept user input, and for other reasons, each thread with a window must continuously retrieve messages from its queue, and act on them.

A programmer makes the process do that by writing a loop that calls GetMessage (which blocks for a message and retrieves it), and then calls DispatchMessage (which dispatches the message), and repeats indefinitely.

Code can also send messages directly to a window procedure.

Modern graphical interface frameworks, such as Windows Forms, Windows Presentation Foundation, MFC, Delphi, Qt, and others do not require applications to code a Windows message loop, because they automatically route events such as key presses and mouse clicks to their appropriate handlers as defined within the framework.