
Here's a
list of Document related tips, tricks and samples.
Do not display a new, empty document on
Application Start. - Tells how to stop the application from creating a new,
empty document every time it starts up.
Get an SDI
document's view - This is how to get a pointer to the view associated with
an SDI document.
Do not display a new, empty document
on Application Start
Normally, an application will display a new, empty document
on startup. This behavior can be modified so that, in the event that nothing has
been specified, then nothing is what you get.
When the application was first created by the project
wizard, a CComandLineInfo object was inserted into the startup code.
CComandLineInfo parses through the application’s command line and determines
what the application is supposed to do based upon the command line arguments.
The most command things are, create a new file, open an existing file or print a
file. The default behavior, if nothing else is specified, is to act as though
the application had been told to create a new document. In this case, we want to
detect ‘create a new file’ and replace with ‘do not do anything at all. Take a
break.’
Here’s how to implement our changes:
BOOL
CMyWinApp::InitInstance()
{
...
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// If no command was specified then we’ll have been told to
// create a new file. Detect this and replace with a command
// that will tell the app to do nothing.
if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
...
}
Back to top
Get an SDI document’s view
While MDI documents may have one or more views associated
with them, and SDI document has just one. Whether an SDI or MDI, each document
has a list of associated views. This is how to use the list to get an SDI’s
active view.
In the CDocument derived class code:
POSITION pos = GetFirstViewPosition();
CView* pFirstView = GetNextView( pos );
If desired, the view pointer can be cast to the
application’s view class and used directly.
Back to top

|