Solved

Command Line processing - II

Posted on 2000-03-24
6
229 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 30

Expert Comment

by:Zoppo
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Zoppo
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:mosaicer
Comment Utility
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 30

Accepted Solution

by:
Zoppo earned 35 total points
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 6 48
java ^ examples 8 57
Window placement 17 64
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 81
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now