Windows Foundation Structs

This section details the fundamental data structures (structs) used within the Windows Foundation API. These structures are crucial for representing various entities, properties, and states within the operating system and its applications. Understanding these structs is essential for effective Windows development.

Overview of Structs

Structs in Windows programming are value types that encapsulate related data fields. They are often used to:

Core Data Structures

RECT Structure

The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle.

Definition

typedef struct _RECT { LONG left; LONG top; LONG right; LONG bottom; } RECT;
  • left: The x-coordinate of the upper-left corner.
  • top: The y-coordinate of the upper-left corner.
  • right: The x-coordinate of the lower-right corner.
  • bottom: The y-coordinate of the lower-right corner.

Commonly used in functions like GetClientRect and InvalidateRect.

POINT Structure

The POINT structure defines a coordinate point in two-dimensional space.

Definition

typedef struct _POINT { LONG x; LONG y; } POINT;
  • x: The x-coordinate.
  • y: The y-coordinate.

Used in functions such as ClientToScreen and GetCursorPos.

SIZE Structure

The SIZE structure specifies the width and height of a rectangle or window.

Definition

typedef struct _SIZE { LONG cx; LONG cy; } SIZE;
  • cx: The width.
  • cy: The height.

Often used with functions that require dimensions, like GetWindowRect (though RECT is more common there).

System Information

SYSTEMMETRICS (or related functions)

While there isn't a direct `SYSTEMMETRICS` struct passed around commonly, the GetSystemMetrics function returns various system metric values. These values often represent dimensions or states, and can be thought of conceptually as parts of a system metrics structure.

GetSystemMetrics takes an index that specifies the system metric to retrieve. Examples include:

LONG screenWidth = GetSystemMetrics(SM_CXSCREEN); LONG screenHeight = GetSystemMetrics(SM_CYSCREEN);

WINDOWINFO Structure

The WINDOWINFO structure contains information about a window.

Definition

typedef struct tagWINDOWINFO { DWORD cbSize; RECT rcWindow; RECT rcClient; DWORD dwStyle; DWORD dwExStyle; DWORD cchWindowText; int cxWindowBorders; int cyWindowBorders; ATOM atomWindowType; } WINDOWINFO;

This struct provides details such as the window's bounding rectangle (rcWindow), client area rectangle (rcClient), styles (dwStyle, dwExStyle), and border dimensions.

Used with the GetWindowInfo function.