Solved

Invoking a dialog box that associated to existing class?

Posted on 2000-03-27
6
277 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
[X]
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
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
Industry Leaders: 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!

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

726 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