DIALOG BOXES

INTRODUCTION

An application's object is programmatically referred to as a parent when it can host,
hold, or carry other objects. For this reason, such a window is also referred to as a container.
Although the first object that comes in mind is the form, this is not the only window that can
act as parent. This means that, in the application programming adventure, one will get
acquainted with various types of containers and they are meant to play different roles. In
some cases, two or more containers can be used to implement the same functionality. In some
other cases, the choice will be narrowed based on the goal. The most common and the most
widely used container is the form. In an application, a form can be configured to display like
a regular dialog box, to become a Single Document Interface (SDI) or to participate in a
Multiple Document Interface (MDI) application. As mentioned already, there are two
categories of controls: parents and children.

PARENT

The child controls are positioned on a parent. To keep track of its children, a parent
control has the Controls property. To create a control inside of a parent, a child control is
added to the Controls property of the parent using the Controls.Add() method. When a parent
control is created, it "gives life" to other windows that can depend on it. When a parent is
destroyed, it also destroys its children. A parent control "carries", "holds", or hosts the
controls positioned on it. When a parent is created, made active, or made visible, it gives
existence and visibility to its controls. When a parent gets hidden, it also hides its controls. If
a parent moves, it moves with its children. The controls keep their positions and dimensions
inside the parent. The .NET Framework provides various parent controls.

CHILD

A window is referred to as child when its existence, its visibility, and its availability
depend on another window referred to as its parent. Except for the forms, all of the Windows
controls one will use in the applications are child controls and they must be parented by
another control.

1

Although the message box is a dialog box. the toolbar disappears. the toolbar is a child of the application's form. its children disappear. In this example. 2 . it requires that the application carry out special processing to ensure the dialog box is hidden and destroyed at appropriate times. If one close or hide the toolbar. it is not recommended. If the application specifies an owner window when calling MessageBox or MessageBoxEx. Note that currently there is no difference between how MessageBox and MessageBoxEx work. This means the dialog box procedure requires no special processing to detect changes to the state of the owner window. Although it is possible to create a dialog box that has no owner. the system neither hides nor destroys the dialog box when other windows in the application are hidden or destroyed. Because the typical dialog box is used in conjunction with a menu item.A message box is a modal dialog box and the system creates it by using the same internal functions that DialogBox uses. the system takes complete control of the creation and management of the message box. A message box typically contains a text message and one or more buttons. If one close the application. For example. the system does not disable any of the application's other windows and allows the user to continue to carry out work in the other windows. For example. When a modeless dialog box has no owner. the system disables the owner. Although this does not defeat the purpose of the modeless dialog box. along with its own children. specifying the text and the number and types of buttons to display. The system creates its own template based on the text and buttons specified for the message box and supplies its own dialog box procedure. the Standard toolbar of Visual Studio 2005 is the parent of the buttons on it. the owner window is usually the window containing the menu. An application creates the message box by using the MessageBox or MessageBoxEx function. the toolbar is a child of the form but is a parent to its buttons. when a modal dialog box has no owner. This means the application does not provide a dialog box template and dialog box procedure. MESSAGE BOXES A message box is a special dialog box that an application can use to display messages and prompt for simple input. At the same time. defeating the purpose of the modal dialog box. The system automatically hides or destroys the dialog box whenever its owner is hidden or destroyed. A child window can be a parent of another control.

WS_CAPTION. The owner window remains disabled until the dialog box is destroyed. An application must not create a modal dialog box having the WS_CHILD style. The DialogBoxParam and DialogBoxIndirectParam functions also create modal dialog boxes. The dialog box remains active until the dialog box procedure calls the EndDialog function or the system activates a window in another application. WS_SYSMENU. DialogBox requires the name or identifier of a resource containing a dialog box template. 3 . When the owner window is not already disabled. they are identical to the previously mentioned functions but pass a specified parameter to the dialog box procedure when the dialog box is created. such as WM_CANCELMODE and WM_ENABLE. the system makes it the active window. The owner window should carry out any actions requested by these messages. the system automatically disables the window and any child windows belonging to it when it creates the modal dialog box. the dialog box template should specify the WS_POPUP. just as it does when creating a modal dialog box. that is. An application creates a modal dialog box by using either the DialogBox or DialogBoxIndirect function. preventing any subsequent input from reaching the application. and DS_MODALFRAME styles. Although a dialog box procedure could potentially enable the owner window at any time. enabling the owner defeats the purpose of the modal dialog box and is not recommended. and a thick border. A modal dialog box with this style disables itself. a title bar. When creating the modal dialog box. The system can send messages to the owner. Although an application can designate the WS_VISIBLE style. DialogBoxIndirect requires a handle to a memory object containing a dialog box template. An application can also direct the system to disable all top-level windows belonging to the current thread by specifying the MB_TASKMODAL value when creating the dialog box. MODAL DIALOG BOXES A modal dialog box should be a pop-up window having a window menu. the system always displays a modal dialog box regardless of whether the dialog box template specifies the WS_VISIBLE style. Neither the user nor the application can make the owner window active until the modal dialog box is destroyed.

The dialog box can return a value through the DialogBox function (or other creation functions) by specifying a value when calling the EndDialog function. The system returns this value after destroying the dialog box. it posts the message back to the application message queue so that the application's main message loop can eventually retrieve the message. To prevent the modal dialog box from sending the WM_ENTERIDLE messages. The system does not return control from the function that creates the dialog box until the dialog box procedure has called the EndDialog function. To process messages for the modal dialog box. As the system creates the modal dialog box. it sends the WM_CANCELMODE message to the window (if any) currently capturing mouse input. the application can specify the DS_NOIDLEMSG style when creating the dialog box. the system enables the owner window again. 4 . Because the system disables the owner window. When an application uses the message in this way. but only if the modal dialog box caused the owner to be disabled. In most cases. the system starts its own message loop. by using the PeekMessage function) so that the modal dialog box can receive any user input. The application can use this message to carry out a background task while the dialog box remains on the screen. When the system retrieves a message that is not explicitly for the dialog box. If it retrieves a WM_QUIT message. all mouse input is lost if the owner fails to release the mouse upon receiving this message. An application that receives this message should release the mouse capture so that the user can move the mouse in the modal dialog box. An application destroys a modal dialog box by using the EndDialog function. taking temporary control of the message queue for the entire application. the dialog box procedure calls EndDialog when the user clicks Close from the dialog box's window menu or clicks the OK or Cancel button in the dialog box. the application must frequently yield control (for example. Most applications use this return value to determine whether the dialog box completed its task successfully or was canceled by the user. When the dialog box procedure is destroyed. The system sends the WM_ENTERIDLE message to the owner window whenever the application message queue is empty. it dispatches the message to the appropriate window.

they pass a specified parameter to the dialog box procedure when the dialog box is created. but the user or the application can change the active window at any time. it remains above the owner window in the Z order. To permit the user to move to and select controls by using the keyboard. such as clicking the Cancel button. Two other functions. and WS_SYSMENU styles. however. An application must destroy all modeless dialog boxes before terminating. the application must call the IsDialogMessage function.MODELESS DIALOG BOXES A modeless dialog box should be a pop-up window having a window menu. also create modeless dialog boxes. CreateDialogParam and CreateDialogIndirectParam. the dialog box template should specify the WS_POPUP. even if the owner window is active. A modeless dialog box cannot return a value to the application as a modal dialog box does. see Dialog Box Keyboard Interface. the application can display the dialog box by passing the window handle to the ShowWindow function. WS_BORDER. WS_CAPTION. An application creates a modeless dialog box by using the CreateDialog or CreateDialogIndirect function. For example. the dialog box procedure calls DestroyWindow in response to user input. the system makes it the active window. If the user never closes the dialog box in this way. The system does not automatically display the dialog box unless the template specifies the WS_VISIBLE style. If the dialog box does become inactive. and a thin border. but the dialog box procedure can send information to the owner window by using the SendMessage function. A modeless dialog box neither disables the owner window nor sends messages to it. The application and the dialog box procedure can use this handle to manage the dialog box. When creating the dialog box. For more information about this function. that is. CreateDialog requires the name or identifier of a resource containing a dialog box template. CreateDialog and other creation functions return a window handle to the dialog box. if WS_VISIBLE is not specified in the dialog box template. a title bar. the application must call DestroyWindow. In most cases. 5 . Most applications use the main message loop for this. The application is responsible for retrieving and dispatching input messages to the dialog box. CreateDialogIndirect requires a handle to a memory object containing a dialog box template. It can destroy a modeless dialog box by using the DestroyWindow function.

Most applications use message boxes to warn the user of errors and to prompt for directions on how to proceed after an error has occurred.microsoft.htm http://www.com/en-us/library/7hf9k79z%28v=vs. A modal dialog box requires the user to close the dialog box before activating another window in the application. The process for handling dialog boxes varies.aspx http://jqueryui. specifying the message and the number and type of buttons to display.functionx. DISPLAYING A MESSAGE BOX The simplest form of modal dialog box is the message box.com/vb/Lesson08.USING DIALOG BOXES One use dialog boxes to display information and prompt for input from the user. The application loads and initializes the dialog box.com/vb. It is similar to a main window containing controls. the user can activate windows in different applications. A modeless dialog box does not require an immediate response from the user. After the user closes the message box.tutorialspoint.com/dialog/ 6 . and destroys the dialog box when the user finishes the task. depending on whether the dialog box is modal or modeless. The MB_YESNO style directs MessageBox to provide two buttons with which the user can choose how to proceed: REFERENCES http://www. The message box displays the message that describes the error condition and how to resolve it.net_dialog_boxes.90%29.htm http://msdn. MessageBox or MessageBoxEx returns a value identifying the button chosen by the user to close the message box. processes user input.net/vb. However. providing its own dialog box template and procedure. One create a message box by using the MessageBox or MessageBoxEx function. The system creates a modal dialog box.