Skip to content

Latest commit

 

History

History
58 lines (41 loc) · 1.7 KB

sample_002.md

File metadata and controls

58 lines (41 loc) · 1.7 KB

Home

Starting an external application in VFP using WinExec

Before you begin:

This code displays an ASCII file in maximized Notepad window. The file C:\newfile.txt is created if it does not exist.

Other code samples you might be interested in:


Code:

#DEFINE SW_HIDE 0
#DEFINE SW_SHOWNORMAL 1
#DEFINE SW_SHOWMINIMIZED 2
#DEFINE SW_SHOWMAXIMIZED 3
#DEFINE SW_SHOWNOACTIVATE 4
#DEFINE SW_SHOW 5
#DEFINE SW_MINIMIZE 6
#DEFINE SW_SHOWMINNOACTIVE 7
#DEFINE SW_SHOWNA 8
#DEFINE SW_RESTORE 9
#DEFINE SW_SHOWDEFAULT 10

DECLARE INTEGER WinExec IN kernel32;
	STRING lpCmdLine, INTEGER nCmdShow

LOCAL cCmdLine, nResult

cCmdLine = ["notepad" "c:\newfile.txt"]
*!*	cCmdLine = "C:\Program Files\Microsoft Office\Office10\WINWORD.EXE"

nResult = WinExec(cCmdLine, SW_SHOWDEFAULT)

IF nResult <= 31
	= MESSAGEBOX("WinExec failed with an error: " +;
		LTRIM(STR(nResult)) + "     ", 48)
ENDIF  

Listed functions:

WinExec

Comment:

Running external applications through the WinExec call you bypass FOXRUN.PIF which makes the whole thing more efficient. According to the Microsoft: all WinExec calls are translated directly into corresponding CreateProcess calls.