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
LVL 7
ChatableAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
New SDI app.
Final step instead of default view change it to CFormView
Thats it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.