• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

Invoking a dialog box that associated to existing class?

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
wzhxxj
Asked:
wzhxxj
  • 3
  • 2
1 Solution
 
MFCAnswerCommented:
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
 
mnewton022700Commented:
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
 
mnewton022700Commented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
wzhxxjAuthor Commented:
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
 
mnewton022700Commented:
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
 
wzhxxjAuthor Commented:
Thanks for your help!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now