Windows API Reference

User32 Functions

The User32.dll library provides functions that manage the Windows user interface. These functions handle user input, window management, dialog boxes, controls, menus, and more.

Commonly Used Functions

CreateWindowEx

Creates an overlapped, top-level window. It specifies a class by atom or null-terminated string, window name, window style, and optionally specifies the parent window and menu of the window.

HWND CreateWindowEx( _In_ DWORD dwExStyle, _In_opt_ LPCSTR lpClassName, _In_opt_ LPCSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam );

MessageBox

Creates, displays, and operates a message box window. A message box is a dialog box that can display application-defined information and request user input.

int MessageBox( _In_opt_ HWND hWnd, _In_opt_ LPCSTR lpText, _In_opt_ LPCSTR lpCaption, _In_ UINT uType );

GetMessage

Retrieves messages from the calling thread's message queue and places the message into the specified structure. The thread must have an associated message queue.

BOOL GetMessage( _Out_ LPMSG lpMsg, _In_opt_ HWND hWnd, _In_ UINT wMsgFilterMin, _In_ UINT wMsgFilterMax );

DispatchMessage

Passes a message to the appropriate window procedure for processing. A message is retrieved by the GetMessage function.

LRESULT DispatchMessage( _In_ const MSG *lpmsg );

PostMessage

Posts a message to a thread's message queue and returns without waiting for the thread to process the message. The thread places the message in its message queue by calling the PostThreadMessage function.

BOOL PostMessage( _In_opt_ HWND hWnd, _In_ UINT Msg, _In_ WPARAM wParam, _In_ LPARAM lParam );

GetClientRect

Retrieves the dimensions of a window's drawing area. The drawing area is the portion of the window available for painting.

BOOL GetClientRect( _In_ HWND hWnd, _Out_ LP="'$(H' RECT lpRect );

SetFocus

Activates a specified window. The window is brought to the foreground and activated. Keyboard input is directed to the window. The system returns the handle of the window that previously had the keyboard focus.

HWND SetFocus( _In_ HWND hWnd );

Window Management

DestroyWindow

Destroys the specified window. In addition to erasing the window from the screen, this function sends messages to the window and its children.

BOOL DestroyWindow( _In_ HWND hWnd );

ShowWindow

Sets the show state of a window. The show state is one of the SW_ constants.

BOOL ShowWindow( _In_ HWND hWnd, _In_ int nCmdShow );

Message Handling

TranslateMessage

Translates virtual-key messages into character messages. The character messages are posted to the calling thread's message queue, to be retrieved later by the GetMessage function.

BOOL TranslateMessage( _In_ const MSG *lpmsg );

PeekMessage

Examines the calling thread's message queue for a message of the specified type and, if one is found, retrieves it into the structure specified by the lpMsg parameter. The message is not removed from the queue.

BOOL PeekMessage( _Out_ LPMSG lpMsg, _In_opt_ HWND hWnd, _In_ UINT wMsgFilterMin, _In_ UINT wMsgFilterMax, _In_ UINT wRemoveMsg );