Solved

Modal vs Modeless Dialogs

Posted on 2001-06-27
7
492 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
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

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Importing  SSL Certificate into Firefox using GPO 28 196
isEverywhere  challenge 19 64
Line meaning 9 77
sumHeights2  challenge 7 76
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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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