Dialog app without main dialog 
Author Message
 Dialog app without main dialog

Hi,

I have a dialog based app that should only run when the user opens a file.
I do this with CFileDialog.
If the user presses Ok I do dlg.DoModal(), otherwise I don't.
But the app crashes in release mode after pressing Cancel, while it works
fine in debug mode.
What could be wrong?

--
Olaf van der Spek
Almere, Holland

http://www.*-*-*.com/



Mon, 09 Jun 2003 02:36:06 GMT  
 Dialog app without main dialog
Olaf,

Why not send along your code that launches the dialog?

Cecil

--
Cecil A. Galbraith
http://www.codesoup.com
Programmers Tips and Tricks



Quote:
> Hi,

> I have a dialog based app that should only run when the user opens a file.
> I do this with CFileDialog.
> If the user presses Ok I do dlg.DoModal(), otherwise I don't.
> But the app crashes in release mode after pressing Cancel, while it works
> fine in debug mode.
> What could be wrong?

> --
> Olaf van der Spek
> Almere, Holland

> http://xcc.tiberian.com/



Mon, 09 Jun 2003 03:03:44 GMT  
 Dialog app without main dialog



Quote:
> Olaf,

> Why not send along your code that launches the dialog?

Because I though it wouldn't be necessary.
But here it is:
BOOL CXCCModLauncherApp::InitInstance()
{
 // Standard initialization

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

 xcc_dirs::load_from_registry();

 CXCCModLauncherDlg dlg;
 m_pMainWnd = &dlg;

 const char* xmlf_filter = "XMLF files (*.xmlf)|*.xmlf|";
 CFileDialog file_dlg(true, NULL, 0, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST,
xmlf_filter, NULL);
 if (IDOK == file_dlg.DoModal())
 {
  dlg.set_mod_fname(static_cast<string>(file_dlg.GetPathName()));
  dlg.DoModal();
 }
 return false;

Quote:
}

> Cecil

> --
> Cecil A. Galbraith
> http://www.codesoup.com
> Programmers Tips and Tricks



> > Hi,

> > I have a dialog based app that should only run when the user opens a
file.
> > I do this with CFileDialog.
> > If the user presses Ok I do dlg.DoModal(), otherwise I don't.
> > But the app crashes in release mode after pressing Cancel, while it
works
> > fine in debug mode.
> > What could be wrong?

> > --
> > Olaf van der Spek
> > Almere, Holland

> > http://xcc.tiberian.com/



Mon, 09 Jun 2003 04:58:46 GMT  
 Dialog app without main dialog
Hi!

The reason is that the framework attempt to destroy the m_pMainWnd which is
non null.
Your code may work fine if the line:
m_pMainWnd = &dlg;
is executed only if the main dialog is created (by DoModal()).
Then it should be placed inside if-brackets:
if (IDOK == file_dlg.DoModal())
 {
    m_pMainWnd = &dlg;    <<-------------------------- here
  dlg.set_mod_fname(static_cast<string>(file_dlg.GetPathName()));
  dlg.DoModal();
                        <<----- here, m_pMainWnd = NULL due to main dialog
destruction
 }

Trully yours,

Marc.

--------------------------------------------------------



Mon, 09 Jun 2003 09:10:44 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. dialog based mfc app that starts without showing the main window

2. PBM: Message box not displayed after main dialog box is closed in MFC dialog-based app

3. Main dialog initially hidden, how? (mfc dialog app)

4. Dialog-Based App and Main Dialog Problem

5. How to change on runtime the caption of a C++ dialog app main window

6. How to change on runtime the caption of a C++ dialog app main window

7. Problem Closing UI thread dialog boxes from main app

8. Property Sheet Dialog as main app window

9. Help me in showing a dialog immediately when main dialog shows

10. main dialog window is blocked by second dialog window

11. who to control a main dialog by a child dialog

12. Passing data from a modal dialog to the main dialog

 

 
Powered by phpBB® Forum Software