dialog-layout latest
Loading...
Searching...
No Matches
layout.h File Reference

Win32 dialog dynamic layout engine API. More...

#include <windows.h>
#include <tchar.h>
Include dependency graph for layout.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

Anchor flags

Anchor bitmasks used to define control layout behavior in a dialog.

#define ANCOR_LEFT   0x0001
 Anchor control to the left edge.
 
#define ANCOR_TOP   0x0002
 Anchor control to the top edge.
 
#define ANCOR_LEFT_TOP   (ANCOR_LEFT | ANCOR_TOP)
 Anchor control to both left and top edges.
 
#define ANCOR_RIGHT   0x0004
 Anchor control to the right edge.
 
#define ANCOR_RIGHT_TOP   (ANCOR_RIGHT | ANCOR_TOP)
 Anchor control to both right and top edges.
 
#define ANCOR_BOTTOM   0x0008
 Anchor control to the bottom edge.
 
#define ANCOR_LEFT_BOTTOM   (ANCOR_LEFT | ANCOR_BOTTOM)
 Anchor control to both left and bottom edges.
 
#define ANCOR_RIGHT_BOTTOM   (ANCOR_RIGHT | ANCOR_BOTTOM)
 Anchor control to both right and bottom edges.
 

Functions

void attach_layout (HANDLE resource, HWND dialog, LPCTSTR layout_resource_name)
 Attach a dynamic layout to a dialog box using a layout resource.
 
void init_layout (HWND dialog)
 Initialize dynamic layout management for a dialog.
 
BOOL anchor_control (HWND dialog, DWORD control_id, WORD anchor_topleft, WORD anchor_bottomright)
 Anchor an individual control to specific edges of the dialog, overriding any previous anchor.
 

Detailed Description

Win32 dialog dynamic layout engine API.

This header provides functions and macros for attaching, detaching, and managing dynamic layouts in Win32 dialog boxes. Controls in a dialog can be anchored to dialog edges to provide responsive resizing behavior.

Macro Definition Documentation

◆ ANCOR_BOTTOM

#define ANCOR_BOTTOM   0x0008

Anchor control to the bottom edge.

◆ ANCOR_LEFT

#define ANCOR_LEFT   0x0001

Anchor control to the left edge.

◆ ANCOR_LEFT_BOTTOM

#define ANCOR_LEFT_BOTTOM   (ANCOR_LEFT | ANCOR_BOTTOM)

Anchor control to both left and bottom edges.

◆ ANCOR_LEFT_TOP

#define ANCOR_LEFT_TOP   (ANCOR_LEFT | ANCOR_TOP)

Anchor control to both left and top edges.

◆ ANCOR_RIGHT

#define ANCOR_RIGHT   0x0004

Anchor control to the right edge.

◆ ANCOR_RIGHT_BOTTOM

#define ANCOR_RIGHT_BOTTOM   (ANCOR_RIGHT | ANCOR_BOTTOM)

Anchor control to both right and bottom edges.

◆ ANCOR_RIGHT_TOP

#define ANCOR_RIGHT_TOP   (ANCOR_RIGHT | ANCOR_TOP)

Anchor control to both right and top edges.

◆ ANCOR_TOP

#define ANCOR_TOP   0x0002

Anchor control to the top edge.

Function Documentation

◆ anchor_control()

BOOL anchor_control ( HWND dialog,
DWORD control_id,
WORD anchor_topleft,
WORD anchor_bottomright )

Anchor an individual control to specific edges of the dialog, overriding any previous anchor.

Registers or overrides the anchor points for the specified control in the layout engine. This function can be used after attach_layout() to override anchors loaded from a resource, or after init_layout() to add anchors manually.

Parameters
dialogHandle to the dialog box (HWND).
control_idControl ID (e.g., IDC_BUTTON_OK).
anchor_topleftAnchor flags for the control's top-left corner (see Anchor flags).
anchor_bottomrightAnchor flags for the control's bottom-right corner (see Anchor flags).
Returns
TRUE if the anchor was set successfully, FALSE on error (e.g., illegal anchor or control not found).
Note
It is safe to use anchor_control() after attach_layout() to override anchors set by the resource, or to add anchors for additional controls at runtime.

Example usage:

attach_layout(hInstance, hDlg, MAKEINTRESOURCE(ID_MAINDIALOG_LAYOUT));
anchor_control(hDlg, IDC_MY_BUTTON, ANCOR_RIGHT | ANCOR_BOTTOM, ANCOR_RIGHT | ANCOR_BOTTOM); // override/add anchor
void attach_layout(HANDLE resource, HWND dialog, LPCTSTR layout_resource_name)
Attach a dynamic layout to a dialog box using a layout resource.
Definition layout.c:361
#define ANCOR_RIGHT
Anchor control to the right edge.
Definition layout.h:37
BOOL anchor_control(HWND dialog, DWORD control_id, WORD anchor_topleft, WORD anchor_bottomright)
Anchor an individual control to specific edges of the dialog, overriding any previous anchor.
Definition layout.c:381
#define ANCOR_BOTTOM
Anchor control to the bottom edge.
Definition layout.h:41

◆ attach_layout()

void attach_layout ( HANDLE resource,
HWND dialog,
LPCTSTR layout_resource_name )

Attach a dynamic layout to a dialog box using a layout resource.

Loads the layout information from the specified resource and applies it to the dialog, so its controls will resize and move according to the layout rules when the dialog is resized.

Parameters
resourceHandle to the module containing the resource.
dialogHandle to the dialog box (HWND).
layout_resource_nameName of the layout resource (e.g., MAKEINTRESOURCE(ID_MAINDIALOG_LAYOUT)).
Note
Call this function in WM_INITDIALOG after creating the dialog.

Example usage:

attach_layout(hInstance, hDlg, MAKEINTRESOURCE(ID_MAINDIALOG_LAYOUT));

◆ init_layout()

void init_layout ( HWND dialog)

Initialize dynamic layout management for a dialog.

Prepares the dialog for dynamic layout by creating an internal layout structure. Controls can then be anchored individually using anchor_control().

Parameters
dialogHandle to the dialog box (HWND).
Note
Call this function in WM_INITDIALOG if you are not using a layout resource table, and plan to manually anchor controls using anchor_control().

Example usage:

void init_layout(HWND dialog)
Initialize dynamic layout management for a dialog.
Definition layout.c:368