Dialog Box
Dialog boxes are the pop-ups used to interact with the user. Dialog boxes also help in taking input from the user. There are three types of dialog boxes. These are -
-
Alert Dialog Box - It is typically used to give users a warning message.

-
Prompt Dialog Box - It is used if the user wants to enter a value before proceeding to the next page.

-
Confirm Dialog Box - It allows users to confirm or approve anything. To proceed, the user must click "OK" or "Cancel" when a confirmation window appears. It will return true if the user hits the OK button. If the user presses the Cancel button, confirm() returns false, and null is displayed.

Using ATL Dialog Wizard
To add a dialog box, your project must be an ATL or MFC project. To set up a dialog box using ATL Dialog Wizard, you need to perform the following steps:
- Create an ATL or MFC project.
- Right-click on the project folder.
- Click on add a class option.
- In the template panel, click the ATL dialog option.
- Click open to display the ATL dialog box.
After this, the ATL dialog wizard adds a dialog box from CDialogImpl, CAxDialogImpl, or CSimpleDialog to your project. The dialog box created using CAxDialogImpl can host both Windows controls and ActiveX. While the remaining two can host only Window controls.
Let’s now discuss how we can manually set up dialog boxes.
Manually Setting Dialog Box
The steps for manually setting up the dialog box include -
- Derive a class from either library, i.e., CDialogImpl, CAxDialogImpl, or CSimpleDialog.
- Create an instance of the derived class.
- Declare a message map to handle messages of dialog boxes. A message map is used to provide a handler function for the given message or command.
- Specify the dialog box template.
Example
class DialogBox : public CDialogImpl<DialogBox>
{
public:
enum { IDD = IDD_MYDLG };
BEGIN_MSG_MAP(DialogBox)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnBnClickedCancel)
END_MSG_MAP()
LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/,
BOOL& /*bHandled*/)
{
// Initialization code
return 1;
}
public:
LRESULT OnBnClickedCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
};
Frequently Asked Questions
What is ATL?
ATL stands for Active Template Library. It is a library containing numerous classes that can be used to manipulate and develop Windows.
What are the ways to add a dialog box?
There are two ways to add a dialog box to the ATL project. These are - using ATL Dialog Wizard and manually adding it.
What are dialog boxes?
Dialog boxes are the pop-ups used to interact with the user. Dialog boxes also help in taking input from the user.
Which ATL libraries help in implementing dialog boxes?
Three ATL libraries help in dialog box implementation. These are - CDialogImpl, CAxDialogImpl, and CSimpleDialog.
Conclusion
In this article, we have discussed the implementation of Dialog Boxes. We also discuss the ATL window class. And, at last, we discussed two approaches that can be used for implementing dialog boxes in ATL projects.
Do not stop learning! We recommend you read these articles -.
- Debugging tips for ATL
- ATL Control Containment
- ATL Services
-
ATL COM property pages
Please refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. And also, enroll in our courses and refer to the mock test and problems available. Have a look at the interview experiences and interview bundle for placement preparations.
Keep learning, and Keep Growing!
Do upvote our blogs if you find them engaging and knowledgeable.