?
Solved

Opening a file passed on command line

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

800 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