Solved

Opening a file passed on command line

Posted on 2000-03-23
5
189 Views
Last Modified: 2013-11-20
How do I go about automatically opening a file that was passed on
the command line?

I have a menu item File->Open with ID_FILE_OPEN but don't know
how to simulate a user having clicked on this.  I'm trying
to write some code in the Application InitInstance.

Can I send some sort of a message and have my routine for
ID_FILE_OPEN execute?  (The routine sits in my document class)
Is there a way to directly call my OnFileOpen routine from my
application class?

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

0
Comment
Question by:mosaicer
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
tvanceplus earned 50 total points
ID: 2651147
Just calling the Open menu function wouldn't solve your problem anyway. What you should do is creat some public data in your CWinApp class like

CMyApp:public CWinApp{
....

public:

CCommandLineInfo* comLine;

....

};

Set comLine to the address of the CCommandLineInfo object used in InitInstance.

BOOL CMyApp::InitInstance(){

....

comLine=&cmdLine;

....
}

Then in your CDoc add a public function

CMyDoc:public CDocument{
....

public:

void beginning();
/*and*/
CString fileToBeOpened;

....

};

in this function find the file that you want to open

void CMyDoc::beginning(){
 CCommandLineInfo* myLine;
 myLine=((CMyApp*)AfxGetApp())->comLine;
 if(myLine->m_nShellCommand==FileOpen){
   fileToBeOpened=myLine->m_strFileName;
   
   OpenAFile(fileToBeOpened);
 }
}

the OpenAFile function is your function
to open a specific file with the path passed in as a parameter. Good Luck!

tvanceplus
0
 

Author Comment

by:mosaicer
ID: 2651653
Thanks!
0
 

Author Comment

by:mosaicer
ID: 2653461
I'm having problems implementing this
solution as I'm unable to call
beginning() from my application
class.  Something about an
illegal call to a static member
function.

0
 
LVL 1

Expert Comment

by:tvanceplus
ID: 2653649
Sorry, I forgot to put in that part.
Map a message  to the message OnInitialUpdate() in your CView class;
In that function add this.

void CMyView::OnInitialUpdate(){
 CMyDocument* doc=(CMyDocument*)
     GetDocument();

 doc->beginning();
}

Sorry for not getting this in the answer.

Good Luck!

tvanceplus
0
 

Author Comment

by:mosaicer
ID: 2653739
Thank you very much!  This was
the last thing I had to do to finish
up this project. Yay!


0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 94
post4 challenge 28 104
x-bar in Google Sheets 2 70
Problem to App source 6 70
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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