1. Use the default email transceiver to send emails
Uses
..., Shellapi;
VaR
Lphwnd: hwnd;
Lpoperation, lpfile, lpparameters, lpdirectory: string;
Begin
Lphwnd: = getmediatopwindow ();
Lpoperation: = 'open ';
Lpfile: = 'mailto: '+ 'maple119 @ 263.net' + '? '// Use '? 'End
+ '& CC =' + 'balaba960808 @ 163.com '// CC
+ '& BCC =' + 'lyf .kibosoft.com '// BCC
+ '& Subject =' + 'topic'
+ '& Body =' + 'content in the first line' + '% 0d' + 'content in the second line '// The topic content is transferred to' % 0d'
+ '& File =' + 'd: \ HELP. rtf '; // the attachment is only valid for Outlook Express.
Lpparameters: = '';
Lpdirectory: = '';
ShellExecute (lphwnd, pchar (lpoperation ),
Pchar (lpfile), pchar (lpparameters ),
Pchar (lpdirectory), sw_shownormal );
End;
2. Open a webpage
ShellExecute (0, 'open', 'HTTP: // www.google.com ', '','', sw_shownormal );
3. Print documents
ShellExecute (0, 'print ', 'd: \ HELP. rtf', '','', sw_shownormal)
4. Open a specified file using the default program of the system
ShellExecute (0, 'open', 'd: \ HELP. rtf ', '','', sw_shownormal ))
5. Open the specified file with the specified program
ShellExecute (0, 'open', 'notepad.exe ', 'd: \ HELP. rtf', '', sw_shownormal)
6. Run the shortcut (. lnk)
ShellExecute (handle, 'open', 'c: \ windows \ Desktop \ AAA. lnk ', '','', sw_hide );
Winexec mainly runs the EXE file. For example, winexec('notepad.exe readme.txt ', sw_show );
ShellExecute can run not only EXE files, but also associated files.
First, you must reference the shellapi. Pas unit: Uses shellapi;
1. Standard usage
The meanings of the parameters and prototype of the ShellExecute Function are as follows:
Function ShellExecute (hwnd: hwnd; operation, filename, parameters, directory: pchar; showcmd: integer): hinst; stdcall;
● Hwnd: Specifies the parent window handle. When an error occurs during a function call, it is used as the parent window of the Windows message window. For example, you can set it to the application Main Window handle, that is, application. Handle, or desktop window handle (obtained using the getdesktopwindow function ).
● Operation: Specifies the operation to be performed. The "open" operation indicates that the program specified by the filename parameter is executed, or the file or folder specified by the filename parameter is opened. The "print" operation indicates that the file specified by the filename parameter is printed; the "Browse e" operation indicates browsing the folder specified by the filename parameter. If the parameter is set to nil, the default operation "open" is executed ".
● Filename: used to specify the name of the file to be opened, the name of the program file to be executed, or the name of the folder to be browsed.
● Parameters: If the filename parameter is an executable program, this parameter specifies the command line parameter; otherwise, this parameter should be nil or pchar (0 ).
● Directory: used to specify the default directory.
● Showcmd: If the filename parameter is an executable program, this parameter specifies the initial display mode of the program window. Otherwise, this parameter should be set to 0.
If the ShellExecute Function is successfully called, the returned value is the instance handle of the executed program. If the returned value is smaller than 32, an error occurs.
The above is only the standard usage of the ShellExecute Function. The following describes its special usage.
2. Special usage
If you set the filename parameter to the "http:" protocol format, this function opens the default browser and links to the specified URL address. If multiple browsers are installed on your machine, the function determines which browser to start based on the settings of the HTTP handler (Protocols handler) in Windows 9x/NT Registry.
Format 1: http: // website domain name.
Example: ShellExecute (handle, 'open', http ://;Www.neu.edu.cn', Nil, nil, sw_shownormal );
Format 2: http: // website domain name/Webpage file name.
Example: ShellExecute (handle, 'open', http ://;, Sw_shownormal );
If you set the filename parameter to the "mailto:" protocol format, this function starts the default mail client program, such as Microsoft Outlook (including Microsoft Outlook Express) or Netscape Messanger. If multiple email client programs are installed on your machine, this function determines which email client program to start based on the settings of the mailto protocol handler in the Windows 9x/NT Registry.
Format 1: mailto:
For example, ShellExecute (handle, 'open', 'mailto: ', nil, nil, sw_shownormal); opens the new mail window.
Format 2: mailto: User Account @ email server address
Example: ShellExecute (handle, 'open ',', Nil, nil, sw_shownormal); opens the new mail window and automatically fills in the recipient address. If multiple recipient addresses are specified, the recipient addresses must be separated by semicolons or commas (, the same below ).
Format 3: mailto: User Account @ email server address? Subject = Email Subject & Body = Email body
Example: ShellExecute (handle, 'open ','? Subject = Hello & Body = This is a test ', nil, nil, sw_shownormal); opens the new mail window and automatically fills in the recipient address, mail subject, and mail body. If the mail body contains multiple lines of text, you must add the line feed escape character % 0a between each line of text.
Example (Delphi ):
Call C: project1.exe in an application;
ShellExecute (handle, 'open', 'c: project1.exe ', 'string content', nil, sw_shownormal );
In project1.exe, you can call:
Procedure tform1.formcreate (Sender: tobject );
VaR I: integer;
Begin
For I: = 1 to paramcount do
If paramstr (I) <> ''then showmessage (paramstr (I ));
End;
The last parameter specifies the visibility command for the window.
Use any of the following Constants
Sw_hide hides the window, and the activity status gives a window
Sw_minimize minimizes the window, and the active status gives a window
Sw_restore displays a window with the original size and position, and enables it to enter the active status.
Sw_show displays a window with the current size and position, and enables it to enter the active status.
Sw_showmaximized: Maximize the window and activate it.
Sw_showminimized minimizes the window and activates it.
Sw_showminnoactive minimizes a window without changing the activity window.
Sw_showna displays a window with the current size and position without changing the activity window.
Sw_shownoactivate displays a window with the latest size and position without changing the activity window.
Sw_shownormal is the same as sw_restore.