Solved

Modal vs Modeless Dialogs

Posted on 2001-06-27
7
495 Views
Last Modified: 2013-11-20
Dear Experts,

I am using VC++6/MFC Win 98.

I would like to know if it is possible to make a Dialog Object which can act both modally & modelessly.

i.e Display the Object using both the following methods:

1. MyDialog.DoModal().
2. MyDialog = new CMyDialog(this,...)

If so, how do I detect which it is in the Dialog Constructor?

For modeless dialogs, I normally use the follwing code to create & show the dialog object:

CMyDialog(CWnd* pParent,...)
{
Create(this,CMyDialog::IDD);
ShowWindow(SW_SHOW);
}

Obviously, I don't need to execute the Create & ShowWindow commands if the dialog is Modal.
So, I need some way of detecting if Dialog is Modal or not.

I look forward to you answers.

Bean
0
Comment
Question by:beanjasper
  • 3
  • 3
7 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 6230330
There may be a simple build-in command, but the easiset would be to simply add a variable, m_fIsModal to the derived class.  Then...

  m_dlg= new CMyDlg(...)
  m_dlg.m_fIsModal= TRUE;
  m_dlg.DoModal();
or
  m_dlg= new CMyDlg(...)
  m_dlg.m_fIsModal= FALSE;
  m_dlg.Create(...

-- Dan
0
 

Author Comment

by:beanjasper
ID: 6230653
Hi Dan,

Thats so simple I'm embarassed!

If you don't mind, I'll leave this question open for a couple of days to see if anyone knows of a 'Built In' function.

If not, the points are yours.

Thanks

Bean
0
 
LVL 32

Expert Comment

by:jhance
ID: 6231205
Perhaps there is a flag buried in the data returned by GetWindowLongPtr() that specifies modal vs. non-modal.  

Obviously Windows knows which it is and the information is almost certainly kept in the window itself...

Just a thought.
0
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.

 
LVL 49

Expert Comment

by:DanRollins
ID: 6232533
Actually Windows probably doesn't know -- It just sends messages.  MFC uses a technique in which all dialog boxes are actually modeless -- MFC does *not* call the DialoxBox API (which implements an interal message pump).  MFC wants more control so it implements its own message pump to simulate "Modal Dialog" type action.

You could take a look at the m_nFlags member.  I think that if...
   (m_nFlags & WF_CONTINUEMODAL) != 0
then it is a modal dialog.

-- Dan

0
 

Author Comment

by:beanjasper
ID: 6234346
Dan

m_nFlags - Is this a member of CDialog or is it inherited from CWnd?

I can't find mention of it in the CDialog or CWnd documentation.

Also, where is the list of WF_.. flags such as the one you mentioned above?

I have bumped the points to 75 to recompense you for the extra time required to answer these.

Thanks

Bean
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 75 total points
ID: 6237042
It appears that these flags are not officially documented.  However m_nFlags is a public data member of CWnd.  You can find the flag value constants in the file AFXWIN.H, in the  ... \MFC\Include directory.


You can also glean a little more info by searching MDSN for m_fFlags

-- Dan
0
 

Author Comment

by:beanjasper
ID: 6237103
Yup, 10/10!

Heres an A for your troubles.

Thanks

Bean
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
difference between String.subString() and String.subSequence() 6 171
sum67 challenge 35 93
post4 challenge 28 93
NotAlone Challenge 20 79
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

910 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

19 Experts available now in Live!

Get 1:1 Help Now