MSDN Documentation

User Interface Core APIs

This section provides comprehensive documentation for the core Windows API functions used to create and manage the graphical user interface (GUI) of Windows applications. It covers fundamental concepts like windows, controls, messages, and graphics rendering.

Window Management

Functions for creating, managing, and manipulating windows.

CreateWindowEx

HWND CreateWindowEx( DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam );

Creates an overlapped, pop-up, or child window. It can specify the extended window style, class, window name, size, position, and parent window.

Parameters:

  • dwExStyle: Extended window styles.
  • lpClassName: Registered class name.
  • lpWindowName: Window text.
  • dwStyle: Window styles.
  • x, y, nWidth, nHeight: Position and dimensions.
  • hWndParent: Handle to parent or owner window.
  • hMenu: Handle to menu or child-window identifier.
  • hInstance: Handle to application instance.
  • lpParam: Pointer to window creation data.

Return Value:

  • If the function succeeds, the return value is a handle to the new window.
  • If the function fails, the return value is NULL.

DestroyWindow

BOOL DestroyWindow( HWND hWnd );

Destroys the specified window. The function sends a WM_DESTROY message to the window to be destroyed after it is removed from the screen.

Parameters:

  • hWnd: Handle to the window to be destroyed.

Return Value:

  • If the function succeeds, the return value is nonzero.
  • If the function fails, the return value is zero.

Controls

APIs for common UI elements like buttons, text boxes, and lists.

Graphics and Drawing

Functions for rendering graphics, drawing shapes, and managing device contexts.

GetDC

HDC GetDC( HWND hWnd );

Retrieves a handle to a Device Context (DC) for the client area of a specified window.

Parameters:

  • hWnd: Handle to the window with a client area that the specified device context will represent.

Return Value:

  • A handle to the device context.
  • NULL if the request fails.

ReleaseDC

int ReleaseDC( HWND hWnd, HDC hDC );

Releases a device context (DC), freeing it for use by other applications.

Parameters:

  • hWnd: Handle to the window whose DC is to be released.
  • hDC: Handle to the device context to be released.

Return Value:

  • 1 if the DC was released.
  • 0 if the DC was not released.

Input Handling

APIs for processing keyboard and mouse input.

Functions for creating and managing application menus and dialog boxes.

DialogBoxParam

INT_PTR DialogBoxParam( HINSTANCE hInstance, LPCTSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, LPARAM dwInitParam );

Creates a modal dialog box from a dialog box template defined in a resource file.

Parameters:

  • hInstance: Handle to the module that contains the dialog box template.
  • lpTemplateName: Pointer to a null-terminated string that specifies the resource name of the dialog box template.
  • hWndParent: Handle to the owner window.
  • lpDialogFunc: Pointer to the dialog box procedure.
  • dwInitParam: Value the dialog box procedure can use to initialize the dialog box.

Return Value:

  • The return value is the value passed to SetWindowLongPtr using the DWLP_MSGRESULT index to set the dialog box's message-processing result.
  • If the template specified is not found, or if there is not enough memory to create the dialog box, or if the template is invalid, the return value is -1.

Window Messages

Understanding and handling Windows messages.

The core of Windows GUI programming involves message loops and message handling. Applications receive messages from the system and other applications, which are then dispatched to the appropriate windows.


LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch (uMsg) {
        case WM_PAINT: {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hwnd, &ps);
            // Paint content here
            FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW+1));
            EndPaint(hwnd, &ps);
            return 0;
        }
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        default:
            return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
}