Launching Windows Programs

SM32 has 2 ways to Launch Programs:
PRINT 'LAUNCH'(C$,D$,P,W),
LAUNCH C$,D$,P,W

C$ is the executable command.
D$ is the start dir for the program.
P is the Priority (1=high,0=normal,-1=low).
W is window size(1=maximize, 0=default , -1 - minimize).

The PRINT version can be executed from LINUX or WINDOWS. Note: The PRINT version never returns a TCB(8) value.

C$ ,the command, takes 2 forms that end up executing 2 differrent Windows Functions (ShellExecute or CreateProcess). ShellExecute uses the Windows File association to start the process. Note: ShellExecute never returns a TCB(8) value. A command like:
C$="-print ABC.HTML" would use the the program that is associted with .HTML files to print ABC.HTML. The -print is called the verb. If no verb is specified the verb -open is used.
CreateProcess uses the command as a program name follow by arguments. A command like:
C$="NOTEPAD.EXE ABC.HTML" will bring up NOTEPAD.EXE to edit ABC.HTML

The command is processed as follows:
1. IF C$ contains .EXE or .COM or .BAT ShellExecute is not attempted.
2. IF ShellExecute fails CreateProcess is attempted.

A CreateProcess that succeeds and was executed by an SM32 statement (not a print) sets TCB(8) to a HANDLE. The HANDLE is used in the following syntaxs:
SYNTAXACTION
H=TCB(8)Gets the handle of the last launched program. The action of getting the handle resets TCB(8) to 0.
HANDLECLOSE HCloses the HANDLE specified by H.
E=GEC(H)Gets the exit code of the process specified by H. 259 indicates the process is still running
SENDMESSAGE H,M,P1,P2Posts a message to the Top Level window assoicated with the initial thread of the LAUNCH.
Typical this has been used to end a process started by SM32(M=16,P1=0,P2=0)

To avoid using up Windows Resources a Maximum of 64 HANDLES can be in use at one time (TCB(8) will return 0 on the 65th). After you are finished using a handle you should use HANDLECLOSE to free up the resource. All HANDLES are closed by BEGIN,END,STOP and BYE. Also if you LAUNCH a program and never access the TCB(8) the HANDLE for that LAUNCH will be closed by any subsequent LAUNCH. One program that is useful to have launched with the CreateProcess method is Internet Explorer. The GSYSDIR system variable has be added so the location of mshtml.dll can be specified.
10 BEGIN 
20 DIM K!
30 LET K!["footer"]="";REM "the dim actual did this"
40 LET K!["header"]="";REM "the dim actual did this"
50 CALL "$__PAGE_SETUP",K![ALL];REM "Set page setup"
60 LET L$="rundll32.exe "+GSYSDIR+"\mshtml.dll,PrintHTML "
70 LET F$=DIR(-1)+"HTML\temp.html"
80 LAUNCH L$+$22$+F$+$22$,"",0,0
90 LET H=TCB(8);REM "Handle to Launced program"
100 WAIT -100
110 IF GEC(H)=259 THEN GOTO 0100;REM "Still Running"
120 HANDLECLOSE H
130 CALL "$__PAGE_SETUP",K![ALL];REM "Restore page setup"
Another usefull program to LAUNCH is SM32 itself so a background task can be executed.