Solved

Command Line processing - II

Posted on 2000-03-24
6
234 Views
Last Modified: 2013-11-20
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
Comment
Question by:mosaicer
  • 3
  • 2
6 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 2653678
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
 

Author Comment

by:mosaicer
ID: 2653734
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
 
LVL 31

Expert Comment

by:Zoppo
ID: 2653831
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 

Author Comment

by:mosaicer
ID: 2653931
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
 
LVL 31

Accepted Solution

by:
Zoppo earned 35 total points
ID: 2654015
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
 
LVL 1

Expert Comment

by:hiap_ho
ID: 2654198
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASCII Non-Printable characters/codes and their HTML equivalents 6 132
windows 10 how make picture as desktop background 2 65
noX challenge 17 130
I could not set window to top 4 21
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question