Solved

How to launch an application

Posted on 2000-03-31
6
184 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
[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
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

630 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