?
Solved

modeless & modal

Posted on 1998-09-10
2
Medium Priority
?
391 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 100 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Watch the video of Kernel Migrator for SharePoint, which demonstrate the process easily of migration from SharePoint to SharePoint, OneDrive for Business & Google Drive servers, Public Folder to SharePoint, File Server to SharePoint. The tool has va…

589 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