home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 4
/
BUGCD1997_05.BIN
/
aplic
/
clip4win
/
clip4win.exe
/
C4W30E.HUF
/
SOURCE
/
WINEXEC.PRG
< prev
next >
Wrap
Text File
|
1995-09-03
|
4KB
|
128 lines
////////////////////////////
//
// Clip-4-Win WinExec (Windows version of RUN) demo
//
// Copyright (C) 1992-1995 Skelton Software, Kendal Cottage, Hillam, Leeds, UK.
// All Rights Reserved.
//
// To build: c4wbuild winexec
//
// Thanks to Thomas Kaulen for the Extensions idea!
//
////////////////////////////
#define WIN_WANT_ALL
#include "windows.ch"
#define NO_C4WCLASS
#include "commands.ch"
#include "dll.ch"
#include "vo.ch"
#include "msg.ch"
#define CR chr(13)
static cUserApp
function main_exec()
local oApp, oWnd
CREATE APPLICATION oApp WINDOW oWND TITLE "Clip-4-Win WinExec demo" ;
ON INIT MenuSetup(oWnd)
return nil
static function DoRun(cProgram, cArgs, lWait)
local hInst, lFound := .T.
local cPrg := "", i
local aProgs := {{"CALENDAR.EXE", "cal"}, {"CARDFILE.EXE", "crd"}, ;
{"NOTEPAD.EXE", "txt"}, {"TERMINAL.EXE", "trm"}, ;
{"WRITE.EXE", "wri"}}
cArgs := iif(cArgs == nil, "", " " + cArgs)
if (hInst := RunProg(cProgram + cArgs, lWait)) > 31 // Found ok
return .T.
endif
// try WIN.INI's Extensions section
if lFound := ((i := ascan(aProgs, {|a| a[1] == cProgram})) != 0)
cPrg := GetProfString("Extensions", aProgs[i, 2], "") + "\" + cProgram
if (i := OpenFile(cPrg, "", OF_EXIST)) == -1
lFound := .F.
endif
endif
if lFound
RunProg(cPrg + cArgs, lWait)
else
MessageBox( , cProgram + " not available!" + CR + CR + ;
"Check your installation!", MB_ICONSTOP)
endif
return lFound
_DLL function OpenFile(cFileName AS string, cStruct AS string, nMode AS UINT) ;
AS INT Pascal:Kernel.OpenFile
_DLL function GetModuleHandle(cName AS string) ;
AS int Pascal:Kernel.GetModuleHandle
function RunProg(cCmdLine, lWait)
local hInst, aMsg[MSG_LENGTH], cName
if (hInst := WinExec(cCmdLine)) > 31 // ok
cName = GetModuleFileName(hInst)
do while Default(@lWait, .F.) .and. GetModuleHandle(cName) != 0
if PeekMessage(aMsg)
GetMessage(aMsg)
TranslateMessage(aMsg)
DispatchMessage(aMsg)
endif
enddo
endif
return hInst
static function MenuSetup(hWnd)
MENU IN hWnd
POPUP "&File"
MENUITEM "&Set your app" ;
ACTION cUserApp := GetOpenFileName( , "*.*", "Set App Name")
MENUITEM SEPARATOR
MENUITEM "E&xit" ACTION PostQuitMessage()
ENDPOPUP
POPUP "&Run"
// Chars used: abcdfknoprstuw
MENUITEM "C&alendar" ACTION DoRun("CALENDAR.EXE")
MENUITEM "Calc&ulator" ACTION DoRun("CALC.EXE")
MENUITEM "&Cardfile" ACTION DoRun("CARDFILE.EXE")
MENUITEM "Clip&board" ACTION DoRun("CLIPBRD.EXE")
MENUITEM "Cloc&k" ACTION DoRun("CLOCK.EXE")
MENUITEM "C&OMMAND.COM" ACTION DoRun("COMMAND.COM")
MENUITEM "&DOS" ACTION DoRun("DOSPRMPT.PIF")
MENUITEM "&File Manager" ACTION DoRun("WINFILE.EXE")
MENUITEM "&Notepad Editor" ACTION DoRun("NOTEPAD.EXE")
MENUITEM "&Print Manager" ACTION DoRun("PRINTMAN.EXE")
MENUITEM "&Reg Info Editor" ACTION DoRun("REGEDIT.EXE")
MENUITEM "&Sys Config Editor" ACTION DoRun("SYSEDIT.EXE")
MENUITEM "&Terminal" ACTION DoRun("TERMINAL.EXE")
MENUITEM "MS-&Write" ACTION DoRun("WRITE.EXE")
ENDPOPUP
MENUITEM "&Your App!" ;
ACTION (Default(@cUserApp, GetOpenFileName( , "*.*", "Set App Name")),;
iif(empty(cUserApp), , DoRun(cUserApp)))
MENUITEM "Your App and &Wait!" ;
ACTION (Default(@cUserApp, GetOpenFileName( , "*.*", "Set App Name")),;
iif(empty(cUserApp), , DoRun(cUserApp, , .T.)))
POPUP "&Help"
MENUITEM "&Program Source" ACTION DoRun("NOTEPAD", "WINEXEC.PRG")
MENUITEM "&About" ACTION MessageBox( , "WinExec Demo", "Clip-4-Win")
ENDPOPUP
ENDMENU
return nil