Board index » cppbuilder » How to open Notepad from a program ??

How to open Notepad from a program ??

Can any one tell me how too open fx Notepad from cbuilder.

Jesper Aggerholm

 

Re:How to open Notepad from a program ??


Quote
Stelectric wrote:

> Can any one tell me how too open fx Notepad from cbuilder.

> Jesper Aggerholm

Used to be WinExec();
(From the Win32 API):
The WinExec function runs the specified application.

This function is provided for compatibility with earlier versions of
Windows. For Win32-based applications, use the CreateProcess function.

UINT WinExec(

    LPCSTR lpCmdLine,   // address of command line
    UINT uCmdShow       // window style for new application
   );  

 now you can use CreateProcess();

(Again, from the Win32 API):
Remarks

Win32-based applications should use the CreateProcess function rather
than this function. The WinExec function exists in Win32 to provide
compatibility with earlier versions of Windows. For more information
about how the WinExec function is implemented, see the Remarks section
of the LoadModule function.

Mike

Re:How to open Notepad from a program ??


Quote
> Can any one tell me how too open fx Notepad from cbuilder.

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) But it sounds like what you want to do is to lauch an application,
like notepad, that the user has associated with a particular type
of file, like a text file.  To do this, you use the ShellExec Win32 API.  
Here's a simple example to start up the users web browser on a URL:

  char* txtfile="readme.txt";

  // Now just use ShellExecute to run it
  rcode = ShellExecute( NULL, "open", txtfile, 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

+===================================================+
| Jonathan Arnold (mailto:jdarn...@buddydog.org)    |
| Engineering Manager       Roger Wagner Publishing |
| http://people.ne.mediaone.net/jdarnold            |
+===================================================+

 Diplomacy is the art of saying "Nice doggie" until
 you can find a rock.   -- Will Rogers

Re:How to open Notepad from a program ??


Quote
> Can any one tell me how too open fx Notepad from cbuilder.

If you have a .TXT file that you want to open with the default editor,
call ShellExecute. If want to open notepad specifically, call either
CreateProcess, or WinExect. I have an FAQ on CreateProcess. By
coincidence, some of the code launches notepad.

http://www.bcbdev.com/faqs/faq71.htm

Harold Howe [TeamB]
http://www.bcbdev.com

Other Threads