Invoking a dialog box that associated to existing class?

Posted on 2000-03-27
Medium Priority
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 );

Question by:wzhxxj
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

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

dlg.create( IDD_DLG_MOVE, NULL );

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


Expert Comment

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.

Accepted Solution

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

CDialog dlg(IDD_DLG_MOVE, NULL);

"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.
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.


Author Comment

ID: 2664106
Thanks, mnewton, your suggestion worked.

CDialog dlg(IDD_DLG_MOVE, NULL);

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?

Expert Comment

ID: 2699355

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.


Author Comment

ID: 2728417
Thanks for your help!

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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 tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

764 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