|
Please refer to:
How to call other programs in VFP
-------------------------------------------------- -----------
In VFP, we can use run to call the .exe file generated by VFP itself. Command format:
run c:\..\*.exe
When calling the .exe file that is not generated by VFP itself, you need to add the absolute path and parameters.
Generally speaking, when VFP is used to run executable files that are not generated by VFP itself, a black window will be displayed. You can hide this window by adding /n. For example, to run a minesweeper game under Windows, the command format is as follows:
RUN/n C:\Windows\Winmine.exe
Let's run a more complicated program. Use word to open a word file named mlx.doc under c:\, the command format is as follows:
run /n3 C:\Program Files\Microsoft Office\Office\Winword.exe C:\mlx.doc
Parameters: n hide the black window of VFP at runtime.
3 means to run the program in a maximized manner. 1 Normal way, 2 Minimize way, 3 Maximize way
In this case, although you can add parameters to make the program run smoothly, you still have to specify the absolute path. In actual development, we often cannot determine the file name and absolute path of the application that needs to be started. For example, in the above example, we cannot determine where the user's word is installed. If the user installs the word elsewhere, the above command will be wrong. Another example is a .gif file, some users like to open it with ACD See, some users like to open it with IE, and some users like to open it with Hero,...
To understand this situation, we can call the Windows file link to open the file. That is, all files are opened with the default program of the system. This is necessary to call the Win32 API function of Windows. The calling method is as follows:
DECLARE INTEGER ShellExecute IN shell32.DLL INTEGER HWND,STRING lpszOP,STRING lpszFile,STRING lpszParams,STRING lpszDir,INTEGER fsshowcmd
DECLARE INTEGER GetDesktopWindow IN win32api
HWND = GetDesktopWindow()
lpszOP = "open"
* Specify the name of the file to be opened
lpszFile ="c:\mlx.doc"
lpszParams = ""
lpszDir = "c:\temp"
fsshowcmd = 1
* Execute ShellExecute command
LNRETURN = ShellExecute(HWND, lpszOP,lpszFile, lpszParams, lpszDir,fsshowcmd)
You can use any file name to replace c:\mlx.doc above. If Windows cannot find the corresponding related program under the specified file name, the program will not respond at this time. The relevant parameters can be modified on your own trial to achieve the best results.
-------------------------------------------------- -----------
Use of API function ShellExecute
ShellExecute
Explain that the Shellexecute function is used to execute a verb (verb) on a file. It is usually used to start an application associated with a specific file type. For example, to start Word to read a .doc file, or start Notepad to edit a .txt File. The most common verb used in the second parameter is "Open", but the other available verbs are "edit", "print", "explore" and "properties". Interestingly, use "mailto:" Or "http://" prefix, ShellExecute function can also be used to start the default mail reader with a given email address or start the default browser with a given URL.
Shrink the main file Shell32.dll
Definition in VFP
DECLARE INTEGER ShellExecute IN "Shell32.dll" INTEGER hwnd,STRING lpVerb,STRING lpFile,STRING lpParameters,STRING lpDirectory,LONG nShowCmd
Visual FoxPro application example
* Open Word to edit the file "c:\mywordfile.doc"
=Shellexecute(0,"Open","c:\mywordfile.doc","","",1)
* Open the default browser and locate the paradise forum
=Shellexecute(0,"Open","http://www.dbwin.net/bbs/index.asp?boardID=1&page=1","","",1)
* Open the default mail reader to send a letter to the paradise moderator
=Shellexecute(0,"Open","mailto:njjane@21cn.com","","",1)
* Print the text file "c:\mytextfile.txt"
=Shellexecute(0,"Print","c:\mytextfile.txt","","",1) |
|