Common dialogs

There are several types of common dialog available in windows operating system. Common dialogs are popup dialog windows available as components to take verious input parameters from users.

These are some functionalities common dialogs provide to users-

  • Selecting a file name with path in graphical environment for opening or saving a file.
  • Selecting a system font and size and other attributes with preview.
  • Selecting a color value for graphical or multimedia application
  • Printer selection for prining text or graphical output of the program
  • Pagesetup of the program output.
  • Find and or replace string and parameter input from user

These are built in dialog resources with their additional functionalities. Programmers need not to implement these from scratch but still can reuse these and extend the functionality in their application. These dialogs can be invoked via Win32 API calls directly. However MFC wraps these inside meaningful classes to maintain object oriented approach.

Common dialog pictures

  • GetOpenFileName

    GetOpenFileName
  • GetSaveFileName

    GetSaveFileName
  • ChooseFont

    ChooseFont
  • ChooseColor

    ChooseColor
  • PageSetupDlg

    PageSetupDlg
  • PrintDlg

    PrintDlg
  • FindText

    FindText
  • ReplaceText

    ReplaceText

Common dialog Win32 APIs

Programmers need to include comdlg.h file in their C/C++ files and comdlg32.lib is the import library to include during link time.

  • GetOpenFileName: File Open dialog
  • GetSaveFileName: File Save dialog
  • ChooseFont: Font choose dialog
  • ChooseColor: Color picker dialog
  • PageSetupDlg: Printer page setup dialog
  • PrintDlg: Print dialog
  • FindText: File text find dialog
  • ReplaceText: File text replace dialog

Common dialog MFC classess

CCommonDialog is the base class for classes that encapsulate functionality of the Windows common dialogs. afxdlgs.h is the header file to include in MFC application. Following are the class name of the dialog:

  • CFileDialog: File Open/Save dialog
  • CFontDialog: Font choose dialog
  • CColorDialog: Color picker dialog
  • CPageSetupDialog: Printer page setup dialog
  • CPrintDialog: Print dialog
  • CFindReplaceDialog: File find/replace dialog

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 ...

#