Delphi programming calls the specified Windows program

Source: Internet
Author: User
Tags response code

This example describes how to call the specified Windows program in your own program.

Start a new project and add 4 TButton components to the blank form. The form after you add the component is shown in Figure 1.

Figure 1 form after adding a component

Where the WinExec button is used to invoke the specified Windows program with the WinExec function. The ShellExecute button is used to invoke the specified Windows program with the ShellExecute function. The CreateProcess button and the TerminateProcess button are used to implement a more comprehensive operation on the invoked program, which is used to invoke the specified Windows program, while the latter is used to terminate the invoked Windows program.

The response code to invoke the specified Windows program in the form of the WinExec function is as follows:

procedure TForm1.btnWinExecClick(Sender: TObject);
begin
 WinExec(’Notepad.exe’,SW_MAXIMIZE);
end;

The 1th parameter of the WinExec function represents the path and name of the invoked program, and the 2nd parameter represents how the program is displayed.

The response code to invoke the specified Windows program in the form of the ShellExecute function is as follows:

procedure TForm1.btnShellExecuteClick(Sender: TObject);
begin
 ShellExecute(Application.Handle,’Open’,’NotePad.exe’,PChar(’C:\AutoExec.bat’),nil,SW_SHOWNORMAL);
end;

Where ShellExecute is used to open the program file associated with the specified file. The 1th parameter specifies a handle to a window, and the 2nd parameter specifies the class that the program runs, such as ' Open ' or ' print '; the 3rd parameter specifies a program name or file name that you want to print or open with the associated program, or if an executable file is specified in the 3rd argument, Then the 4th parameter is the argument passed to the executing program, and the 5th parameter specifies the full path of the executable program. The last parameter is used to set how the program runs.

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.