Kbase P105641: 4GL/ABL: How to run a windows application using the WinExec API Function?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  12/30/2008 |
|
Status: Verified
GOAL:
4GL/ABL: How to run a windows application using the WinExec API Function?
GOAL:
How to open a Microsoft Word document using the WinExec API Function in 4GL?
GOAL:
What are the WinExec API Function error return codes descriptions?
FACT(s) (Environment):
Windows
Progress 8.x
Progress 9.x
OpenEdge 10.x
FIX:
1. The following code demonstrates how to run the windows Microsoft Word application and how to open a Microsoft Word document using the WinExec API Function:
/* The following Visual Style parameters define the initial state of the application's main window. */
&GLOBAL-DEFINE SW-SHOWNORMAL 1 /* Start the application in a normal size window. */
&GLOBAL-DEFINE SW-SHOWMINIMIZED 2 /* Start the application minimized. Show an icon at the bottom of the screen. */
&GLOBAL-DEFINE SW-SHOWMAXIMIZED 3 /* Start the application in a maximized window. */
&GLOBAL-DEFINE SW-SHOWNOACTIVATE 4 /* Start the application but set the focus back to the calling program. */
&GLOBAL-DEFINE SW-SHOWMINNOACTIVE 7 /* Start the application minimized and set the focus back to the calling program. */
/* Variable Defininition */
DEFINE VARIABLE cProgramName AS CHARACTER NO-UNDO. /* The windows program to run. In this example MS WORD. */
DEFINE VARIABLE cFileName AS CHARACTER NO-UNDO. /* The file to be opened by this instance of MS WORD. */
DEFINE VARIABLE iReturnResult AS INTEGER NO-UNDO. /* The return result value of the WinExe API function. */
/* Intialize the program name and optionally the file name argument of the command to be run */
ASSIGN
cProgramName = "C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE"
cFileName = "C:\WRK91E\mydocument.doc".
/* Launch MS WORD in a normal window and open the specified document */
RUN WinExec (INPUT cProgramName + CHR(32) + cFileName, INPUT {&SW-SHOWNORMAL}, OUTPUT iReturnResult).
/* Display error message and code ONLY if WinExec failed to launch the program */
IF iReturnResult < 32 THEN
MESSAGE "Application Failed:" iReturnResult VIEW-AS ALERT-BOX.
/* EXTERNAL PROCEDURE definition of the WinExec API function */
PROCEDURE WinExec EXTERNAL "KERNEL32.DLL":
DEFINE INPUT PARAMETER ProgramName AS CHARACTER.
DEFINE INPUT PARAMETER VisualStyle AS LONG.
DEFINE RETURN PARAMETER StatusCode AS LONG.
END PROCEDURE.
2. If the function succeeds, the return value is greater than 31. If the function fails, the return value is one of the following:
0 The system is out of memory or resources.
2 The specified file was not found.
3 The specified path was not found.
11 The .exe file is invalid.