To open the default program using ShellExecute (mail client)

Source: Internet
Author: User
Tags function prototype one mail microsoft outlook

Reprint: http://www.cnblogs.com/xubin0523/archive/2012/11/01/2749729.html

ShellExecute
The function of ShellExecute is to run an external program (either open a registered file, open a directory, print a file, etc.) and have some control over the external program.

There are several API functions that can implement these functions, but in most cases shellexecute is more used, and it is not too complex.

ShellExecute function prototype and parameter meanings are as follows:

ShellExecute (

HWND hwnd,//parent window handle (eg: null,handle, etc.)

LPCSTR lpoperation,//operation type (e.g. "open") * to add double quotation marks

LPCSTR lpfile,//file or path to be manipulated

LPCSTR lpparameters,//Specify parameters to pass when Lpoperation is "explore", usually set to null

LPCSTR lpdirectory,//Specify default directory, usually set to null

INT nShowCmd//How the file is opened in the usual way or maximized or minimized, typically sw_shownormal

)
Parameter description:
HWnd: Used to specify the parent window handle. When an error occurs in the function call procedure, it acts as the parent window of the Windows message window. For example, you can set it to the application main window handle, which is application.handle, or you can set it as the desktop window handle (obtained with the GetDesktopWindow function).

Operation: Used to specify the action to be made. Where the "open" operation means that the program specified by the filename parameter is executed, or the file or folder specified by the filename parameter is opened, and the "print" operation means that the file specified by the filename parameter is printed; "Explore" The action represents browsing the folder specified by the filename parameter. When the parameter is set to nil, the default action "open" is executed.

FileName: Used to specify the file name to open, the name of the program file to execute, or the folder name to browse.

Parameters: If the filename parameter is an executable program, this parameter specifies a command-line argument, 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 how the program window is initially displayed, otherwise this parameter should be set to 0.

If the ShellExecute function call succeeds, the return value is the instance handle of the executing program. If the return value is less than 32, it indicates an error occurred.

The above is only the standard usage of the ShellExecute function, and the following describes its special usage.
Examples are as follows:

Call Notepad

ShellExecute (NULL, "open", "NOTEPAD"). EXE ", null,null,sw_shownormal);


2. Special usage

If the filename parameter is set to the "http:" protocol format, the function opens the default browser and links to the specified URL address. If multiple browsers are installed in the user's machine, the function determines which browser to start based on the settings of the HTTP protocol handler (Protocols Handler) in the Windows 9x/nt registry.

Format one:/HTTP website domain name.

e.g. ShellExecute (Handle, "open", http://;

Www.neu.edu.cn ', NULL, NULL, SW_SHOWNORMAL);

Format two: HTTP//Website name/page file name.

e.g. ShellExecute (Handle, "open", http://;

Www.neu.edu.cn/default.htm ', Null,null,

SW_SHOWNORMAL);

If the filename parameter is set to the "mailto:" protocol format, the function launches the default mail client, such as Microsoft Outlook (also including Microsoft Outlook Express) or Netscape Messanger. If more than one mail client is installed in the user's machine, the function determines which mail client to start based on the settings of the Mailto protocol handler in the Windows 9x/nt registry.

Format one: mailto:

such as: ShellExecute (Handle, "open", "mailto:", null, NULL, SW_SHOWNORMAL); Open the new mail window.

Format two: mailto: User account @ Mail server address

such as: ShellExecute (Handle, "open", "mailto:[email protected]", NULL, NULL, SW_SHOWNORMAL), opens a new mail window, and automatically fills in the recipient's address. If you specify multiple recipient addresses, the recipient addresses must be separated by semicolons or commas (hereinafter).

Format three: mailto: User account @ Mail server address? subject= message subject &body= message body

such as: ShellExecute (handle, ' open ', ' mailto:[email protected]? Subject=hello&body=this is a test ', nil, nil, SW_SHOWNORMAL); Opens a new mail window and automatically fills in the recipient address, message subject, and message body. If the message body includes multiple lines of text, you must add a newline escape character%0a between each line of text.


Example (Delphi):

Call C:\Project1.exe in an application;

ShellExecute (handle, ' open ', ' c:\Project1.exe ', ' string contents ', nil, SW_SHOWNORMAL);

Can be called in Project1.exe:

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, which specifies a command for the visibility of the window.

Please use any one of the following constants

Sw_hide hidden window, active state to another window

sw_minimize minimized window, active state to another window

Sw_restore displays a window with its original size and position, while making it active

Sw_show displays a window with the current size and position, and makes it active

Sw_showmaximized to maximize the window and activate it

sw_showminimized Minimize the window and activate it

Sw_showminnoactive minimizes a window without changing the active window

Sw_showna displays a window with the current size and position without changing the active window

Sw_shownoactivate displays a window with the nearest size and position without changing the active window

Sw_shownormal is the same as Sw_restore

ShellExecute

To open the default program using ShellExecute (mail client)

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.