Solved

How to launch an application

Posted on 2000-03-31
6
179 Views
Last Modified: 2013-11-20
I need to execute from my application another program (not Notepad!) and this program must open a txt file.
I tried the following:

void Launch()
{
SHELLEXECUTEINFO aShellExecStruct;
      aShellExecStruct.cbSize = sizeof(SHELLEXECUTEINFO);
      aShellExecStruct.fMask = SEE_MASK_NOCLOSEPROCESS;
      aShellExecStruct.hwnd = ::GetDesktopWindow();
      aShellExecStruct.lpVerb = "open";
      aShellExecStruct.lpFile ="application.exe";
      aShellExecStruct.lpParameters = NULL;
      aShellExecStruct.lpDirectory = "c:\\temp";
      aShellExecStruct.nShow = SW_SHOWNORMAL;
      
      
      BOOL aResult = ::ShellExecuteEx(&aShellExecStruct);      
      if (aResult)
      {
            HANDLE aProcHandle = aShellExecStruct.hProcess;
            if (aProcHandle)
            {
                  ::WaitForSingleObject(aProcHandle, INFINITE);
                  AfxMessageBox("application is done.");
            }
      }
      else
      {
            AfxMessageBox("Could not start the application");
      }
}

This code launchs the application correcly but I don't know how to open a document in this application.

Any idea?

Thanks
0
Comment
Question by:qocarlos
6 Comments
 
LVL 5

Expert Comment

by:vachooho
ID: 2673461
aShellExecStruct.lpParameters = "document_File_name";

most applications has the ability to open document  by specifying it in their command line

try this

0
 
LVL 3

Author Comment

by:qocarlos
ID: 2673808
Thanks,
I've also written the application I must execute. The problem is that in this application there is the line
cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing

in order to keep the application from creating a blank document at startup.

For this reason, when I specify the file in the command line, nothing is opened.
How can I solve this problem?
0
 
LVL 8

Expert Comment

by:gelbert
ID: 2674271
There are two options:

1. Change your application that before you reset command line(cmdInfo.m_nShellCommand) you save command line in some other variable. This way you would have name of a docunent to open and avoid creating blank document

2. Make COM Outproc server out of your application. Then after creation call interface method to specify name of document to open
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:tvanceplus
ID: 2674353
try using the

WinExec(LPCSTR filename,NULL)

function. It is easier to use than the shell commands


Good Luck!
0
 
LVL 5

Accepted Solution

by:
vachooho earned 100 total points
ID: 2674803
if(
cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)  cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;

will not open new empty document but will allow to open file.


0
 
LVL 3

Author Comment

by:qocarlos
ID: 2675797
Thanks!

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 96
Expand to include initial dialog with two choices. 9 80
Making an alias 7 101
Capture logon name 13 88
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.

808 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