• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Command Line processing - II

How do I go about automatically opening a file that was passed on
the command line?

I'm trying
to write some code in the Application InitInstance.

Maybe there's a better way to accomplish what I'm trying to do?

My main problem is that I can't
seem to make any calls from my
application InitInstance to any
functions from my Document, View, or
MainFrame classes (something about
illegal call to static member
function).  My handler for OnFileOpen
(when it is selected from the menu)
sits in my document class.  Ideally,
I would like to get this routine
called somehow upon startup of the
program.

Is there a good place to initially
handle command line processing?
Maybe in OnInitialUpdate for my
window?  

0
mosaicer
Asked:
mosaicer
  • 3
  • 2
1 Solution
 
ZoppoCommented:
By default command line parameters are handled in the InitInstance function of your CWinApp-derived class with following code:

CMyApp::InitInstance()
{
 ...
 CCommandLineInfo cmdInfo;
 ParseCommandLine(cmdInfo);
 ProcessShellCommand(cmdInfo);
 ...
}

the ParseCommandLine() function fills the cmdInfo object with data passed as command line (or default data, i.e. command FileNew if no filename passed)

the ProcessShellCommand() function then calls document function related on the data set in cmdInfo.

see help for these functions and the CCommandLineInfo class...

hope that helps,

ZOPPO
0
 
mosaicerAuthor Commented:
Yes, this is as far as I was able to
get with the documentation.  It is
unclear to me where to proceed from
there.  (Sorry, I'm just a novice.
Just started with MFC 2 months ago)
0
 
ZoppoCommented:
By default you have to do nothing! If you pass a file via command line there happens following:

ParseCommandLine() sets cmdInfo like this:
cmdInfo.m_ShellCommand = CCommandLineInfo::FileOpen
cmdInfo.m_strFileName = "PassedFile.ext"

then ProcessShellCommand() does following:
....
BOOL bResult = TRUE;
switch (rCmdInfo.m_nShellCommand)
{
....
 case CCommandLineInfo::FileOpen:
 if (!OpenDocumentFile(rCmdInfo.m_strFileName))
  bResult = FALSE;
 break;
....
}

so, CWinApp::OpenDocumentFile() is called which calls CDocManager::OpenDocumentFile() which searches for best matching document template and calls its CDocTemplate::OpenDocumentFile() which creates a new document and then calls the new document's CDocument::OnOpenDocument() which calls the new documents CObject::Serialize().

Both CDocument::OnOpenDocument() and CObject::Serialize() are virtual.

Since the default implementation of CWinApp::OnFileOpen() simply calls CDocManager::OnFileOpen() which then calls CWinApp::OpenDocumentFile() there should be nothing to do for you, except you're opening your document files from OnFileOpen() by extra processing instead of simply calling base class's OnFileOpen() and load your document through Serialize().

Questions ?

ZOPPO
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mosaicerAuthor Commented:
Well, I'm not using serialize, so
I would have to write routines for
that.  I don't have a totally clear
understanding of how exactly that
would work.

I have a specialized file structure
to be loaded in that is generated
by another program.  This structure
doesn't store all of the document
parameters that serialize needs
(I think?... Like I say, I don't
have a good understanding of
serialize).

One other hitch is that I'm actually
loading in three files, 1 text file
which then gives me two other filenames
of files that need to be loaded.
These files are loaded with some
third party libraries (a special
variant of TIFF) and I then
process the resulting data and
store it in my document as a Device
Independent Bitmap.  As the data
structures (aerial imagery) are already
quite large (our machines are
requiring up to 2 GIGs of RAM!),
I don't want to keep extra data
around (ie. the original files
that were loaded) as that would bump
up the requirements even more.  So I suspect that this adds more complications to the Serialize implementations.

I'm sure that it is easily doable if
you know what you're doing :)
but unfortunately, being a novice,
I'd rather do things the easy way.
Since I've already implemented an
OnFileSave that works, it would
be nice to just use that one.

Thanks you very much for your
suggestions though.




0
 
ZoppoCommented:
It doesn't work this way coz OnFileOpen is never called with ProcessShellCopmmand. Simply do your loading in an overridden OnOpenDocument instead of OnFileOpen, then it should work
0
 
hiap_hoCommented:
Are you using Visual C++ 6 ?
if you make a normal application
the first command line would automatically be opened in the Document classes. Busy rite now so cannot give you a more complete answer

Regards,

hh
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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