Solved

modeless dialogs

Posted on 1998-12-04
1
330 Views
Last Modified: 2013-11-20
hi regards!
i already asked this question, but i didn't get convincing reply. Please do explain modeless dialog, the arguments
passed to it's create member function. Please cite an
example. Is it a must to allocate dynamically the memmory for modeless dialogs ? ..................
0
Comment
Question by:sunraj
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
ID: 1325776
A modeless dialog is one which need not be completed before the user can continue work in the application.

The Create function simply takes the resource id of the dialog in the resource file (usually beginning IDD_) and optionally the parent window (CWnd *)

BOOL bCreate = dlg.Create( IDD_DIALOG1, pWnd ) ;
or
BOOL bCreate = dlg.Create( IDD_DIALOG1 ) ;

bCreate is set to TRUE if the dialog was created okay.

The dialog the continues processing messages, while the rest of the app can to.

When you close the modeless dialog, you mustn't use the EndDialog API to do it.  Basically this function is called by CDialog::EndDialog, CDialog::OnOK and CDialog::OnCancel.  Avoid these functions like the plague for modeless dialogs.

Instead use DestroyWindow() ; to kill the modeless dialog.  You can call this within the dialog, or from another piece of code in your app.

And no it is not necessary to dynamically allocate memory the modeless dialog.  What you do need to is make sure the memory for the dialog class is not free'd before the dialog exits, and dynamically allocating is an easy way around this.

For example

void SomeFunc()
{
   CMyDialog oDlg ;

   oDlg.Create( IDD_DIALOG1 ) ;
}

At the second } oDlg goes out of scope, meaning the variable is freed.  This is bad news as the dialog is still displayed and executing.  Therefore it a good way round this is to dynamically allocate the memory (using new) and free it later (using delete).
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now