Solved

Invoking a dialog box that associated to existing class?

Posted on 2000-03-27
6
251 Views
Last Modified: 2013-11-20
I am creating an MDI MFC application.  I have a custom dialog box that I have created using the resource editor.  In classwizard, I associate the dialog box resource to an existing class( not a new class), that is, the view class.  Once I do this, I can access the dialogs resources for the view class.  However, I not sure how to create the dialog box and bring it up - how do you do it?  

I tried the following but got an exception.
CDialog dlg;
dlg.create( IDD_DLG_MOVE, NULL );
dgl.DoModal();


 
0
Comment
Question by:wzhxxj
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:MFCAnswer
ID: 2662023
ur dlg is of the type CDialog dlg which
is not correct.
dlg should be an object of the CDialog derived class.
check the name of ur derived class .
it should be something like this

class derivedclassname :public CDialog


remove
dlg.create( IDD_DLG_MOVE, NULL );

jus do
dgl.DoModal();  that should work.


0
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2662245
You can use class wizard to create the dialog class for you. You can associate the dialog resource you have created with a new dialog class. Then you won't need to call create on the dialog at all. Just instantiate it and then call DoModal.

If on the other hand you actually want your view to be this dialog, you will need to derive your view from CFormView.
0
 
LVL 3

Accepted Solution

by:
mnewton022700 earned 100 total points
ID: 2662280
You should not call create and then DoModal. Instead try this:

CDialog dlg(IDD_DLG_MOVE, NULL);
dlg.DoModal();

"Create" will show the dialog modelessly, which you definitely don't want to do before attempting to show to modally.

I would still recommend creating your dialog class however.
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.

 

Author Comment

by:wzhxxj
ID: 2664106
Thanks, mnewton, your suggestion worked.

CDialog dlg(IDD_DLG_MOVE, NULL);
dlg.DoModal();

However, I did have to change the dialog box style to 'Popup' or 'Overlapped' for it to work correctly.  When 'Child' was selected, the dialog box would not gain focus but would act modally( i had to kill the app).  Would you happen to know the difference between these settings?
0
 
LVL 3

Expert Comment

by:mnewton022700
ID: 2699355
wzhxxj,

Sorry, I didn't reply to your next question earlier. I hadn't checked my mail for a few days so I didn't see your comment.

I found this comment in MSDN about WS_CHILD.

Do not use the WS_CHILD style with a modal dialog box because the DialogBox function always disables the parent or owner of the newly created dialog box. When a parent window is disabled, its child windows are disabled as well.

0
 

Author Comment

by:wzhxxj
ID: 2728417
Thanks for your help!
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

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: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.

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

14 Experts available now in Live!

Get 1:1 Help Now