Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

I am using VC++6.0 [MFC based].I need to create multiple dialogs so that all the dialogs are active simultaneously.
Is this possible to do using modeless dialog method.
If possible please help me in creating and also explain the procedure in steps as I am a beginner.

Thanks in Advance
vandana
Posted
Updated 27-Mar-11 22:48pm
v3

Nitheesh George answer is almost correct. You just need to create the dialog object dynamically, or make it member of a class, otherwise the dialog object will be detroyed as soon as you exit the function.

If you prefere to create the dialog dynamically, you can do something like:
CYourDialog* dlg = new CYourDialog();
dlg->Create(IDD_YOUR_DIALOG_ID, this);
dlg->ShowWindow(SW_NORMAL);


And to make sure you don't have memory leaks, you also have to delete the created dialog once it is not needed anymore. For example:

Add this inside your dialog .h file:
class CYourDialog
{
    ...
protected:
    virtual void PostNcDestroy();
    afx_msg void OnClose();
};

Add this inside your dialog .cpp file:
BEGIN_MESSAGE_MAP(CYourDialog, CDialog)
    ...
    ON_WM_CLOSE()
END_MESSAGE_MAP()
...
void CYourDialog::PostNcDestroy()
{
    CDialog::PostNcDestroy();
    delete this;
}
void CYourDialog::OnClose()
{
    CDialog::OnClose();
    DestroyWindow();
}
 
Share this answer
 
Hi,

Please find the sample below,

CMyDialog dlg;
dlg.Create(IDD_DIALOG1, this);
dlg.ShowWindow(SW_NORMAL);

this will create a modelless window you can interact with the parent window or any other top level and create another model/modeless window no probs


Hope this helps
 
Share this answer
 
Comments
Olivier Levrey 29-Mar-11 8:48am    
Voted 4. You should make dlg not local, otherwise the dialog object will be destroyed as soon as you exit the function.
vandanaraob 29-Mar-11 11:00am    
Will I have to create a single document based application and then insert dialogs or dialog based application itself will work??
Olivier Levrey 29-Mar-11 11:14am    
They are very different...

A dialog based application will create a modal dialog box as the main window. You can of course create as many other dialogs (or windows) as you want after, but as soon as the main dialog is closed, the application will quit.

A SDI application will be richer: menu, toolbar, and so on...
vandanaraob 29-Mar-11 23:02pm    
So for modeless dialog single document application is required???
Nitheesh George 30-Mar-11 0:51am    
Hi vandanaraob,

You can add a modeless dialog in any kind of application, whether it be a MDI/SDI/Dialog. The only difference is that a model dialog won't let you to interact with other windows in application when is open. You need to dismiss it to interact with other windows in your app. While a modeless dialog lets you to interact with the other windows without dismissing it, like a normal window.
Are you using MFC or just Win32?
 
Share this answer
 
You may indeed do that using modeless dialogs.
Check one (or more) of the following CodeProject's articles:
http://www.codeproject.com/search.aspx?artkw=modeless&sbo=kw&usfc=false[^].

:-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900