How To Make A Dialog Box

Table of contents:

How To Make A Dialog Box
How To Make A Dialog Box

Video: How To Make A Dialog Box

Video: How To Make A Dialog Box
Video: How to make a Dialogue System in Unity 2024, November
Anonim

A significant part of the interface of most applications is implemented in the form of dialog boxes. Windows has support for creating windows of this type from templates stored in the resources of the executable module. Therefore, in order to create a dialog box, you usually need to develop its template and write the code for the handlers of the necessary messages.

How to make a dialog box
How to make a dialog box

Necessary

Microsoft Visual C ++ 6.0

Instructions

Step 1

Add a new dialog template to your application resources. Switch to the ResourceView tab of the project window in Microsoft Visual C ++ and press Ctrl + R or select the Insert and Resource … items from the menu. In the list of the window that appears, select the Dialog item and click the New button.

How to make a dialog box
How to make a dialog box

Step 2

Change the id, title, font, size and style set of the added dialog. Immediately after creation, the dialog box template will open in the resource editor. Right-click on it and select Properties from the context menu. On the General tab, enter a title for the dialog and a convenient resource identifier. On the Styles and More Styles tabs, select styles, and on the Extended Styles and More Extended Styles tabs, select the extended window styles. Close the Dialog Properties window.

How to make a dialog box
How to make a dialog box

Step 3

Add controls to the dialog. Click on one of the buttons on the Controls toolbar, which shows the desired element. Click on an empty space in the editable dialog box. Adjust the position and size of the added control with the mouse.

How to make a dialog box
How to make a dialog box

Step 4

Change the IDs and styles of the controls added to the dialog. Click on any of them with the right mouse button. Select Properties from the context menu. Edit the properties you want.

How to make a dialog box
How to make a dialog box

Step 5

Create a class to serve the dialog. Press Ctrl + W. In the Adding New Class window, select the Create a new class option and click OK. In the New Class window, in the Name field, enter the class name and click OK.

How to make a dialog box
How to make a dialog box

Step 6

Add message handlers to the dialog box and the controls within it. Immediately after creating a class, the MFC ClassWizard window will automatically open (in addition, it can always be displayed by pressing Ctrl + W). Switch to the Message Maps tab. Select a dialog or the required control from the Object IDs list. Select the ID of the message you want to process from the Messages list. Click the Add Function button to add a handler.

Switch to the Member Variables tab. In the Control IDs list, select the desired control. Click the Add Variable button to add the associated variable. Click OK on the MFC ClassWizard window to commit your changes.

How to make a dialog box
How to make a dialog box

Step 7

Write the code to initialize and populate the dialog controls with data. Open for editing the implementation file of the class created in the fifth step. Add code to the handlers created in step 6. For example, it makes sense to add the code for filling elements with data into the OnInitDialog handler of the WM_INITDIALOG message.

How to make a dialog box
How to make a dialog box

Step 8

Test the functionality of the created dialog box. Build the application by pressing the F7 key. Run the program by pressing Ctrl + F5.

Recommended: