Gufeatza

As I said in the subject i try to open a Word document from mfc that is on the disk in this form :

"ex 2.doc"

For this I used Process class. As first argument of the Process's contructor i gave winword.exe's place on the hard and the position of the Word document to be opened.

So it looks like this :

Process* p = new Process(strComand, this);
p->run();

stComand contains : "C:\\Program Files (x86)\\Microsoft Office\\OFFICE11\\WINWORD.EXE E:\\Documente\\Ex 2.doc"

If documents word is simple, as : a.doc or example.doc it works fine. But as in the example above microsoft word doesn't recognize the file. I guess that space figures out to be for the compiler a third separated part. But Program Files also has two separated parts and there's no problem with it.

My interest consist in finding the way c++ parses names from many parts in a single one(ex: ms-dos -> space equal ~), if something like this exists, or contrary a way a can do this or another way to open this kind of named word documents.

Please Help me... Thanks a lot!


Re: Visual C++ Express Edition Open MS Word documents that have their name as 2 parts separated by space

orcmid

Gufeatza wrote:

stComand contains : "C:\\Program Files (x86)\\Microsoft Office\\OFFICE11\\WINWORD.EXE E:\\Documente\\Ex 2.doc"

Use \" to insert double-quotes around the entire stCommand string. This will take care of all of the spaces in the path and not have the system treat C:\Program as the command and the rest as parameters:

Code Snippet
"\"C:\\Program Files (x86)\\Microsoft Office\\OFFICE11\\WINWORD.EXE E:\\Documente\\Ex 2.doc\""


You can do this all of the time, whether or not there are spaces, and it should always work.

- Dennis






Re: Visual C++ Express Edition Open MS Word documents that have their name as 2 parts separated by space

Gufeatza

When I use double brackets as you said Word doesn't even start. :-




Re: Visual C++ Express Edition Open MS Word documents that have their name as 2 parts separated by space

orcmid

Gufeatza wrote:
When I use double brackets as you said Word doesn't even start. :-

Show us the code that creates the value in stCommand or strCommand.

- Dennis

PS: Also, where is the on-line documentation of the Process class you are using, or is this a class of your own






Re: Visual C++ Express Edition Open MS Word documents that have their name as 2 parts separated by space

orcmid

orcmid wrote:

Use \" to insert double-quotes around the entire stCommand string. This will take care of all of the spaces in the path and not have the system treat C:\Program as the command and the rest as parameters:

Code Snippet
"\"C:\\Program Files (x86)\\Microsoft Office\\OFFICE11\\WINWORD.EXE E:\\Documente\\Ex 2.doc\""

Wait, I misread your original snippet. It is a command plus a single parameter.

Do it this way:

Code Snippet

"\"C:\\Program Files (x86)\\Microsoft Office\\OFFICE11\\WINWORD.EXE\" \"E:\\Documente\\Ex 2.doc\""

There are four \" insertions. One pair around the command, another pair around the parameter. This assumes that your Command String is going to be passed to a console shell or or similar process-creation operation.

You might also try simply using the command string "\"E:\\Documente\\Ex 2.doc\"" and let Windows figure out that it needs to launch Word, and let it find it automatically. (This will depend on how the process is created.)

- Dennis






Re: Visual C++ Express Edition Open MS Word documents that have their name as 2 parts separated by space

Gufeatza

Thanks a lot.. the last indication made the project work as I wanted!




Re: Visual C++ Express Edition Open MS Word documents that have their name as 2 parts separated by space

Gufeatza

Sorry for not testing for the beginning, but i noticed right about now that when i try the same thing on Excel documents and PowerPoint, it takes the wright file following your indications... the problem is that it opens those file, but hidden somewhere or I do not know how to explain myself this. It opens, but practically nothing happens, like it minimizes the document somewhere. I say so because when I click again on that document's name, Microsoft Office services notice me that the file is already opened. At PowerPoint, when I click the second time, it opens the file wright.

Have any ideas




Re: Visual C++ Express Edition Open MS Word documents that have their name as 2 parts separated by space

orcmid

Gufeatza wrote:
It opens, but practically nothing happens, like it minimizes the document somewhere. I say so because when I click again on that document's name, Microsoft Office services notice me that the file is already opened. At PowerPoint, when I click the second time, it opens the file wright.

Check to see if there are command-line parameters that can be used to control how Office Applications open from the command line. You will have to search somewhere on Microsoft Office and Command Line operation of it. The information is not available here.

You might also want to use this variant command and see if it works better:

"start \"E:\\Documente\\Ex 2.doc\""

- Dennis