Dialog Boxes

People talk to other people and exchange their inputs via verbal dialogs. Dialog boxes are the medium to talk to its users and collect their inputs. A dialog box usually contains one or more controls/widgets with which the user enters text, chooses options, or directs the action of the command. Dialog boxes are primarily of two types - modal and modeless.

Modal dialogs

Modal dialog creates an UI thread and pops above parent window. This dialog gets curser focus on top of parent window and completely blocks parent. Parent windows cannot get focus until dialog closes. About box of any application is a good example of modal dialog.

About box Modal Dialog

DialogBox

DialogBox function which is basically a macro creates a modal dialog box from a dialog box template resource. DialogBox does not return control until the specified callback function terminates the modal dialog box by calling the EndDialog function. The DialogBox macro uses the DialogBoxParam function.

DialogBox API

int DialogBox(
  HINSTANCE hInstance,  /* handle to application instance */
  LPCTSTR lpTemplate,   /* identifies dialog box template */
  HWND hWndParent,      /* handle to owner window */
  DLGPROC lpDialogFunc  /* pointer to dialog box procedure */
);

int DialogBoxParam(
  HINSTANCE hInstance,     /* handle to application instance */
  LPCTSTR lpTemplateName,  /* identifies dialog box template */
  HWND hWndParent,         /* handle to owner window */
  DLGPROC lpDialogFunc,    /* pointer to dialog box procedure */
  LPARAM dwInitParam       /* dialog initialization parameter */
);

Modeless dialogs

Modeless dialog is one which opens on top of parent window but still parent can get focus and process events. Modeless dialog does not block parent window and this is needed when users need to enter frequent inputs and same time want to get the reflection in the parent window. Find/Replace dialog is a good example of modeless dialog.

Find Modeless Dialog

CreateDialog

CreateDialog macro creates a modeless dialog box from a dialog box template resource. The CreateDialog macro uses the CreateDialogParam function.

CreateDialog API

HWND CreateDialog(
  HINSTANCE hInstance,  /* handle to application instance */
  LPCTSTR lpTemplate,   /* identifies dialog box template name */
  HWND hWndParent,      /* handle to owner window */
  DLGPROC lpDialogFunc  /* pointer to dialog box procedure */
);
HWND WINAPI CreateDialogParam(
  HINSTANCE hInstance,         /* handle to application instance */
  LPCTSTR lpTemplateName,      /* identifies dialog box template name */
  HWND hWndParent,             /* handle to owner window */
  DLGPROC lpDialogFunc,        /* handle to owner window */
  LPARAM dwInitParam           /* dialog initialization parameter */
);

About our authors: Team EQA

Further readings

Where is WinMain() function in MFC application ?

MFC hides WinMain in its framework and includes source file on WinMain(). This explains how framework calls global CWinApp::Initinstance() from entry WinMain.

What is the utility of CWinApp class?

This is constructed during global C++ objects are constructed and is already available when Windows calls the WinMain function, which is supplied by the ...

Basic steps in Win32 GUI Application with source code.

Define a custom Window class structure, Register the class name, CreateWindow, Show windows and write message get and dispatch loop statements. Define the Window CallBack procedure and write the handlers.

What is a Window CallBack procedure and what is its utility?

DispatchMessage() is a API which indirectly triggers the Window CallBack procedure. Message structure members from this function are passed to the CallBack procedure. CallBack procedure should implement event handlers depending on the need of the application.

What are LPARAM and WPARAM in window proc function?

LPARAM and WPARAM are the two parameters in Window CallBack procedure. They signifies parameters of various events. They are used in handing individual events.

What are the basic steps of a typical MFC based application?

We need to write WinMain and need to follow all these in a Win32 application. However we need not to write much if we are writing an application with MFC ...

#