Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Basic question about ShellExecute
Message
De
08/07/2009 06:33:28
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Database:
Visual FoxPro
Divers
Thread ID:
01410832
Message ID:
01410835
Vues:
138
This message has been marked as the solution to the initial question of the thread.
>Hi all
>I let the user select a file which path is saved in a textbox. How do i run that file? ( it may be either doc or xls or htm). I remember i should use shellexecute, but i think i have to set something in the parameters.
>
>Jaime

Short version:
#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

declare long ShellExecute in "shell32.dll" ;
	long hwnd, string lpszOp, ;
	string lpszFile, string lpszParams, ;
    string lpszDir, long nShowCmd

lcFileName = "c:\My Folder\MyFile.htm"
ShellExecute(0,'Open',m.lcFileName,0,0,SW_SHOWNORMAL)
Long version:
ShellExec('c:\temp\mydoc.doc')
ShellExec('c:\temp\myfile.jpg')
ShellExec('d:\fpd26\foxprox.exe','mytest.prg','d:\fpd26',0)
ShellExec('d:\fpd26\foxprox.exe',,'d:\fpd26')
ShellExec('c:\myFolder\myHTM.htm')

Function ShellExec
Lparameters tcExecutable,tcParams,tcWorkingDir,tnShowType,tcOperation
#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

declare long ShellExecute in "shell32.dll" ;
	long hwnd, string lpszOp, ;
	string lpszFile, string lpszParams, ;
    string lpszDir, long nShowCmd

tcOperation  = Iif(Empty(m.tcOperation), 'Open', m.tcOperation)
tcExecutable = Iif(Empty(m.tcExecutable), '', m.tcExecutable)
tcParams     = Iif(Empty(m.tcParams), '', m.tcParams)
tcWorkingDir = Iif(Empty(m.tcWorkingDir), '', m.tcWorkingDir)
tnShowType   = Iif(type('m.tnShowType') # 'N', SW_SHOWNORMAL, m.tnShowType)

Local lnResult
lnResult = ShellExecute(0,m.tcOperation,m.tcExecutable,m.tcParams,m.tcWorkingDir,m.tnShowType)
If !( m.lnResult > 32 ) && Error
	MessageBox(GetShExecErrorMsg(m.lnResult))
	Return .F.
endif


Function GetShExecErrorMsg
Lparameters tnErrNum
Local array aErrors[1]
Local lcMessage, lcErrors,lnErrors,ix

Text to m.lcErrors noshow
0,The operating system is out of memory or resources. \n
2,The specified file was not found. \n
3,The specified path was not found. \n
11,The .exe file is invalid (non-Win32® .exe or error in .exe image). \n
5,The operating system denied access to the specified file.  \n
27,The file name association is incomplete or invalid. \n
30,The DDE transaction could not be completed because
other DDE transactions were being processed. \n
29,The DDE transaction failed. \n
28,The DDE transaction could not be completed because the request timed out. \n
32,The specified dynamic-link library was not found.  \n
31,There is no application associated with the given file name extension.
This error will also be returned if you attempt to print a file that is not printable. \n
8,There was not enough memory to complete the operation. \n
26,A sharing violation occurred. \n
EndText
clear
lnErrors = ALines(aErrors,m.lcErrors,.t.,'\n')
For ix=1 to m.lnErrors
	If ( Val(Chrtran(left(aErrors[m.ix],;
		At(',',aErrors[m.ix])-1),Chr(13)+Chr(10),'')) = m.tnErrNum )
		lcMessage = Substr(aErrors[m.ix],At(',',aErrors[m.ix])+1)
		exit
	endif
EndFor
If Empty(m.lcMessage)
	lcMessage = 'An unspecified error occurred.'
EndIf
Return m.lcMessage
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform