Article View: borland.public.cppbuilder.nativeapi
Article #12909Re: How to run another program
From: Jonathan Arnold
Date: Thu, 13 Nov 2003 13:50
Date: Thu, 13 Nov 2003 13:50
48 lines
2925 bytes
2925 bytes
Maurice Anderson wrote:
> I would like to run/start a GUI.exe or Console.exe program in the OnClick
> event of a button. Anyone know how to do this?
Basically you have 3 options:
1) The easiest way to run an arbitrary application is to use the Win32 API
call WinExec. You build the command line and then you just run it. It
doesn't give you much control over how it runs, besides the 2nd CmdShow
parameter, but it is easy to use. Just ignore the "provided for compatibility
with earlier versions of Windows" in the help file - it ain't going anywhere.
2) Go up the ladder in control to the suggest CreateProcess API call. This
one has a monstrous number of parameters, but you get lots of control in
return, including some info so you can wait on it and such.
3) If you want to launch an application, like a web browser, that the
user has associated with a particular type of file, like a URL, you use
the ShellExec Win32 API. Here's a simple example to start up the
users web browser on a URL:
char* URL = "http://www.inprise.com";
// Now just use ShellExecute to run it
rcode = ShellExecute( NULL, "open", URL, NULL, "C:\\", SW_SHOW );
All of these functions can be found in you Win32.hlp file. Yet another
option is to find a component to help out. The ZieglerCollection has a
component that helps out running external applications.
http://www.zieglersoft.com
Also, see Harold Howe's faq of the matter:
http://www.bcbdev.com/faqs/faq71.htm
And Kent Reisdorph's article:'
http://www.bridgespublishing.com/articles/issues/9903/Spawning_external_applications.htm
You can also use the standard C APIs of exec, system, and spawn.
--
Jonathan Arnold C/C++/CBuilder Keen Advice:
http://www.keen.com/categories/categorylist_expand.asp?sid=5156620
Comprehensive C++Builder link site:
http://www.buddydog.org/C++Builder/c++builder.html
Technical Details
Message-ID:
<3fb38c1a$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3fb31fce@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,7300c6a35bdece53 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-11-13 06:10:53 PST Date: Thu, 13 Nov 2003 08:50:18 -0500 From: Jonathan Arnold <jdarnold@buddydog.org> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.6a) Gecko/20031030 MultiZilla/1.5.0.3l X-Accept-Language: en-us, en, ja MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: How to run another program References: <3fb31fce@newsgroups.borland.com> In-Reply-To: <3fb31fce@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 66.92.76.225 Message-ID: <3fb38c1a$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1068731418 66.92.76.225 (13 Nov 2003 05:50:18 -0700) Lines: 48 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail