INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS
Come Join Us!
Are you a
Computer / IT professional?
Join Tek-Tips now!
- Talk With Other Members
- Be Notified Of Responses
To Your Posts
- Keyword Search
- One-Click Access To Your
- Automated Signatures
On Your Posts
- Best Of All, It's Free!
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.
Partner With Us!
"Best Of Breed" Forums Add Stickiness To Your Site
(Download This Button Today!)
"...These forums are an excellent source and example of the way people can help each other..."
Where in the world do Tek-Tips members come from?
Execute (spawn) a program
How do I use ShellExecute?
Posted: 22 May 02 (Edited 25 Jun 04)
hwnd is the handle of the parent window.
lpOperation is the action that should be performed. The following actions are valid:
open or NULL -- The function opens the file specified by lpFile. The file can be an executable file or a document file. The file can be a folder to open.
print -- The function prints the file specified by lpFile. The file should be a document file. If the file is an executable file, the function opens the file, as if "open" had been specified.
explore -- The function explores the folder specified by lpFile.
lpFile is the file to open or print, an executable file, or folder to explore.
lpParameters specifies any addition command line arguments.
lpDirectory specifies the default directory.
nShowCmd tells how to open an executable file. nShowCmd can be:
SW_HIDE -- Hides the window and activates another window.
SW_MAXIMIZE -- Maximizes the specified window.
SW_MINIMIZE -- Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE -- Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW -- Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT -- Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
SW_SHOWMAXIMIZED -- Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED -- Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE -- Displays the window as a minimized window. The active window remains active.
SW_SHOWNA -- Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE -- Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL -- Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
If lpFile is a document then nSHowCmd should be 0.
If the call to ShellExecute succeeds, the return value is greater than 31. Otherwise, the value can be:
0 -- The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND -- The specified file was not found.
ERROR_PATH_NOT_FOUND -- The specified path was not found.
ERROR_BAD_FORMAT -- The .EXE file is invalid (non-Win32 .EXE or error in .EXE image).
SE_ERR_ACCESSDENIED -- The operating system denied access to the specified file.
SE_ERR_ASSOCINCOMPLETE -- The filename association is incomplete or invalid.
SE_ERR_DDEBUSY -- The DDE transaction could not be completed because other DDE transactions were being processed.
SE_ERR_DDEFAIL -- The DDE transaction failed.
SE_ERR_DDETIMEOUT -- The DDE transaction could not be completed because the request timed out.
SE_ERR_DLLNOTFOUND -- The specified dynamic-link library was not found.
SE_ERR_FNF -- The specified file was not found.
SE_ERR_NOASSOC -- There is no application associated with the given filename extension.
SE_ERR_OOM -- There was not enough memory to complete the operation.
SE_ERR_PNF -- The specified path was not found.
SE_ERR_SHARE -- A sharing violation occurred.
This function allows you to use the default Windows settings to open, print, or explore files or directories. It will also allow you to override those defaults. Not every parameter needs to filled in, many can be NULL.
ShellExecute cannot execute 16-bit programs. It is more complex than WinExec. It cannot you tell when the spawned program has finished.
ShellExecute(handle, "open";, "MyFile.txt", NULL, NULL, SW_SHOWNORMAL); // opens MyFile with default editor for text files
ShellExecute(handle, NULL, "MyEditor.exe";, "MyFile.txt", NULL, SW_SHOWNORMAL); // opens MyFile with MyEditor program
ShellExecute(handle, "print", "MyFile.txt", NULL, NULL, SW_SHOWNORMAL); // Prints MyFile
ShellExecute(handle, "explore", "C:\\", NULL, NULL, SW_SHOWNORMAL); // Explores root of C: drive
Back to Embarcadero: C++Builder FAQ Index
Back to Embarcadero: C++Builder Forum
Join Tek-Tips® Today!
Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.
Here's Why Members Love Tek-Tips Forums:
- Talk To Other Members
- Notification Of Responses To Questions
- Favorite Forums One Click Access
- Keyword Search Of All Posts, And More...
Register now while it's still free!
Already a member? Close this window and log in.
Join Us Close