ShellExecute application window

ShellExecute
has three API functions can run the executable file WinExec, ShellExecute and CreateProcess.
1.CreateProcess because the use of complex, rarely used.
2.WinExec mainly run the EXE file. Such as: WinExec ( 'the Readme.txt Notepad.exe', SW_SHOW);
3.ShellExecute can not only run the EXE file or files already associated with the run.
Shellapi.pas must first reference means: uses ShellAPI;
. 1) standard usage.
  The ShellExecute function prototype and parameters are as follows:
  function the ShellExecute (the hWnd: the HWND; Operation, FileName, the Parameters, Directory: the PChar; ShowCmd: Integer): HINST; _stdcall;
  ● hWnd: used to specify the parent window handle. When an error occurs during a function call, it will serve as the parent window Windows message window. For example, it may be set to the main application window
handle, i.e. Application.Handle, may be provided (the function obtained by GetDesktopWindow) desktop window handle.
  ● Operation: specifies an operation to be performed. Where the "open" operation indicates execution specified by the FileName parameter program, or open specified by the FileName parameter file or
folder; "print" operation indicates that the print specified by the FileName parameter file; "explore" operation indicates the browser specified by the FileName argument folder. When the parameter is set to nil, expressed enforcement
The default action line "open". 
  ● FileName: used to specify the name of the file to be opened, the file name of the program to be executed or to browse the folder name.
  ● Parameters: If the FileName parameter is an executable program, this parameter specifies the command-line parameters, otherwise this parameter should be nil or PChar (0).
  ● Directory: used to specify the default directory.
  ● ShowCmd: If the initial parameter FileName is an executable program, this parameter specifies the window display mode, otherwise this parameter should be set to 0.
  If ShellExecute function succeeds, the value of the execution of the program instance handle is returned. If the return value is less than 32, then an error occurred.
  The foregoing is merely a function ShellExecute standard usage, it will be described below the special usage.
2) Special usage.
  If the FileName parameter is set to "http:" protocol format, the function will open your default browser and link to the specified URL. If the user's machine in a multiple browsers installed
, the function will determine which browser is set to start based on Windows 9x / NT Registry http protocol handler (Protocols Handler) is.
  Formats: http: // domain.
  Such as: ShellExecute (handle, 'open' , http://www.neu.edu.cn ', nil, nil, SW_SHOWNORMAL);
  format two: http: // domain / web page file name.
  Such as: ShellExecute (handle, 'open' , http://www.neu.edu.cn/default.htm',nil,nil,SW_SHOWNORMAL);


  If the FileName parameter is set to "mailt" protocol format, the function will start the default mail client, such as Microsoft Outlook (also included in the Microsoft
Outlook Express) or Netscape Messanger. If more than one mail client program installed on the user's machine, the function will be based on Windows 9x / NT Registry mailto protocol processing
to determine which mail client to start the setup program.
  Formats: mailt
  such as: ShellExecute (handle, 'open' , 'mailt', nil, nil, SW_SHOWNORMAL); new message window opens.
  Two formats: mailt user account @ mail server address
  such as: ShellExecute (handle, 'open' , '[email protected]', nil, nil, SW_SHOWNORMAL); open a new message window, fill and close automatically
member people address. If you specify a plurality of recipient addresses, between the recipient addresses must be separated by a comma or a semicolon (below).
  Three formats:? Mailt user account @ mail server address subject = mail subject & body = body of the message
  , such as: ShellExecute (handle, 'open' , '[email protected]?subject=Hello&Body=This is a test', nil, nil,
SW_SHOWNORMAL); open a new message window, and automatically fill in the recipient's address, message subject and message body. If the message body include multiple lines of text, it must include line breaks between each line of text

Escape character% 0a.
Examples (Delphi):
in an application calls the c: \ Project1.exe;
ShellExecute (handle, 'Open', 'c: \ Project1.exe', 'string content', nil, SW_SHOWNORMAL);
in Project1.exe in can call:
Procedure TForm1.FormCreate (Sender: TObject);
var
I: Integer;
the begin
for I: = ParamCount to do. 1
IF ParamStr (I) <> '' the then
    ShowMessage (ParamStr (I));
End;
finally that parameter specifying a command terms of visibility of the window. Please any one of the following constants:
SW_HIDE hidden window, to make a window active
SW_MINIMIZE minimized window, to make a window active
SW_RESTORE display a window with the original size and position, so that it enters the active state while
SW_SHOW with the current displaying a window size and location, so that it enters the active state while
SW_SHOWMAXIMIZED maximized window, and activate it
SW_SHOWMINIMIZED minimize the window, and activate it
SW_SHOWMINNOACTIVE a window is minimized, while not changing the active window
SW_SHOWNA a display window, the active window does not change the size and position with the current
SW_SHOWNOACTIVATE display a window with the size and location of the latest, while not changing the active window
SW_SHOWNORMAL the same SW_RESTORE
 

Usage example:

If you open the site 
ShellExecute (0, "open",  "http://www.csdn.net", 0, 0, 1);
replaces the third argument to want to open the site you can
if you open a file 
ShellExecute (0 , "open", "D:  \ 1.txt", 0, 0, 1);
replace the third parameter into the path of the file, while paying attention to \ replace \
if a print file, 
the ShellExecute (0, "Print" , "D: \ 1.txt",  0, 0, 1);
replace the third parameter into the path of the file, while paying attention to \ replace \
open an executable file 
ShellExecute (0, "open", "C: \ Program files (x86) \ Tencent  \ QQ \ QQProtect \ Bin \ QQProtect.exe ", 0, 0, 1);
replace the third parameter into the path of the file, while paying attention to \ replace \ 
open system comes not need to specify the path, 
ShellExecute (0, "open", "notepad", 0, 0, 1); * /
open a folder 
ShellExecute (0, "open", "C: \", 0, 0, 1)
need to replace the third parameter into the path of the folder, while paying attention to \ into \
mail 
ShellExecute (0, "open",  "mailto:", 0, 0, 1);
replacing the third parameter to mailto : 
Send e-mail specifically address 
ShellExecute (0, "open", "[email protected]", 0, 0, 1);
 

Published 17 original articles · won praise 2 · views 20000 +

Guess you like

Origin blog.csdn.net/toove/article/details/98215078