Modeless windows




















Now you'll move on to the modeless dialog and to the common dialogs. Modeless dialogs allow the user to work elsewhere in the application while the dialog is active.

In this Module's first example, you'll build a simple modeless dialog that is controlled from a view. Modeless Dialogs. In the MFC Library version 6. If you're using a modeless dialog with a view, you'll need to know some specialized programming techniques.

Creating Modeless Dialogs. For modal dialogs, you've already learned that you construct a dialog object using a CDialog constructor that takes a resource template ID as a parameter, and then you display the modal dialog window by calling the DoModal member function. The window ceases to exist as soon as DoModal returns. Modeless dialogs are more complicated.

You start by invoking the CDialog default constructor to construct the dialog object, but then to create the dialog window you need to call the CDialog::Create member function instead of DoModal. Create takes the resource ID as a parameter and returns immediately with the dialog window still on the screen.

You must worry about exactly when to construct the dialog object, when to create the dialog window, when to destroy the dialog, and when to process user-entered data. Here's a summary of the differences between creating a modal dialog and a modeless dialog. Modal Dialog.

Modeless Dialog. Constructor used. Constructor with resource ID param. Default constructor no params. Function used to create window. Create with resource ID param. Table 1. User-Defined Messages. Suppose you want the modeless dialog window to be destroyed when the user clicks the dialog's OK button. This presents a problem. How does the view know that the user has clicked the OK button? The dialog could call a view class member function directly, but that would "marry" the dialog to a particular view class.

A better solution is for the dialog to send the view a user-defined message as the result of a call to the OK button message-handling function. When the view gets the message, it can destroy the dialog window but not the object.

This sets the stage for the creation of a new dialog. The former causes an immediate call to the message-handling function, and the latter posts a message in the Windows message queue. Because there's a slight delay with the PostMessage option, it's reasonable to expect that the handler function has returned by the time the view gets the message. Dialog Ownership. Now suppose you've accepted the dialog default pop-up style, which means that the dialog isn't confined to the view's client area.

As far as Windows is concerned, the dialog's "owner" is the application's main frame window, not the view. You need to know the dialog's view to send the view a message. Therefore, your dialog class must track its own view through a data member that the constructor sets.

The CDialog constructor's pParent parameter doesn't have any effect here, so don't bother using it. We could convert the previous Module monster dialog to a modeless dialog, but starting from scratch with a simpler dialog is easier.

As in the previous Module example, pressing the left mouse button while the mouse cursor is inside the view window brings up the dialog, but now we have the option of destroying it in response to another event, pressing the right mouse button when the mouse cursor is inside the view window. We'll allow only one open dialog at a time, so we must be sure that a second left button press doesn't bring up a duplicate dialog. To summarize the upcoming steps, the MYMFC9 view class has a single associated dialog object that is constructed on the heap when the view is constructed.

The dialog window is created and destroyed in response to user actions, but the dialog object is not destroyed until the application terminates. The options and the default class names are shown here. Use the dialog editor to create a dialog resource.

Change the dialog caption to Modeless Dialog. For example, you can use a modal dialog window to retrieve login information from a user before the user can continue working on an application. Modal windows are useful in presenting important information or requiring user interaction. You can show the C1Window control as a modal dialog box using the ShowModal method:. You can customize the color of your modal background using the ModalBackground property:. A modeless dialog window enables users to interact with other windows while the dialog window is present.

Use this type of dialog window when the requested information is not necessary to continue. Modeless dialog windows do not keep the input focus so you can work on two applications at once.

A modeless dialog window is commonly used in menus and help systems where the user can use the dialog window and the application window concurrently.

For example, a toolbar is a modeless dialog window because it can be detached from the application and the user can select items in the toolbar to apply features to the detached or separated application. You can show the C1Window control as a modeless dialog box using the Show method:. Product Support Forum Print this page. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services. Privacy policy. You can use class CDialog to manage two kinds of dialog boxes:. Modeless dialog boxes , which stay on the screen and are available for use at any time but permit other user activities. The resource editing and procedures for creating a dialog template are the same for modal and modeless dialog boxes.



0コメント

  • 1000 / 1000