Help Center
Help CenterAfxNovaWindows

CDialog Class

Members (8)

Documentation

CDialog Class

Introducing CDialog: A Streamlined Dialog Engine for FreeBasic

CDialog is a lightweight yet powerful dialog engine tailored for FreeBasic developers seeking a clean, high-level approach to building Windows dialogs — without sacrificing control or clarity. Inspired by the straightforwardness of PowerBasic’s DDT model, yet engineered with modern design in mind, CDialog offers structured, maintainable UI development rooted in the familiar logic of the Windows API.

At its core, CDialog replicates and refines the DDT engine, delivering cleaner syntax, robust internal architecture, and simplified message handling. Whether you're building modal or modeless dialogs, adding controls, or managing layout behavior, CDialog keeps things intuitive and transparent — no bloat, no black boxes.

Among its standout features is the automatic anchoring system, which minimizes the tedium of UI resizing logic. By applying simple declarative rules, it handles control repositioning and scaling automatically — sparing developers the hassle of manual calculations. Crucially, this system works identically for dialogs defined in pixels or dialog units, providing consistency and flexibility across design styles.

And for those who prefer procedural syntax, DDT.inc bridges the gap by exposing DDT-style wrappers atop the CDialog class — allowing developers to adopt CDialog incrementally or stick with the idioms they already know.

Whether you're modernizing legacy utilities, crafting new tools, or just writing code for fun, CDialog delivers a flexible, DPI-aware foundation that respects both your time and your muscle memory.

Include file: AfxNova/CDialog.inc.

NameDescription
ConstructorCreates instances of the CDialog class.
hDialogGets/sets the handle of the dialog.
IsModalChecks if the dialog is modal.
IsCustomChecks if it is a custom dialog.
UsesPixelsChecks if the dialog uses pixels.
UsesUnitsChecks if the dialog uses dialog units.

Dialog methods

NameDescription
DialogNewCreates a new dialog using dialog units.
DialogNewPixelsCreates a new dialog using pixels.
DialogShowModalShows the dialog as modal.
DialogShowModelessShows the dialog as modeless.
DialogEndEnds the dialog.
DialogEndResultReturns the value passed to DialogEnd.
DialogDoEventsMessage pump for modeless dialogs.
GetDefIdRetrieves the identifier of the default push button control for a dialog box.
SetDefIdChanges the identifier of the default push button for a dialog box.
DialogRepositionRepositions a top-level dialog box so that it fits within the desktop area.
DialogShowStateChange the visible state of a dialog.
DialogMaximizeMaximizes the dialog.
DialogMinimizeMinimizes the dialog.
DialogHideHides the dialog.
DialogNormalizeMakes the dialog visible at its normal size and position.
DialogDisableDisables the dialog.
DialogEnableEnables the dialog.
DialogRedrawRedraws the dialog.
DialogForceVisibilityRepositions the dialog if it is off-screen.
DialogCenterCenters the dialog.
DialogStabilizeMakes a Dialog stabilized (non-closeable).
DialogNonStableMakes a Dialog non stable (closeable).
IsDialogStabilizedChecks if the dialog is stabilized.
IsDialogNonStableChecks if the dialog is non stable.
DialogPostPosts a message in the message queue.
DialogSendSends a message to the dialog.
DialogGetSizeGets the width and height of the dialog.
DialogGetWidthGets the width of the dialog.
DialogGetHeightGets the height of the dialog.
DialogSetSizeSets the size of the dialog.
DialogGetBoundsRetrieves the bounds of a window without the drop shadows.
DialogGetClientRetrieves the coordinates of the dialog's client area.
DialogGetClientWidthGets the width of the the dialog's client area.
DialogGetClientHeightGets the height of the the dialog's client area.
DialogSetClientAdjusts the bounding rectangle of the dialog based on the desired size of the client area.
DialogGetTextGets the text of the dialog caption.
DialogSetTextSets the text of the dialog caption.
DialogGetLocGets the location of the top left corner of the window.
DialogSetLocSets the location of the top left corner of the window.
DialogGetUserRetrieves a value from the user data area of the dialog.
DialogSetUserSets a value in the user data area of a dialog.
CBGetDlgMsgResultGets the return value of a message processed in the dialog box procedure.
CBSetDlgMsgResultSets the return value of a message processed in the dialog box procedure.

Control methods

NameDescription
ControlAddAdds a control to the dialog.
ControlSetFocusSets the focus in the specified control of a dialog box.
ControlDisableDisables the specified control.
ControlEnableEnables the specified control.
ControlGetLocGets the location of the top left corner of the window.
ControlSetLocSets the location of the top left corner of the window.
ControlGetTextRetrieves the text in a control or control caption.
ControlSetTextSets the text in a control or control caption.
ControlHandleReturns a window handle for the specified control ID.
ControlHideHides the specified control.
ControlNormalizeMakes visible the specified control.
ControlKillDestroys the specified control.
ControlShowStateChanges the visible state of a control.
ControlRedrawRedraws the specified control.
ControlPostPosts a message in the message queue.
ControlSendSends the specified message to the specified control.
ControlGetSizeGets the width and height of the control.
ControlGetWidthGets the width of the control.
ControlGetHeightGets the height of the control.
ControlSetSizeSets the width and height of the specified window.
ControlGetClientRetrieves the coordinates of the control's client area.
ControlGetClientWidthGets the width of the control's client area.
ControlGetClientHeightGets the height of the control's client area.
ControlSetClientAdjusts the bounding rectangle of the dialog based on the desired size of the client area.
ControlCenterHorizMoves the control to the center of the dialog horizontally
ControlCenterVertMoves the control to the center of the dialog vertically.
ControlGetCheckGets the check state of a radio button or check box.
ControlSetCheckSets the check state of a radio button or check box.
ControlSetOptionSets the check state for an Option (radio) control, and unsets the check state for other Option buttons in a group.

Fonts

NameDescription
DialogGetFontGets the handle of the font used by the dialog.
DialogGetFontFaceNameGets the face name of the font used by the dialog.
DialogGetFontPointSizeGets the point size of the font used by the dialog.
FontNewCreates a logical font.
FontEndDestroys a font when it is no longer needed.
ControlGetFontGets the handle of the font used by the control.
ControlSetFontSets the font that a control is to use when drawing text.
ControlGetFontFaceNameGets the face name of the font used by the control.
ControlGetFontPointSizeGets the point size of the font used by the control.

Images

NameDescription
DialogSetIconChanges both the dialog icon in the caption, and the icon shown in the ALT+TAB task list.
DialogSetIconExSets the big and small icons of the dialog.
FindResourceTypeFinds the resource type given it's identifier or name.
ControlSetImageChanges the icon or bitmap displayed in an image label control.
ControlSetImageXChanges the icon or bitmap displayed in an image label control.
ControlSetImgButtonChanges the bitmap displayed in an image button control.
ControlSetImgButtonXChanges the bitmap displayed in an image button control.

Metric conversions

NameDescription
DialogUnitsToPixelsConverts the specified dialog box units to screen units (pixels).
DialogUnitsToPixelsRatiosRetrieves the conversion ratios from dialog units to pixels.
DluToPixRXRetrieves the conversion ratios from dialog units to pixels.
DluToPixRXRetrieves the conversion ratios from dialog units to pixels.
PixelsToDialogUnitsConverts the specified screen units (pixels) to dialog box units.
PixelsToDialogUnitsRatiosRetrieves the conversion ratios from pixels to dialog units.
PixToDluRXRetrieves the conversion ratio from pixels to dialog units.
PixToDluRYRetrieves the conversion ratio from pixels to dialog units.

DPI scaling

NameDescription
rxRatioReturns the horizontal DPI scaling ratio.
ryRatioReturns the vertical DPI scaling ratio.
ScaleXScales an horizontal coordinate according the DPI (dots per pixel) being used by the desktop.
ScaleYScales a vertical coordinate according the DPI (dots per pixel) being used by the desktop.
UnscaleXUnscales an horizontal coordinate according the DPI (dots per pixel) being used by the desktop.
UnscaleYUnscales a vertical coordinate according the DPI (dots per pixel) being used by the desktop.
ScaleRectScales a RECT structure according the DPI (dots per pixel) being used by the desktop.
UnscaleRectUnscales a RECT structure according the DPI (dots per pixel) being used by the desktop.

Layout manager

NameDescription
AdjustControlsAdjust the controls size and/or position.
ControlAnchorAnchor the control.
GetAnchorItemGets the anchor item.

Colors

NameDescription
ControlSetColorSets the colors of the control.
DialogSetColorSets the background color of the dialog.
DialogDisableRepaintOnResizeEnable/disable dialog repainting during resizing.
DialogEnableRepaintEnable/disable dialog repainting during resizing.
GetColorItemGets the color item.
IsDialogRepaintDisabledChecks if repainting is enabled during resizing.
IsDialogRepaintDisabledOnResizeChecks if repainting is enabled during resizing.

Keyboard accelerators

NameDescription
AccelHandleGets the accelerator table handle.
AccelAttachAttaches an accelerator table handle.
AddAcceleratorAdds an accelerator key to the table.
CreateAcceleratorTableCreates the accelerator table.
DestroyAcceleratorTableDestroys the accelerator table.

Scrollable dialogs

NameDescription
DialogSetViewPortMakes a dialog scrollable by shrinking its client area size.
IsDialogScrollableFlag indicating if a dialog is scrollable.
DialogResetScrollBarsResets the dikalog scrolling information.
DialogSetupScrollBarsSets the dialog scroll information.
DialogOnVScrollHandles vertical scrollbar messages.
DialogOnHScrollHandles horizontañ scrollbar messages.
DialogOnSizeHandles WM_SIZE messges.

Helper function

NameDescription
CDialogPtrReturns a pointer to the CDialog class given the handle of the window created with it or the handle of any of it's children.

Constructor

Creates instances of the CDialog class.

CONSTRUCTOR (BYREF fontName AS WSTRING = "Segoe UI", BYVAL ptSize AS LONG = 9, _
   BYVAL fontStyle AS BYTE = 0, BYVAL charset AS BYTE = DEFAULT_CHARSET) 
ParameterDescription
fontNameOptional. The font name. Default value: "Segoe UI"
ptSizeOptional. The font point size. Default value: 9 pt.
fontStyleOptional. The font style. 0 = Normal. 2 = Italic. Default value: 0
charsetOptional. The font character set. Default value: DEFAULT_CHARSET
CharsetDescription
ANSI_CHARSETANSI character set.
ARABIC_CHARSETArabic character set.
BALTIC_CHARSETBaltic character set.
CHINESEBIG5_CHARSETTraditional Chinese (Big 5) character set.
DEFAULT_CHARSETCharacter set value based on the system default Windows ANSI code page. For example, when the system locale is English (United States), it is set as ANSI_CHARSET.
EASTEUROPE_CHARSETEastern European character set.
GB2312_CHARSETSimplified (PRC) Chinese character set.
GREEK_CHARSETGreek character set.
HANGEUL_CHARSETKorean (Hangul) character set.
HEBREW_CHARSETHebrew character set.
JOHAB_CHARSETKorean (Johab) character set.
MAC_CHARSETCharacter set value based on the current system Macintosh code page. This value is used primarily in legacy code and should not generally be needed since modern Macintosh computers use Unicode for encoding.
OEM_CHARSETOEM-specific character set. The OEM character set is system dependent.
RUSSIAN_CHARSETCyrillic character set.
SHIFTJIS_CHARSETShift-JIS (Japanese Industry Standard) character set.
SYMBOL_CHARSETWindows symbol character set.
THAI_CHARSETThai character set.
TURKISH_CHARSETTurkish character set.
VIETNAMESE_CHARSETVietnamese character set.
Usage examples
DIM pDialog AS CDialog
DIM pDialog AS CDialog = CDialog("Segoe UI", 9)
DIM pDialog AS CDialog = CDialog("Times New Roman", 10, 2, DEFAULT_CHARSET)

hDialog

Returns the dialog handle.

PROPERTY hDialog () AS HWND
Usage example
DIM hDlg AS HWND = pDlg.hDialog

IsModal

Returns TRUE if the dialog is modal; FALSE otherwise.

FUNCTION IsModal () AS BOOLEAN
Usage example
DIM bModal AS BOOLEAN = pDlg.IsModal

IsCustom

Returns TRUE if it is a custom dialog; FALSE otherwise.

FUNCTION IsCustom () AS BOOLEAN
Usage example
DIM bCustom AS BOOLEAN = pDlg.IsCustom

UsesPixels

Returns TRUE if the dialog uses pixels; FALSE otherwise.

FUNCTION UsesPixels () AS BOOLEAN
Usage example
DIM bUsesPixels AS BOOLEAN = pDlg.UsesPixels

UsesUnits

Returns TRUE if the dialog uses dialog units; FALSE otherwise.

FUNCTION UsesUnits () AS BOOLEAN
Usage example
DIM bUsesUnits AS BOOLEAN = pDlg.UsesUnits

DialogNew

Creates a dialog in memory. A new empty dialog is created, but not yet displayed. Once the dialog has been created and all of the desired controls have been added with, the dialog can be displayed with the DialogShowModeless or DialogSHowModal functions.

If a modeless dialog is created, the application must create a DialogDoEvents message pump for the duration of the dialog. Failure to provide a message pump can result in disruptions to the display of the dialog, or the inability of the dialog to respond to messages such as button clicks, etc. Modal dialogs do not require a message pump.

To change the displayed state of a dialog (i.e., hidden, minimized, etc) after the dialog has been created, use the DialogShowState function.

If a dialog does not have either WS_CHILD or WS_POPUP styles, Windows may enforce a minimum dialog width of some 60-70 dialog units.

You can give to the dialog a class Name of your choice; otherwise, the predefined class #32770" is used.

The overloaded function DialogNewPixels uses pixels instead of dialog units.

FUNCTION DialogNew (BYVAL hParent AS HWND = HWND_DESKTOP, BYREF wszTitle AS WSTRING, _
   BYVAL x AS LONG = -1, BYVAL y AS LONG = -1, BYVAL cx AS LONG = 0, BYVAL cy AS LONG = 0, _
   BYVAL dwStyle AS LONG = 0, BYVAL dwExStyle AS LONG = 0) AS HWND
FUNCTION DialogNew (BYREF wszClassName AS WSTRING, BYVAL hParent AS HWND = HWND_DESKTOP, _
   BYREF wszTitle AS WSTRING = "", BYVAL x AS LONG = -1, BYVAL y AS LONG = -1, _
   BYVAL cx AS LONG = 0, BYVAL cy AS LONG = 0, BYVAL dwStyle AS LONG = 0, _
   BYVAL dwExStyle AS LONG = 0) AS HWND
FUNCTION DialogNewPixels (BYVAL hParent AS HWND = HWND_DESKTOP, BYREF wszTitle AS WSTRING, _
   BYVAL x AS LONG = -1, BYVAL y AS LONG = -1, BYVAL cx AS LONG = 0, BYVAL cy AS LONG = 0, _
   BYVAL dwStyle AS LONG = 0, BYVAL dwExStyle AS LONG = 0) AS HWND
FUNCTION DialogNewPixels (BYREF wszClassName AS WSTRING, BYVAL hParent AS HWND = HWND_DESKTOP, _
   BYREF wszTitle AS WSTRING = "", BYVAL x AS LONG = -1, BYVAL y AS LONG = -1, _
   BYVAL cx AS LONG = 0, BYVAL cy AS LONG = 0, BYVAL dwStyle AS LONG = 0, _
   BYVAL dwExStyle AS LONG = 0) AS HWND
ParameterDescription
wszClassNameThe class name.
hParentHandle of the parent window or dialog. If there is no parent, use zero (0) or HWND_DESKTOP. If the dialog is MODAL, the parent window/dialog will be disabled while this "child" dialog is running.
wszTitleThe text displayed in the title or caption bar of the dialog.
x, yOptional location of the top-left corner for the dialog. The location is specified in the same terms (pixels or dialog units) as specified in the DialogNew / DialogNewPixels functions. If neither x and y are specified, the dialog is centered on the screen. If CW_USEDEFAULT (&H080000000) is specified, the default Windows position is used (cascading from the upper-left corner).
cx, cyThe width and height of the dialog. The size is specified in the same terms (pixels or dialog units) as specified in the DialogNew / DialogNewPixels functions. If the default dialog style (or any other dialog style that includes the WS_CAPTION style) is used, the width and height parameters specify the client size only, and this does not include any caption and border dimensions.

If the style does not include WS_CAPTION, the width and height specify the overall dialog size, including the caption and border, if any. Note that WS_CAPTION is a combination of the WS_BORDER and WS_DLGFRAME styles. The default dialog style includes WS_BORDER and WS_DLGFRAME styles, so it implicitly includes the WS_CAPTION style. |

dwStyle
dwExStyle
Return value

The Windows window handle assigned by Windows. This handle should be used with subsequent Dialog and Control functions, and may be directly used with Windows API calls.

If the dialog could not be created (i.e., due to low Windows resources), NULL is returned.