Various usage of Windows API functions shellexecute

zhaozj2021-02-16  48

When you see the information on a website, I found a learning information about the Windows API function. Translation to recognize the use of this API faster.

SHELLEXECUTE function is to run an external program (or open a registered file, open a directory, print a file, etc.) and have certain control over external programs.

There are several API functions to implement these features, but in most cases, shellexecute is more used, and it is not too complicated. The following is an example of its usage.

Start a new application

Shellexecute (Handle, 'Open', Pchar ('c: /test/app.exe'), NIL, NIL, SW_SHOW;

Open a notepad and open a file (system can identify the path to the notepad application, so we don't have to use the absolute path)

Shellexecute (Handle, 'Open', Pchar ('Notepad'), Pchar ('C: / Test/readme.txt'), NIL, SW_SHOW;

Print a document

Shellexecute (Handle, 'Print', Pchar ('C: / Test/test.doc'), NIL, NIL, SW_SHOW);

Note: Maybe you will see Word Temporary Open, but it will automatically turn off.

Open an HTML page

Shellexecute (Handle, 'Open', Pchar ('http://www.festra.com/'), nil, nil, sw_show;

You can open the application through a registered file type

Shellexecute (Handle, 'Open', Pchar ('C: /Test/readme.txt'), NIL, NIL, SW_SHOW;

Open a directory with Windows Explorer

Shellexecute (Handle, 'Explore', Pchar ('C: / Windows)', NIL, NIL, SW_SHOW;

Run a DOS command and return immediately

Shellexecute (Handle, 'Open', Pchar ('Command.com'), Pchar ('/ c copy file1.txt file2.txt'), nil, sw_show;

Run a DOS command and keep the DOS window exist

Shellexecute (Handle, 'Open', Pchar ('Command.com'), Pchar ('/ K Dir'), NIL, SW_SHOW);

转载请注明原文地址:https://www.9cbs.com/read-23017.html

New Post(0)