Wednesday, December 17, 2008

[vb6] Invoke any program from VB code

Use the ShellExecute function to start another program, to print a document file or start explorer in a specified directory. The hwnd parameter is the window handle of your main form, lpOperation specifies the operation you want and can be "open", "print" or "explore" (pass vbNullString to get the default which is "open"). lpFile is the full name of the file. Use lpParameters to specify any parameters to pass to the file, if it's an exe, or vbNullstring if no parameters. nShowCmd specifies how you want the app /doc window to appear, you'd normally pass SW_SHOWNORMAL (=1), but it can be any of the API constants starting with "SW_". The function returns the instance handle of the app, or an error code (those below 33).
    Private Declare Function ShellExecute& Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd As Long)

No comments:

Post a Comment