Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Functions

Status
Not open for further replies.
Sep 17, 2001
673
US
Windows Function Wrapper (starting point for those not using this great option and to spark ideas.)
Copy the code below into a .prg then save as 'WindowsFunctions.prg'. Then execute the following:

FROM COMMAND LINE DO THESE:
SET PROCEDURE TO WindowsFunctions ADDITIVE
loWF = CREATEOBJECT('WindowsFunctions')
loWF.Notepad()
loWF.Cmd()



COPY BELOW TO .PRG CALLED 'WindowsFunctions.prg':

Define Class WindowsFunctions As Custom

FUNCTION Notepad
LPARAMETERS lcPath
This.ShellExec(0,"open","notepad","",lcPath,1)
ENDFUNC

FUNCTION Cmd
LPARAMETERS lcPath
IF EMPTY(lcPath)
lcPath = ALLTRIM(SYS(5))+"\"
ENDIF

This.ShellExec(0,"open","cmd","",lcPath,1)
ENDFUNC


Function ShellExec
Lparameters hndWin, cAction, cFileName, cParams, cDir, nShowWindow

*!* hndWin - Parent window handle (typical 0)
*!* cAction - Action to be performed on cFileName.
*!* cFileName - File which cAction is to be performed on.
*!* cParams - Parameters to pass if file type is executable.
*!* cDir - Executable program's default or start-up directory.
*!* nShowWindow - Initial window state (1 = normal, 2 = minimized, 3 = maximised).

If Empty(hndWin)
hndWin = 0
Endif

If Empty(cAction)
cAction = "open"
Endif

If Empty(cFileName)
cFileName = "notepad"
Endif

If Empty(cParams)
cParams = ""
Endif

If Empty(cDir)
cDir = ""
Endif

If Empty(nShowWindow)
nShowWindow = 1
Endif

Declare Integer ShellExecute In shell32.Dll ;
INTEGER hndWin, ;
STRING cAction, ;
STRING cFileName, ;
STRING cParams, ;
STRING cDir, ;
INTEGER nShowWin

lnStatus = ShellExecute(hndWin,cAction,cFileName,cParams,cDir,nShowWindow)
If lnStatus <=32
Messagebox("ShellExecute failed: "+Message(),0,"Error")
Endif
Return

ENDFUNC

Enddefine


Regards,

Rob
 
robsuttonjr

One often missed but very useful parameter is
Code:
[COLOR=blue]*!*    nShowWindow - Initial window state ([b]0 = hidden[/b], 1 = normal, 2 = minimized, 3 = maximised).[/color]
Useful for .bat files, command line utilities etc.


FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.net
PDFcommandertm.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top