dialog-layout latest
Loading...
Searching...
No Matches
layout.c File Reference
#include <stdio.h>
#include "layout.h"
Include dependency graph for layout.c:

Classes

struct  LAYOUT_COORD
 
struct  LAYOUT_ITEM
 
struct  LAYOUT_ITEM_LIST
 
struct  LAYOUT
 Structure representing a dialog layout. More...
 
struct  LAYOUT_ITEM_RC
 
struct  LAYOUT_CHILD_PARAM
 

Typedefs

typedef struct LAYOUT_ITEM_LIST LAYOUT_ITEM_LIST
 

Functions

void attach_layout (HANDLE resource, HWND dialog, LPCTSTR layout_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.
 

Typedef Documentation

◆ LAYOUT_ITEM_LIST

typedef struct LAYOUT_ITEM_LIST LAYOUT_ITEM_LIST

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