[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

Use dialog as main window

OK, Here's the deal.
I'm very new to MFC programming. I need you to show me a complete example on how to use a dialog resource as the main window of my MFC program. I don't to actually display a dialog box but rather use the resource as a CFrameWnd.

Please keep your code compatible with MSVC++ 6.0
0
Chatable
Asked:
Chatable
  • 3
  • 3
  • 2
  • +2
1 Solution
 
AndyAinscowFreelance programmer / ConsultantCommented:
New SDI app.
Final step instead of default view change it to CFormView
Thats it.
0
 
ChatableAuthor Commented:
I've already created a CFormView for the dialog.
I don't know how to use it though.

Please provide the actual code for InitInstance.
0
 
jkrCommented:
Why not using a dialog-based application in the first place? Whenthe MFC AppWizard asks "What type of application do you want to create?", just select "Dialog based", that's it.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
AndyAinscowFreelance programmer / ConsultantCommented:
>>Please provide the actual code for InitInstance.

No need - let the wizard create it for you.
0
 
ChatableAuthor Commented:
I already have code and complicated dialogs in my current project.
Please devise how to do this without creating a new project.
0
 
jkrCommented:
You can easily create a new project and transfer the dialog to it by opening the .rc files in a text editor and paste the old dialog resource in the new project, no big deal.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
Make a new project as I suggested.
Copy the InitInstance from it to your current project.
0
 
alb66Commented:
This is the InitInstance code in order to use a dialog as main window:

BOOL CTestApp::InitInstance()
{

      InitCommonControls();

      CWinApp::InitInstance();

      AfxEnableControlContainer();

      SetRegistryKey(_T("MyRegKey"));


      // create the dialog...
      CTestDlg dlg;

      m_pMainWnd = &dlg;

      // ... and execute it
      INT_PTR nResponse = dlg.DoModal();
      if (nResponse == IDOK)
      {
      }
      else if (nResponse == IDCANCEL)
      {
      }

      // close the application
      return FALSE;
}
0
 
nksaxenaCommented:
BOOL CTestApp::InitInstance()
{

      InitCommonControls();

      CWinApp::InitInstance();

      AfxEnableControlContainer();

      SetRegistryKey(_T("MyRegKey"));


      // create the dialog...
      CTestDlg dlg;// Object will be destroyed as soon as its out of scope, use a pointer
     CTestDlg *pDlg = new CTestDlg();


//      m_pMainWnd = &dlg;
       m_pMainWnd = pDlg;

      // ... and execute it
      INT_PTR nResponse = dlg.DoModal();
      if (nResponse == IDOK)
      {
      }
      else if (nResponse == IDCANCEL)
      {
      }

      // close the application
      return FALSE;
}
0
 
alb66Commented:
For nksaxena:

Dialog object goes out of scope when the function returns; but when InitInstance() returns with false, the whole application terminates.
So it is correct and safe to construct object on the stack.
0
 
nksaxenaCommented:
oh yes. its scope really does not matter here since DoModal() is called. Thanks for correction.
0
 
ChatableAuthor Commented:
nksaxena:
I've already tried that one. It doesn't do exactly what I want because it doesn't open the dialog resource as the main window but rather opens the dialog as a dialog with no main window at all.

Anyway, I've recreated the project as AndyAinscow suggested and now it works.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now