Solved

Opening a file passed on command line

Posted on 2000-03-23
5
190 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

763 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