CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2009
    Posts
    21

    Why does my property sheet has disappeared immediately?

    I have a dialog based application named: basicreport
    and created
    one dialog called: CExternalDataDlg ,
    3 property page called: CImportPage, COptionPage, CConfirmPage
    and 1 property sheet named: CImportPropertySheet.

    inside: BOOL CBasicReportApp::InitInstance()

    Code:
     BOOL CBasicReportApp::InitInstance(){
    ......
            CExternalDataDlg dlg;
    	m_pMainWnd = &dlg;
    	INT_PTR nResponse = dlg.DoModal();
    	if (nResponse == IDOK)
    	{
    		// TODO: Place code here to handle when the dialog is
    		//  dismissed with OK
    		
    	}
    	else if (nResponse == IDCANCEL)
    	{
    		// TODO: Place code here to handle when the dialog is
    		//  dismissed with Cancel
    		
    	}
            return FALSE;
    }
    CExternalDataDlg displayed correctly, worked fine!
    I have change above code to:
    Code:
     BOOL CBasicReportApp::InitInstance(){
            ......
            CImportPropertySheet importWizardSheet(_T("Import Spreadsheet Wizard"));
    	CImportPage importpage;
    	COptionPage optionpage;
    	CConfirmPage confirmpage;
    
    	importWizardSheet.AddPage(&importpage);
    	importWizardSheet.AddPage(&optionpage);
    	importWizardSheet.AddPage(&confirmpage);
    	importWizardSheet.SetWizardMode();
    	
    
    	m_pMainWnd = &importWizardSheet;
    
    	INT_PTR nWizardResponse = importWizardSheet.DoModal();
    	if(nWizardResponse == ID_WIZFINISH){
    		AfxMessageBox(_T("Importing..........."));
    	}
    	else if(nWizardResponse == IDCANCEL){
    		AfxMessageBox(_T("Cancel"));
    	}
    	else{
    	}
            return FALSE;
    }
    CImportPropertySheet displayed correctly, worked fine!
    but when i combinated the both above into once. It looked like
    Code:
            CExternalDataDlg dlg;
    	m_pMainWnd = &dlg;
    	INT_PTR nResponse = dlg.DoModal();
    	if (nResponse == IDOK)
    	{
    		// TODO: Place code here to handle when the dialog is
    		//  dismissed with OK
    		CImportPropertySheet importWizardSheet(_T("Import Spreadsheet Wizard"));
    		CImportPage importpage;
    		COptionPage optionpage;
    		CConfirmPage confirmpage;
    
    		importWizardSheet.AddPage(&importpage);
    		importWizardSheet.AddPage(&optionpage);
    		importWizardSheet.AddPage(&confirmpage);
    		importWizardSheet.SetWizardMode();
    		
    		INT_PTR nWizardResponse = importWizardSheet.DoModal();
    		if(nWizardResponse == ID_WIZFINISH){
    			AfxMessageBox(_T("Importing..........."));
    		}
    		else if(nWizardResponse == IDCANCEL){
    			AfxMessageBox(_T("Cancel"));
    		}
    		else{
    		}
    	}
    	else if (nResponse == IDCANCEL)
    	{
    		// TODO: Place code here to handle when the dialog is
    		//  dismissed with Cancel
    		return FALSE;
    	}
    
    	// Since the dialog has been closed, return FALSE so that we exit the
    	//  application, rather than start the application's message pump.
    	return FALSE;
    The ExternalDataDlg displayed, when i press OK button on ExternalDataDlg the CImportPropertySheet blink and the immediately disappear without any action by user.

    i dont know why? Please kindly advise
    Last edited by pcuong1983; April 11th, 2009 at 05:16 AM. Reason: edit format

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: Why does my property sheet has disappeared immediately?

    The answer, why this happens, can be found in MSDN topic CWinThread::m_pMainWnd:
    "The Microsoft Foundation Class Library will automatically terminate your thread when the window referred to by m_pMainWnd is closed. If this thread is the primary thread for an application, the application will also be terminated."
    Main thread exists immediately after CExternalDataDlg dlg is closed.

    The simplest way to fix this is to move CExternalDataDlg call to CImportPropertySheet ::OnInitDialog. If user presses Cancel, call EndDialog to prevent CImportPropertySheet from showing. In OnInitInstance, leave CImportPropertySheet as the only main application window.

  3. #3
    Join Date
    Apr 2009
    Posts
    21

    Re: Why does my property sheet has disappeared immediately?

    Quote Originally Posted by Alex F View Post
    The answer, why this happens, can be found in MSDN topic CWinThread::m_pMainWnd:
    "The Microsoft Foundation Class Library will automatically terminate your thread when the window referred to by m_pMainWnd is closed. If this thread is the primary thread for an application, the application will also be terminated."
    Main thread exists immediately after CExternalDataDlg dlg is closed.

    The simplest way to fix this is to move CExternalDataDlg call to CImportPropertySheet ::OnInitDialog. If user presses Cancel, call EndDialog to prevent CImportPropertySheet from showing. In OnInitInstance, leave CImportPropertySheet as the only main application window.
    It works!
    Thank so much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured