Microsoft KB Archive/193772

= HOWTO: Use the _ShellExecute Foundation Class =

Article ID: 193772

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q193772



SUMMARY
This article demonstrates how to call the _ShellExecute Foundation Class in the _Environ Visual Class Library.



MORE INFORMATION
You can use the _ShellExecute Foundation Class in the _Environ Visual Class Library to either open or print the file that passed to _ShellExecute. If the file is found, or if there was no association with the file, you can test the return value for possible reasons why the ShellExecute failed. A return value over 32 indicates success.

The following code shows how to print a Microsoft Word 97 document named Test.doc in the Word97 directory using the _ShellExecute Foundation Class.

Sample Code
* Start of code * * Program using _ShellExecute class in _Environ library *  * Pass in three parameters: *   tcFileName= file to open/print *   tcWorkdir = path to file *       tcOperation = what to do with the file, Open or Print *  *  Return:   2  - Bad Association (e.g., invalid URL) *           29 - Failure to load application *           30 - Application is busy *           31 - No application association *  *            Values over 32 indicate success *  LPARAMETERS tcFileName,tcWorkDir,tcOperation tcFileName = "Test.doc" tcWorkDir = "C:\Word"        && Use appropriate directory here tcOperation = "Print" runapp = NEWOBJECT("_ShellExecute",HOME+"Ffc\_Environ.vcx") retval=runapp.ShellExecute(tcFileName,tcWorkDir,tcOperation)

IF retval <= 32 =MESSAGEBOX("ShellExecute was unsuccessful.") ENDIF * End of code * You can also use the _ShellExecute Class to run another application. The following example opens Windows Explorer:

Sample Code
* Start of code * * Program using _ShellExecute class in _Environ library tcFileName = "Explorer.exe" tcOperation = "Open" retval=runapp.ShellExecute(tcFileName,tcWorkDir,tcOperation) IF retval <= 32 =MESSAGEBOX("ShellExecute was unsuccessful.") ENDIF * End of code *

