Cmd Line Param to Document
Ross Levin -- levinro@cyberenet.net
Wednesday, December 04, 1996
Environment: VC++ 4.2b, NT 4.0
I am looking for a way to get a command line parameter to the Document
class. I want to open a file just like the default behavior of the
AppWizard generated application, however, I don't want the fully
qualified path prepended to my file name. My file is really a database.
An alternative I have is to get the command line parameter from in the
Init of the App class, but how do I get the Document class to get that
from the APP. Is there a GetApp in the Document class like the
GetDocument in the View class?
Thanks,
Ross
Norman L Covington -- doubleM@cris.com
Friday, December 06, 1996
[Mini-digest: 8 responses]
>I am looking for a way to get a command line parameter to the Document
>class. I want to open a file just like the default behavior of the
>AppWizard generated application, however, I don't want the fully
>qualified path prepended to my file name. My file is really a database.
I can think of a couple ways to hand your situation, by setting the
CCommandLineInfo variables your self after your ParseCommandLine(...) call
(something like cmdInfo.m_strFileName = _T("MyDatabase"); and
cmdInfo.m_nCommandShell = CCommandLineInfo::FileOpen;) , but before the
ProcessShellCommand(...) call. You can override your Document Template
OnFileOpen(...) member function, which will be called by the
ParseShellCommand(...) call (All of which is located in the
CMyApp::InitInstance() with the exception of the Document Template override).
>An alternative I have is to get the command line parameter from in the
>Init of the App class, but how do I get the Document class to get that
>from the APP. Is there a GetApp in the Document class like the
>GetDocument in the View class?
But to answer this question specifically, you can call AfxGetApp() from
within your CDocument derived class or any other class in your application
for that matter, as long as the header file is include to identify the
CMyApp declaration.
Hope you find this helpful...
Norman
-----From: "Randy Taylor"
see doc for:
CWinApp::ParseCommandLine
CWinApp::CCommandLineInfo
AfxGetApp
----------
> From: Ross Levin
> To: mfc-l@netcom.com
> Subject: Cmd Line Param to Document
> Date: Wednesday, December 04, 1996 6:39 AM
>
> Environment: VC++ 4.2b, NT 4.0
>
> I am looking for a way to get a command line parameter to the Document
> class. I want to open a file just like the default behavior of the
> AppWizard generated application, however, I don't want the fully
> qualified path prepended to my file name. My file is really a database.
>
> An alternative I have is to get the command line parameter from in the
> Init of the App class, but how do I get the Document class to get that
> from the APP. Is there a GetApp in the Document class like the
> GetDocument in the View class?
>
> Thanks,
>
> Ross
-----From: Mike Blaszczak
At 06:39 12/4/96 -0500, Ross Levin wrote:
>Environment: VC++ 4.2b, NT 4.0
>An alternative I have is to get the command line parameter from in the
>Init of the App class, but how do I get the Document class to get that
>from the APP. Is there a GetApp in the Document class like the
>GetDocument in the View class?
You can use AfxGetApp() in your application anywhere you want to.
.B ekiM
.B ekiM
http://www.nwlink.com/~mikeblas/
I'm afraid I've become some sort of speed freak.
These words are my own. I do not speak on behalf of Microsoft.
-----From: "P.J. Tezza"
Ross,
See ::AfxGetApp (MFC global function) and ::GetCommandLine (Win32 global function).
PJ
pj@exemplarsoftware.com
----------
From: Ross Levin
Sent: Wednesday, December 04, 1996 6:39 AM
To: mfc-l@netcom.com
Subject: Cmd Line Param to Document
Environment: VC++ 4.2b, NT 4.0
I am looking for a way to get a command line parameter to the Document
class. I want to open a file just like the default behavior of the
AppWizard generated application, however, I don't want the fully
qualified path prepended to my file name. My file is really a database.
An alternative I have is to get the command line parameter from in the
Init of the App class, but how do I get the Document class to get that
from the APP. Is there a GetApp in the Document class like the
GetDocument in the View class?
Thanks,
Ross
-----From: Jim Lawson Williams
At 06:39 AM 4/12/96 -0500, you wrote:
>Is there a GetApp in the Document class like the GetDocument in the View class?
G'day!
Check out "CWinApp* AfxGetApp( )".
Regards,
Jim LW
>From the BBC's "Barchester Chronicles":
"I know that ultimately we are not supposed to understand.
But I also know that we must try."
-- the Reverend Septimus Harding, C++ programmer
-----From: Amir Shoval
Ross Levin wrote:
>
> Environment: VC++ 4.2b, NT 4.0
>
> I am looking for a way to get a command line parameter to the Document
> class. I want to open a file just like the default behavior of the
> AppWizard generated application, however, I don't want the fully
> qualified path prepended to my file name. My file is really a database.
MFC has a class names CCommandLineInfo. Look in the On-Line help.
>
> An alternative I have is to get the command line parameter from in the
> Init of the App class, but how do I get the Document class to get that
> from the APP. Is there a GetApp in the Document class like the
> GetDocument in the View class?
>
Try AfxGetApp(). It's a global function that returns a pointer to the
CWinApp object.
> Thanks,
>
> Ross
It seems all the information you need can be found in the on-line help.
Amir
--
--------------------------
Amir Shoval N.C.C. Israel
torin@netvision.net.il
--------------------------
-----From: "Paul Martinsen"
> Environment: VC++ 4.2b, NT 4.0
>
> I am looking for a way to get a command line parameter to the Document
> class. I want to open a file just like the default behavior of the
> AppWizard generated application, however, I don't want the fully
> qualified path prepended to my file name. My file is really a database.
>
> An alternative I have is to get the command line parameter from in the
> Init of the App class, but how do I get the Document class to get that
> from the APP. Is there a GetApp in the Document class like the
> GetDocument in the View class?
Try AfxGetWinApp();
Paul.
-----From: ktm@ormec.com
On mfc-l, Ross (levinro@cyberenet.net) wrote:
> Environment: VC++ 4.2b, NT 4.0
>
> I am looking for a way to get a command line parameter to the Document
> class. I want to open a file just like the default behavior of the
> AppWizard generated application, however, I don't want the fully
> qualified path prepended to my file name.
>
> An alternative I have is to get the command line parameter from in the
> Init of the App class, but how do I get the Document class to get that
> from the APP. Is there a GetApp in the Document class like the
> GetDocument in the View class?
1) Looking at CYourApp.InitInstance shows the use of CCommandLineInfo to
determine the contents of the command line. Documentation for the ParseParam
method explains how this works.
2) Access theApp or use AfxGetApp and a cast to get at your application class.
In this case, you won't need the cast, as you'll probably be making a call like
CCommandLineInfo cmdInfo;
AfxGetApp()->ParseCommandLine(cmdInfo);
3) #include and use _splitpath to extract the filename part of a
fully qualified path.
Katy
--
Katy Mulvey ktm@ormec.com
Software Development Engineer
ORMEC Systems http://www.ormec.com
| Вернуться в корень Архива
|