1.1.2 Queued Input

One of the biggest differences between Windows applications and standard C applications is the way in which they receive user input.

Input to an MS-DOS application is typically in the form of 8-bit characters read from the keyboard. The application reads these characters by calling the standard-input functions getchar and fscanf, which return ASCII or other codes corresponding to the keys pressed. The application can also intercept interrupts from input devices such as the mouse and timer to use information from those devices as input.

In a Windows application, all input from the keyboard, mouse, and timer is intercepted by Windows, which places the input in the appropriate application's message queue. When the application is ready to retrieve input, it simply reads the next input message from its message queue.

A Windows input message contains far more input information than is available in the standard MS-DOS environment. Such a message specifies the system time, the position of the mouse, the state of the keyboard, the scan code of the key (if a key was pressed), the mouse button pressed, as well as the device generating the message. For example, two keyboard messages, WM_KEYDOWN and WM_KEYUP, correspond to the pressing and releasing of a specific key. For each keyboard message, Windows provides a device-independent virtual-key code that identifies the key, the device-dependent scan code generated by the keyboard, and the status of other keys on the keyboard, such as SHIFT, CTRL, and NUMLOCK. Keyboard, mouse, and timer messages all have the same format and are all processed in the same manner.