Click here to Skip to main content
11,796,631 members (73,712 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ MFC dialog

I have an MFC view, and I have another project which implements and MFC dialog.
I want to host the dialog in my view.
My view is of class CFormView.

I did it that way in my view code:

m_myDialog->Create(myDialog::IDD, this);

Now, I see my dialog, but I can't set focus on it and can't use it.

What do I have to change in order to host my dialog in my view, and be able to use it and set focus to it, just as part of the view?

Posted 3-Oct-12 22:02pm
Edited 3-Oct-12 22:31pm
Richard MacCutchan at 4-Oct-12 4:28am
Some time since I used MFC but I think you need to use the CFormView class.
user_code at 4-Oct-12 4:30am
Hi, Thanks. My view is already a CFormView class.
Richard MacCutchan at 4-Oct-12 4:47am
In that case, the form should automatically load the dialog, you do not need to call Create() outside of the class. See CFormView Class for details.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

To embed controls into a view defined by a dialog template you can use a CDialogBar object. Then all notifications from the controls are send to the view and can be handled there.

To do this with your project, change the type of your m_myDialog object to CDialogBar * and move all control handlers from your CDialog derived class to your view class.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Make sure you've set the Style property to Child.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 505
1 Abhinav S 417
2 OriginalGriff 360
3 CPallini 285
4 KrunalRohit 249
0 OriginalGriff 2,012
1 Maciej Los 1,725
2 KrunalRohit 1,310
3 CPallini 1,055
4 ppolymorphe 858

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100