"Go" ShellExecute ()--Run an external program

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

Original link: http://www.verydemo.com/demo_c173_i86999.html

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. Basic introduction There are several API functions that can implement these functions, but in most cases shellexecute is more used, and it is not too complex. Prototype and parametric meanings ShellExecute function prototype and parameter meanings are as follows: ShellExecute (
Hwnd:hwnd;   {Specify parent Window handle} Operation:pchar;   {Specify an action, for example: Open, print} Filename:pchar;   {Specify the file or program to open} Parameters:pchar;   {Specify parameters for the program you want to open, or nil if you open the file} Directory:pchar;   {Default Directory} Showcmd:integer {Open option}): HINST; {Execution succeeds returns the application handle; if this value<= +, which indicates an execution error} //possible errors in the return value are: = 0 {out of memory}Error_file_not_found=2;  {File name error} Error_path_not_found=3;  {Path name error} Error_bad_format= One;  {EXE file is invalid} Se_err_share= -;  {A sharing error has occurred} Se_err_associncomplete= -;  {The file name is not complete or invalid} Se_err_ddetimeout= -;  Timeout Se_err_ddefail= in;  {DDE transaction failed} Se_err_ddebusy= -;  {The DDE transaction cannot be completed while the other DDE transaction is being processed} Se_err_noassoc= to; {There are no associated applications} //showcmd Parameter Optional value: sw_hide = 0; {Hidden}Sw_shownormal=1;  {display with the nearest size and position, activate} Sw_normal=1;  {Same Sw_shownormal} Sw_showminimized=2;  {Minimized, active} Sw_showmaximized=3;  {Maximize, activate} Sw_maximize=3;  {Same sw_showmaximized} Sw_shownoactivate=4;  {display with the nearest size and position, not activated} Sw_show=5;  {Same Sw_shownormal} Sw_minimize=6;  {minimized, not activated} Sw_showminnoactive=7;  {Same Sw_minimize} Sw_showna=8;  {Same Sw_shownoactivate} Sw_restore=9;  {Same Sw_shownormal} Sw_showdefault=Ten;  {Same Sw_shownormal} Sw_max=Ten; {Same Sw_shownormal}
Example//Call CalculatorShellExecute (NULL,"Open","calc.exe", Null,null,sw_shownormal); //Call NotepadShellExecute (NULL,"Open","NOTEPAD. EXE", Null,null,sw_shownormal); 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.
2. Special usage If you set the filename parameter 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 will be based on the Windows 9x/the settings of the HTTP protocol handler (Protocols Handler) in the NT registry determine which browser to start. Format one: http://website domain name. such as: ShellExecute (Handle,"Open","http: //;www.neu.edu.cn", NULL, NULL, SW_SHOWNORMAL);

Format two: http://website name/page file name. such as: 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 will be based on the Windows 9x/the setup of the Mailto protocol handler in the NT registry determines which mail client to start.
Format one: mailto: 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 isa test ', NULL, NULL, SW_SHOWNORMAL); Opens a new mail window and automatically fills in the recipient's 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', NULL, SW_SHOWNORMAL);  Can be called in Project1.exe: procedure tform1.formcreate (Sender:tobject); varI:integer; Begin fori:=1To ParamCount Do    ifParamstr (i) <>"'Then showmessage (Paramstr (i));  End  The last parameter, which specifies a command for the visibility of the window. Please use any of the following constants Sw_hide hide the window, the active state to another window sw_minimize minimized window, the active state to another window Sw_restore with the original size and position to display a window, while Make it active sw_show displays a window with the current size and position, and makes it active sw_showmaximized maximizes the window and activates it sw_showminimized the minimized window and activates S W_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 a window with the nearest size and position without changing the live Dynamic window Sw_shownormal is the same as Sw_restore

"Go" ShellExecute ()--Run an external program

Related Article

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.