API function shellexcute

Source: Internet
Author: User
Tags microsoft outlook

ShellExecute (null, "open", "winword", "d: // 1.doc", null, sw_show );
ShellExecute (null, "open", "winword", "d: // 2.txt", null, sw_show );
ShellExecute (null, "open", "winword", "d: // 3.html", null, sw_show );
 
The prototype and parameter Meanings of the ShellExecute Function are as follows: ShellExecute (hwnd: hwnd; {specify the parent window handle} Operation: pchar; {specify the action, for example, open, print} filename: pchar; {specify the file or program to be opened} parameters: pchar; {specify parameters for the program to be opened; if the file is opened, it should be nil} Directory: pchar; {default directory} showcmd: INTEGER {open option}): hinst; {the application handle is returned if the execution is successful. If the value is <= 32, indicates execution error} // possible errors returned: = 0 {insufficient memory} error_file_not_found = 2; {file name error} error_path_not_found = 3; {path name error} error_bad_format = 11; {EXE file invalid} se_err_share = 26; {sharing error} se_err_associncomplete = 27; {file name incomplete or invalid} se_err_ddetimeout = 28; {timeout} se_err_ddefail = 29; {DDE Transaction Failed} se_err_ddebusy = 30; {another DDE transaction is being processed and this DDE transaction cannot be completed} se_err_noassoc = 31; {No associated application} // optional showcmd parameter value: sw_hide = 0; {hide} sw_shownormal = 1; {display with the nearest size and position, activation} sw_normal = 1; {same as sw_shownormal} sw_showminimized = 2; {minimized, activation} optimized = 3; {maximized, activation} sw_maximize = 3; {same as sw_showmaximized} sw_shownoactivate = 4; {display with the nearest size and position, not activated} sw_show = 5; {same as sw_shownormal} sw_minimize = 6; {minimized, not activated} sw_showminnoactive = 7; {same as sw_minimize} sw_showna = 8; {same as sw_shownoactivate} sw_restore = 9; {same as sw_shownormal} sw_showdefault = 10; {same as sw_shownormal} sw_max = 10; {same as sw_show}
[Edit this section] example
// Call the calculator ShellExecute (null, "open", "calc.exe", null, null, sw_shownormal); // call the notepad ShellExecute (null, "open", "notepad. EXE ", null, null, sw_shownormal); ● 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.
[Edit this section] 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", null, null, sw_shownormal );
Format 2: http: // website domain name/Webpage file name.
Example: ShellExecute (handle, "open", "http: //; www.neu.edu.cn/default.htm", null, null, 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:", null, null, sw_shownormal); opens the new mail window.
Format 2: mailto: User Account @ email server address
Example: ShellExecute (handle, "open", "mailto: who@mail.neu.edu.cn", null, null, sw_shownormal); opens a 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 = mail subject & Body = Mail body such as: ShellExecute (handle, 'open', 'mailto: who@mail.neu.edu.cn? Subject = Hello & Body = This is a test ', null, null, 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; ShellExecute (handle, 'open', "C:/project1.exe", 'string content', null, sw_shownormal in an application ); 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 a command for visibility in the window. Use any of the following constant sw_hide to hide the window. The activity state is minimized for the other window sw_minimize. The activity state is displayed for the other window sw_restore with the original size and position, at the same time, make it enter the activity status sw_show to display a window with the current size and position, and make it enter the activity status sw_showmaximized maximization window, and activate it to the sw_showminimized minimization window, activate sw_showminnoactive to minimize a window, and display a window with the current size and position without changing the activity window sw_showna. Do not change the activity window sw_shownoactivate to display a window with the latest size and position, the activity window sw_shownormal and sw_restore are not changed at the same time.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.