Solved

Opening a file passed on command line

Posted on 2000-03-23
5
185 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
Handling string inputs in C/Linux 23 167
sameEnds challenge 3 106
zeroFront challenge 7 71
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now