Solved

modeless & modal

Posted on 1998-09-10
2
382 Views
Last Modified: 2013-11-20
hai,

How to implement modeless dialog box ?
why it is neccessary to create a pointer to the dialog and why should the memmory be allocated for a modeless dialog box.
please explain in detail.
I'll double the points for suitable answers
adv thanks!
0
Comment
Question by:sunraj
2 Comments
 
LVL 1

Expert Comment

by:Bridge
ID: 1322029
ask yourself, when and where is the dialog destroyed ?
If its a MODAL it can be destroyed after the DoModal call. If its a MODELESS it could be anywhere.
0
 
LVL 1

Accepted Solution

by:
plebel earned 50 total points
ID: 1322030
A modeless dialog is not blocking, so it can not be a local static variable.  A modeles dialog need a DYNAMIC implementation so it will be free to run in paralell of the window that created it, and must be able to destroy itself and automaticaly free its memory space.  

When you use the DoModal function, the window or the function which call the DoModal function is blocked until the dialog is closed.  

when you use the Create function, it create an autonom dialog box and return to the calling window.  The calling window can then destroy the dialog in any time or the dialog can destroy itself latter but both (diallog an caller windows) are free to run in the same time.  So a modeless dialog can be use as a floating tool box.

But you must pay attention, if both (caller window and dialog) have the possibility to destroy the dialog, you must implement a mecanism to let the caller know if the dialog is alive.  In the same way, the dialog that destroy itself must delete itself.

here is an example

I use "BOOL OpenDlg(UINT Idd)" to open the dialog as medeless

I use "void CloseDlg()" to close the dialog from outside

I use void "CAbout::OnOK()" to close the dialog from INSIDE

As you can see, i use the pAbout to know if the object is valid and i set it to null when the object is deleted.

static CAbout *pAbout = NULL;  

// i define the pointer as static because it is implemented on // the dialog box file and not on the caller window file.

BOOL OpenDlg(UINT Idd)
{
      if (!pAbout)
      {
            pAbout = new CAbout(Idd,TRUE);
            pAbout->Create(Idd);
            pAbout->ShowWindow(SW_SHOW);
            pAbout->UpdateWindow();
      }
      return TRUE;
}

void CloseDlg()
{
      if (pAbout)
      {
            pAbout->DestroyWindow();
            delete pAbout;

            /////////////////
            // be sure you set the pointer as NULL

            pAbout = NULL;
      }
}


/////////////////////////////////////////////////////////////////////////////
// CAbout dialog


CAbout::CAbout(UINT Idd,CWnd* pParent /*=NULL*/)
      : CDialog(Idd, pParent), CVersionInfo()
{
      //{{AFX_DATA_INIT(CAbout)
            // NOTE: the ClassWizard will add member initialization here
      //}}AFX_DATA_INIT


}


void CAbout::DoDataExchange(CDataExchange* pDX)
{
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CAbout)
            // NOTE: the ClassWizard will add DDX and DDV calls here
      //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAbout, CDialog)
      //{{AFX_MSG_MAP(CAbout)
      ON_WM_TIMER()
      //}}AFX_MSG_MAP
END_MESSAGE_MAP()

//////////////////////////////
// CAbout message handlers

void CAbout::OnOK()
{
      if (pAbout)
      {
            pAbout->DestroyWindow();
            delete pAbout;

            /////////////////
            // be sure you set the pointer as NULL

            pAbout = NULL;
      }
}

Enjoy it!

Pierre
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 157
while loop over for loop 7 93
no14 challenge 14 62
post4 challenge 28 93
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 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

18 Experts available now in Live!

Get 1:1 Help Now