[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


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.
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.


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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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 …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

650 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