unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> Button3: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> procedure Button3Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> StartupInfo:TStartupInfo;<br> ProcessInfo:TProcessInformation;<br>begin<br> // 初始化工作<br> FillChar(StartupInfo,Sizeof(StartupInfo),#0);<br> StartupInfo.cb := Sizeof(StartupInfo);<br><br> StartupInfo.dwFlags := STARTF_USESHOWWINDOW;<br> CreateProcess(nil,<br> 'Calc', // 运行计算器<br> nil,<br> nil,<br> false,<br> CREATE_NEW_CONSOLE or<br> NORMAL_PRIORITY_CLASS,<br> nil,<br> nil,<br> StartupInfo,<br> ProcessInfo);<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> WinExec('NotePad',SW_RESTORE); // 运行写字本<br>end;<br><br>procedure TForm1.Button3Click(Sender: TObject);<br>var<br> HWndCalc: HWnd; // 窗口句柄<br>begin<br> // 查找“计算器”窗口<br> HWndCalc:= FindWindow(nil, '计算器');<br> if HWndCalc <> 0 then<br> SendMessage(HWndCalc, WM_CLOSE, 0, 0);<br>end;<br><br>end.<br>