Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Opening a file passed on command line

Posted on 2000-03-23
5
Medium Priority
?
197 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 200 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

Independent Software Vendors: 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!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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 …
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

972 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