Solved

How to launch an application

Posted on 2000-03-31
6
168 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Expert Comment

by:tvanceplus
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks!

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

11 Experts available now in Live!

Get 1:1 Help Now