1
votes

In VS2013, i created an MFC Application Dialoged Based. I modify the project in order to use PropertyPage and Propertysheet at the beginning of the application, so, instead of lauching a CDialog, it launch my propertypage.

After, I created a Dialog, and the class associates ( from::CdialogEx). I would like to open this dialog behind a button click.

Behind my button click, i do:

CMyDialog myDialog;
myDialog.DoModal();

I don't have any error message, but, i don't show my Dialog at the screen.

Maybe it's because this dialog has no child no ?

Anyone could help me please ?

Thanks a lot,

Best regards,

Nixeus

EDIT :

Here is my Entry point :

#include "stdafx.h"
#include "KenoApp.h"
#include "KenoDlg.h"

#include "GenerationDlg.h"
#include "KenoSheet.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CKenoApp

BEGIN_MESSAGE_MAP(CKenoApp, CWinApp)
    ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()


// construction CKenoApp

CKenoApp::CKenoApp()
{

}


// Seul et unique objet CKenoApp

CKenoApp theApp;


// initialisation de CKenoApp

BOOL CKenoApp::InitInstance()
{
    AfxEnableControlContainer();

    // Standard initialization

#ifdef _AFXDLL
        // Call this when using MFC in a shared DLL
#else
    Enable3dControlsStatic();   // Call this when linking to MFC statically
#endif

    CKenoSheet KenoSheet;
    KenoSheet.SetTitle(L"Keno Helper v1.1");

    CGenerationDlg Generation;
    CKenoDlg KenoDlg;

    KenoSheet.AddPage(&KenoDlg);
    KenoSheet.AddPage(&Generation);

    //m_pMainWnd = &KenoSheet;

    int nResponse = KenoSheet.DoModal();

    // Since the dialog has been closed, return FALSE so that we exit the
    //  application, rather than start the application's message pump.
    return FALSE;
}

And after, on my property page :

CAboutDlg myDialog;
theApp.m_pMainWnd = &myDialog;
myDialog.DoModal();

My problem is now that, the DoModal() close my application.

2
Can you try displaying the Dialog as a modeless one?Abhinav
No, how doing this ? I try to use the ShowWindow() method, bu i have an assert error !Walter Fabio Simoni
Trying, and error ( see at the top ) ;)Walter Fabio Simoni
Have you looked to ensure that the code is finding the dialog resource? Dialog creation typically fails when the resource cannot be found.rrirower

2 Answers

1
votes

Quick fix: In the InitInstance() of your application:

CMyPropSheet pps(_T("My Property Sheet"), NULL, 0);
//m_pMainWnd = &pps;        // *** remark away this line if you have it
int nResponse = pps.DoModal();
// do response ...

CTestDlg dlg;
m_pMainWnd = &dlg;          // this line is a must have
nResponse = dlg.DoModal();
// do response ...

The above code is assuming the PropertySheet and Dialog is to be launched sequentially one after the other, inside the InitInstance() of the application. After more information from you, it seems that it is not the way you want it, so the above code is not applicable for your problem. Please revert your code back to the original before using my suggestion.

0
votes

Can you post the result of myDialog.DoModal(); call.

You can try the following piece of code:

Modeless:

CMyDialog myDialog = new CMyDialog();

if(myDialog != NULL)
{
    BOOL ret = myDialog->Create(10000, this);
    if(!ret)
        AfxMessageBox(_T("Error creating Dialog"));

    myDialog->ShowWindow(SW_SHOW);
}
else
{
    AfxMessageBox(_T("Error Creating Dialog Object"));
}