System Layout API Reference

msdn.microsoft.com/windows/api/system/layout

This document provides a comprehensive reference for the System Layout API in Windows. These functions allow developers to interact with and manage the visual and structural layout of windows and controls within the Windows operating system.

Note: This API is part of the core Windows API and is essential for creating user interfaces that adhere to Windows design guidelines and provide consistent user experiences.

Key Concepts

Understanding the following concepts is crucial when working with the System Layout API:

Core Functions

The System Layout API provides a variety of functions for managing window positioning, sizing, and visibility. Here are some of the most commonly used functions:

SetWindowPos

Sets the size, position, and ordering of a window. This is one of the most fundamental functions for layout manipulation.

BOOL SetWindowPos(
  HWND hWnd,
  HWND hWndInsertAfter,
  int  X,
  int  Y,
  int  cx,
  int  cy,
  UINT uFlags
);

Parameters:

GetWindowRect

Retrieves the dimensions of the bounding rectangle of a window. The dimensions are in screen coordinates relative to the upper-left corner of the screen.

BOOL GetWindowRect(
  HWND   hWnd,
  LPRECT lpRect
);

Parameters:

MoveWindow

Changes the size and position of a given window. This function is similar to SetWindowPos but is often simpler for basic repositioning.

BOOL MoveWindow(
  HWND hWnd,
  int  X,
  int  Y,
  int  nWidth,
  int  nHeight,
  BOOL bRepaint
);

Parameters:

Layout Structures

The API uses several structures to define positions and dimensions:

Structure Description
RECT Defines the coordinates of the upper-left and lower-right corners of a rectangle.
POINT Defines a point in two-dimensional space.
SIZE Defines the width and height of a rectangular area.

DPI Scaling

Modern Windows applications must be DPI aware to ensure proper scaling on high-resolution displays. The System Layout API includes functions to help manage this:

Tip: Always ensure your application declares its DPI awareness level to the system for optimal visual presentation.

Example Usage

Here's a simplified example of how to move a window to a specific position and size:

HWND hWnd = GetActiveWindow(); // Or GetForegroundWindow(), etc.
int newX = 100;
int newY = 100;
int newWidth = 400;
int newHeight = 300;

if (hWnd != NULL) {
    SetWindowPos(hWnd, NULL, newX, newY, newWidth, newHeight, SWP_NOZORDER | SWP_SHOWWINDOW);
}

Related Topics