MFC VS2010 Can't Add CDialogEx derived class by wizard - c++

In my MFC project I try to create dialog. So in Resource View insert Dialog.
Then double click inside dialog, to get dialog class. MFC Add Class Wizard runs, when I input Class name, and select Base class: CDialogEx. Click Finish button, wizard closes and nothing else happens. None files (cpp, h) is created.
Can You tell me what can be wrong?
As workaround I create manualy files .cpp and .h where derive class from CDialogEx, it is displayed correctly , and I can work with it (messages are handled correctly)
But I have other problems, with Add variable to controls for example.

Related

Create CMFCPropertyPage class linked to Dialog using Class Wizard in VS2017?

I added a new resource dialog IDD_PROPPAGE_LARGE, Assigned it a new ID, title, etc.. Now I launch the class wizard via right click on dialog in resource editor - add class. It has Add MFC Class, I choose base class CMFCPropertyPage and Enter my class name, take defaults for .h and .cpp file, leave dialog id set which has the correct ID.
It creates the .cpp/.h file. I go in there and there is no link to the ID (it creates a simple class derived from CMFCPropertyPage, but the constructor doesn't even call it). More to the issue, I went in to the class wizard to assign the various fields for DDX/DDV and nothing is listed.
What am I doing wrong?
TIA!!

MFC: Emdedded child dialog is not showing up within parent dialog

I came across a tutorial showing how to embed a child dialog within a parent dialog using MFC. I am using Visual Studio 2015. My setup is as follows. Using the Visual Studio MFC Application Wizard to create a new MFC Visual C++ Project called MFCApplication3, I select a Dialog based application where MFC is used in a Shared DLL. Using boilerplate code, I have a simple Thick Frame Dialog, no maximize or minimize box.
In my resource view, I go to my Dialog editor to edit the main dialog. I add a picture control with a blank area in the center and name it IDC_STATIC. This will simply be used as a placeholder for my child dialog that I wish to embed. It looks like:
Still in the resource view, I create a new Dialog. I call it IDD_CHILD. I add some components. It looks like this:
Now back in the Solution Explorer, I add a class using the Add Class wizard, selecting to add an MFC Class. The class name is CChildDialog, with a base class of CDialog, and I use the already generated IDD_CHILD as the Dialog ID. It generates the .cpp and associated .h file. In the constructor of CChildDialog, I add a call to the Create function so the constructor becomes:
CChildDialog::CChildDialog(CWnd* pParent /*=NULL*/)
: CDialog(IDD_CHILD, pParent)
{
Create(IDD_CHILD, pParent);
}
Now I modify the dialog code generated automatically when I created the project. In CMFCApplication3Dlg.h, I add a private member of type CChildDialog* called m_childDlg, and #include the associated header file. In CMFCApplication3Dlg.cpp, I add this to the OnInitDialog function prior to the return statement:
CRect rc;
GetDlgItem(IDC_STATIC)->GetWindowRect(rc);
ScreenToClient(&rc);
m_childDlg = new CChildDialog(this);
m_childDlg->MoveWindow(rc);
Now I build the solution, run it, but it looks like it does in the first picture. A blank placeholder spot for a child dialog, but no child dialog. What could I be doing wrong?
It turns out (while composing this question) that the answer to my problem was two properties I need to set while in the resource view. When I have the child dialog open (IDD_CHILD), within the properties pane, I need to set the following properties:
Style: Child
Visible: TRUE
(I am not sure why Visible defaults to FALSE in this case). Making those two changes, voila! I get my embedded dialog:

MFC menu item doesn't open dialog box

I am having a proglem with the MFC application and the DialogBox. I am quiet sure I've done everything well with this tutorial: https://msdn.microsoft.com/en-us/library/6wb9s9ah.aspx
but still it doesn't work...
1. I've created new project with simple menu commands.
2. I've created new menu item (+ID) and new resource DialogBox (+ID).
3. Then I've added a new class named CParameters with the Class Wizard. For the BaseClass I've typed in CDialog.
4. I've created new handler on the menu item and added the code
CParameters dlg;
dlg.DoModal();
I think this is it, and this should work... But it doesnt... What is missing??
Here is my project, you can access it freely:
https://www.dropbox.com/sh/e6ajoxqk76hkuvn/AACRMY8bgcuyXguFwP240QB9a?dl=0
Additionally I want to insert TextEditors and to change parameters in my program from the dialog box.
A scan of your source code reveals that you are trying to handle the menu item event within the class that is going to display the dialog.
void CParameters::OnParam()
{
// TODO: Add your command handler code here
CParameters dlg;
dlg.DoModal();
}
I don't see anywhere else that you actually instantiate the dialog class (I may have missed it). What you are trying is incorrect. You cannot handle the menu item event within the same class that displays the dialog because that class (CParameters) has not been instantiated, so, it cannot respond to the menu event. Typically, the menu event would be handled in the mainframe class.
If you are doing this by adding a new menu item from a simple SDI application, then trying adding that part of code in
CMainFrame::OnEdit
OnEdit method used here is obtained from the Event Handler for the new menu item and Message type being COMMAND.

How to change ActiveX control's property programmatically with MFC?

I added a activex control to my MFC project, I don't use the dialog editor to add the control, I just used MFC to generate a wrapper class for the control, and call the "create" member in the wrapper class to create the control programmatically, the code is more or less like:
class CMyView
{
CCalendar m_ctl;
//other members.....
}
int CMyView::OnCreate
{
m_ctl.create("",WS_CHILD|WS_VISIBLE,this,CRect(50,50,100,100));
//.....
}
But I found that the wrapper class provide no way for me to change the control's property, so if I want to change the control's property programmatically, what should I do? Can I achieve this through a wrapper class? Or can it be done programmatically at all? Or is it only can be done via a dialog editor? Thank you.
Yes, wrapper only includes functions, if you create it via class wizard.
To change properties, i.e. variables, you could instantiate ActiveX in a form or a dialog and you would have the ability to modify values of properties in properties window.
If you want to do it on-the-run, you can right click to activeX object and then click on add variable. You will see that it will also create wrapper class for the object. This class will automatically include getters and setters for the activex, visible in the newly generated header file.
If you have already created a wrapper class for your activex, it may not work, try this in a fresh project. You can then copy generated .cpp and .h files to your own project afterwards.

How Do I Launch a Dialog in MFC?

I'm fairly new to VC++ and MFC, so bear with me. I have created a new dialog, and I want to figure out how to display it when the user clicks a button.
I have not create a class or header file for the dialog -- I tried using the class wizard, but it pretty much sucked and didn't work. That, or I was doing something wrong. Either one is equally as likely if you ask me.
So what steps do I need to take when creating the source/header files and getting the dialog to launch/display? It is a modal dialog.
CLARIFICATION: I understand that I need to create an instance of the dialog class, then just call DoModal() on it, but I'm not sure how to create the class file (with and/or without the wizard).
Right click the project and select
Add | Resource...
Select Dialog under Resource
type and click New.
Select Project | Add Class...
Enter CMyDialog for the Class
name, CDialog for the Base class
and Click Finish.
Read more: How to Make MFC Dialog Boxes
Seems to me you can make the button click just create a new instance of the dialog object and activate it. You'll probably have to keep a reference to the dialog so it doesn't get killed when the button action fxn returns it doesn't get garbage collected..