Article ID: 170918 - View products that this article applies to.
This article was previously published under Q170918
You can use the Windows API ShellExecute() function to start the application associated with a given document extension without knowing the name of the associated application. For example, you could start the Paintbrush program by passing the filename ARCADE.BMP to the ShellExecute() function.
The ShellExecute function opens or prints the specified file. Following is the declaration to use when calling this function from Visual Basic:
The following table provides descriptions for each parameter:
Parameter Description ---------------------------------------------------------------------------- hwnd Identifies the parent window. This window receives any message boxes an application produces (for example, for error reporting). lpszOp Points to a null-terminated string specifying the operation to perform. This string can be "open" or "print." If this parameter is NULL, "open" is the default value. lpszFile Points to a null-terminated string specifying the file to open. lpszParams Points to a null-terminated string specifying parameters passed to the application when the lpszFile parameter specifies an executable file. If lpszFile points to a string specifying a document file, this parameter is NULL. LpszDir Points to a null-terminated string specifying the default directory. FsShowCmd Specifies whether the application window is to be shown when the application is opened.
Step-by-Step ExampleThe following example demonstrates how to start an application or load a document into its associated application. The Windows API ShellExecute() function is different from the Visual Basic Shell() function in that you can pass the ShellExecute() function the name of a document and it will launch the associated application, and then pass the filename to the application.
General Information About the ProcessIf the function succeeds, the return value is the instance handle of the application that was run. If there was an error, the return value is less than or equal to 32.
The file specified by the lpszFile parameter can be a document file or an executable file. If it is a document file, this function opens or prints it depending on the value of the lpszOp parameter. If it is an executable file, this function opens it even if the lpszOp specifies "PRINT."
"Programmer's Reference, Volume 2: Functions" of the Microsoft Windows Software Development Kit (SDK), pages 901-904
Article ID: 170918 - Last Review: August 30, 2004 - Revision: 3.2
Contact us for more help