Winapi: ShellExecute-open an external program or file

Source: Internet
Author: User
ShellExecute (hwnd: hwnd; {specify the parent window handle} Operation: pchar; {specify the action, for example, open, print} filename: pchar; {specify the file to open or Program } 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 will be returned if the execution is successful. If this value is // an example to illustrate more problems (do not forget uses shellapi ;): {open a file in Notepad for example} begin ShellExecute (handle, 'open', 'notepad.exe ', 'c: \ windows \ schedlgu. TXT ', nil, sw_shownormal); end;
  
   
 {The first parameter is used as the parent window of the error Prompt window. It cannot be nil or 0 (desktop window)} begin ShellExecute (0, 'open ', 'notepad.exe ', 'c: \ windows \ schedlgu. TXT ', nil, sw_shownormal); end;
  
   
 {If the second parameter is nil, it also defaults to open} begin ShellExecute (0, nil, 'notepad.exe ', 'c: \ windows \ schedlgu. TXT ', nil, sw_shownormal); end;
  
   
 {File path can be placed in parameter 5} begin ShellExecute (0, nil, 'notepad.exe ', 'schedlgu. txt', 'c: \ Windows', sw_shownormal); end;
  
   
 {Specify parameter 3 as the file to be opened, and the file will be opened with the corresponding default program; Number Parameter 4 should be nil} begin ShellExecute (0, nil, 'schedlgu. TXT ', nil, 'c: \ Windows', sw_shownormal); end;
  
   
 {If the file is in the program directory/current directory/system32/Windows/PATH environment variable, you can also set parameter 5 to nil} begin ShellExecute (0, nil, 'schedlgu. TXT ', nil, nil, sw_shownormal); end;
  
   
 {If parameter 3 is a file, run parameter 2 to print the file.} begin ShellExecute (0, 'print', 'schedlgu. txt ', nil, nil, 1); end;
  
   
 {Open web page with IE} begin ShellExecute (handle, 'open', 'i0000e. EXE ', 'about: blank', nil, sw_shownormal); end;
  
   
 {Open web page with Firefox} begin ShellExecute (handle, 'open', 'firefox.exe ', 'about: blank', nil, sw_shownormal); end;
  
   
 {Open webpage with default browser} begin ShellExecute (handle, 'open', 'cmder.exe ', 'about: blank', nil, sw_shownormal); end;
  
   
 {Use the default browser to open the webpage} begin ShellExecute (0, nil, 'HTTP: // del.cnblogs.com ', nil, nil, 1); end;
  
   
 

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.