Something that I really like about Visual Studio 2005 and 2008 is it's "Start Page". Rather than starting with a blank project or an otherwise blank screen, it presents to the user:
- Recent projects to open
- Information useful to the user (RSS feeds, links to help documents, etc.)
I've wanted to try to mimic the start page in my own applications. At first, based on it's visual attractiveness, I thought it was a CHtmlView-based window. However, after further examination, it appears to be a custom-drawn window.
To start your own "Start Page" in your own MDI applications, you need to create a new CView-derived class (CHtmlView, CScrollView, etc.), a CDocument-derived class, and a CMDIChildWnd- or CMdiChildWndEx-derived class to work with your view. In your application's InitInstance() function, create a second doc template, but don't register it by calling AddDocTemplate().
pDocTemplate = new CMultiDocTemplate(IDR_STARTPAGE,
RUNTIME_CLASS(CStartPageDoc),
RUNTIME_CLASS(CStartPageFrame),
RUNTIME_CLASS(CStartPageView));
if (!pDocTemplate)
return FALSE;
m_pStartPageTemplate = pDocTemplate;
Here, we saved the template into our own member variable in the application. If you call AddDocTemplate(), then when you attempt a File New, you'll be prompted with a dialog of what type of document to create. We don't want that, so we just won't register the template with the MFC sub-system.
Create a function in your application that will show the existing start page, or create a new one if one does not already exist.
void CStartPageApp::OnStartPage()
{
// See if we already have an existing doc open
POSITION pos = m_pStartPageTemplate->GetFirstDocPosition();
if (pos == NULL)
{
// We don't, so just create a new one
m_pStartPageTemplate->OpenDocumentFile(NULL);
}
else
{
// Get the existing doc's first view's frame
// and activate that frame.
CDocument *pDoc = m_pStartPageTemplate->GetNextDoc(pos);
ASSERT(pDoc != NULL);
if (pDoc == NULL)
return;
pos = pDoc->GetFirstViewPosition();
ASSERT(pos != NULL);
if (pos == NULL)
return;
CView *pView = pDoc->GetNextView(pos);
ASSERT(pView != NULL);
if (pView == NULL)
return;
CFrameWnd *pFrame = pView->GetParentFrame();
ASSERT(pFrame != NULL);
if (pFrame == NULL)
return;
pFrame->ActivateFrame();
}
}
Once you have this function, you can call it at any point to show your start page. As long as this is the only place that you create your view, then you'll enforce having only one Start Page visible at any time.
How you show your Start Page is up to you. I had it shown on startup at the end of the application's InitInstance() function.
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
{
OnStartPage();
}
else
{
// Dispatch commands specified on the command line.
// Will return FALSE if app was launched with /RegServer,
// /Register, /Unregserver or /Unregister.
if (!ProcessShellCommand(cmdInfo))
return FALSE;
}
I also had a menu item that showed the page.
ON_COMMAND(ID_START_PAGE, &CStartPageApp::OnStartPage)
In your document, you can force it's title to be "Start Page".
BOOL CStartPageDoc::OnNewDocument()
{
SetPathName(_T("Start Page"), FALSE);
if (!CDocument::OnNewDocument())
return FALSE;
return TRUE;
}
What you show on your Start Page is also up to you. In a future post, I'll go into some details on how I attempted to mimic Microsoft's Start Page's look and feel.