OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Modeless dialog boxes

Unlike modal dialog boxes, a modeless dialog box allows you to continue using other windows in your application while it is open.

You can use a modeless dialog box to let the user continue to perform actions, find information, and so on, while still using the dialog box.

Use TDialog::Create() to execute a modeless dialog box. When using Create to execute a dialog box, you must explicitly make the dialog box visible by either specifying the WS_VISIBLE flag for the resource style or using the ShowWindow function to force the dialog box to display itself.

Example

For example, suppose your resource script file looks something like this:

DIALOG_1 DIALOG 18, 18, 142, 44
CAPTION "Dialog 1"
{
PUSHBUTTON "Button", IDOK, 58, 23, 25, 16
}

Now, suppose you try to create this dialog box modelessly using the following code:

.
.
.
TDialog dialog1(this, "DIALOG_1");
dialog1.Create();
.
.
.

This dialog box would not appear on your screen. To make it appear, you would have to do one of two things:

.
.
.
TDialog dialog1(this, "DIALOG_1");
dialog1.Create();
dialog1.ShowWindow(SW_SHOW);
.
.
.

The TDialog::CmOk() and TDialog::CmCancel() functions close the dialog box and delete the object. These functions handle the IDOK and IDCANCEL messages, usually sent by the OK and Cancel buttons, in the TDialog response table. The CmOk function calls CloseWindow to close down the modeless dialog box. The CmCancel function calls Destroy with the IDCANCEL parameter. Both these functions close the dialog box. If you override either CmOk or CmCancel, you need to either call the base class CmOk or CmCancel function in your overriding function or perform the closing and cleanup operations yourself.

Alternately, you can create your dialog box object in the constructor for the parent of the dialog box. This way, you create the dialog box object just once. Furthermore, any changes made to the dialog box state, such as its location, active focus, and so on, are kept the next time you open the dialog box. Like any other child window, the dialog box object is automatically deleted when its parent is destroyed. This way, if you close down the dialog box's parent, the dialog box object is automatically destroyed; you do not need to explicitly delete the object.

More specifically, ObjectWindows' default behavior when the user closes a modeless dialog box is to close the dialog window, but not to delete its pointer and not to call its class's destructor. If the dialog object has a parent window, the dialog object's pointer is deleted (and its destructor is called) when the parent window closes. If there is no parent window, the pointer is not automatically deleted.

You can override this default behavior by setting the wfDeleteOnClose flag in the dialog object's class constructor (call SetFlag(wfDeleteOnClose)). Setting wfDeleteOnClose causes ObjectWindows to automatically delete the pointer and call the class destructor of a modeless dialog object when the dialog window receives a WM_CLOSE message (when the user closes it). Setting this flag has no effect on modal dialog boxes.

Example

In the following code fragment, a parent window constructor just constructs a dialog box object, and another function actually creates and displays the modal dialog box:

class TParentWindow : public TFrameWindow
{
public:
TParentWindow(TWindow* parent, const char* title);
void CmDOIT();
protected:
TDialog *dialog;
};
.
.
.
void TParentWindow::CmDOIT()
{
dialog = new TDialog(this, IDD_EMPLOYEE_INFO);
dialog->Create();
}

See Also