When I am starting a new project I always choose between SDI or Dialog based depending on the interface layout I will need. Do not get sidetracked by "Document/View", I have created hundreds of projects but never once used the "Document" capabilities. One of the first things I do after generating a SDI project is remove the generated CDocument code. Think of it more as "Frame Window / View" vs "Dialog" based.
If your interface needs to be a complex, with frame windows you have built in control bars and you still have the CFormView class (which I use allot). If your project is a simple utility you would probably choose the Dialog based project.
The AppWizard generates a skeleton project for you but as a minimalist I try and remove all unnecessary code. I will post an example of the way I do things with SDI projects, I hope it helps a little.
Here is an example of an alternative way to create your main window:
CMainFrame* g_pMainFrame = NULL;
CString g_cstrWinClass("YourWindowClassName");
BOOL CApp::InitInstance()
{
INITCOMMONCONTROLSEX iccx = {0};
iccx.dwSize = sizeof(iccx);
iccx.dwICC = ICC_STANDARD_CLASSES;
InitCommonControlsEx(&iccx);
CWinApp::InitInstance();
WNDCLASS wc = {0};
wc.style = CS_DBLCLKS|CS_GLOBALCLASS;
wc.lpfnWndProc = ::DefWindowProc;
wc.hInstance = AfxGetInstanceHandle();
wc.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
wc.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszClassName = g_cstrWinClass;
if(!::GetClassInfo(wc.hInstance, wc.lpszClassName, &wc))
{
if(!::RegisterClass(&wc))
{
TRACE(_T("Window class could not be registered\n"));
return FALSE;
}
}
g_pMainFrame = new CMainFrame;
m_pMainWnd = g_pMainFrame;
DWORD dwStyle = WS_OVERLAPPEDWINDOW;
if(!g_pMainFrame->Create(
g_cstrWinClass, g_cstrWinName,
dwStyle, CRect(0,0,1024,768), NULL,
MAKEINTRESOURCE(IDR_MAINFRAME), NULL))
return FALSE;
g_pMainFrame->CenterWindow();
g_pMainFrame->ShowWindow(SW_SHOW);
g_pMainFrame->UpdateWindow();
return TRUE;
}
Here is an alternative way to create your view(s) inside your frame window init function:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
...
CCreateContext context;
memset(&context, 0, sizeof(CCreateContext));
context.m_pNewViewClass = RUNTIME_CLASS(CMainView);
VERIFY(g_pMainView = STATIC_DOWNCAST(CMainView,
CreateView(&context, AFX_IDW_PANE_FIRST)));
g_pMainView->OnInitialUpdate();
SetActiveView(g_pMainView);
return 0;
}
Here is how to switch out your active view:
void CCSMainFrame::SwitchView(CView* pNewView)
{
ASSERT(pNewView);
CView* pOldView = GetActiveView();
if(pOldView == pNewView)
return;
if(pOldView)
{
pOldView->ShowWindow(SW_HIDE);
::SetWindowLong(pOldView->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST+1);
}
if(pNewView)
{
pNewView->BringWindowToTop();
pNewView->ShowWindow(SW_SHOWNORMAL);
pNewView->UpdateWindow();
::SetWindowLong(pNewView->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST);
SetActiveView(pNewView);
RecalcLayout();
}
}