0
votes

I've created the new dialog window (Visual Studio 2012, dialog based MFC application) and call it from program menu like this:

CDialog dlg(IDD_Dialog1);
dlg.DoModal();

In new window (in IDD_Dialog1) i'm trying to make a MessageBox. By clicking of the button MessageBox isn't showed.

How to make it correctly?

1
You have to drive a new class from CDialog, named for example CMyDialog. You can search for tutorials on CDialog, there are many. Or add a new dialog in resource section, double click on the dialog in resource, Visual Studio will automatically create the class for you. In resource editor, insert a button in dialog, double click on the button, VS should create a function to handle what happens when you click the button.Barmak Shemirani
Can you share some codes?Mirjalal
Please show the code that uses MessageBox. Or, try using using AfxMessageBox.rrirower

1 Answers

1
votes

Here is some basic code which you shouldn't really need. It's better to use Visual Studio Wizard to make an MFC application, dialog based or something, then go to resource editor, create a dialog, double click on that dialog in resource editor, it gets done for you. While still in resource editor, drag & drop a button to the dialog, double click on that button which you just dropped in...

//mydialog.h
class CMyDialog : public CDialog
{
public:
   CMyDialog(int id, CWnd* parent = NULL);
   void OnButton1();
   DECLARE_MESSAGE_MAP()
};

//mydialog.cpp
BEGIN_MESSAGE_MAP(CMyDialog, CDialog)
   ON_COMMAND(IDC_BUTTON1, OnButton1)
END_MESSAGE_MAP()

CMyDialog::CMyDialog(int id, CWnd* parent) : CDialog(id, parent){
}

void CMyDialog::OnButton1(){
   MessageBox(L"hello world");
}

//myapp.cpp
BOOL CMyApp::InitInstance()
{
   CWinApp::InitInstance();
   CMyDialog dlg(IDD_DIALOG1);
   dlg.DoModal();
   return 0;
}