海信家电”换帅 “ 高玉玲接替代慧忠出任新任董事长
2024-11-22
图1 添加组件后的窗体 |
procedure TForm1.btnWinExecClick(Sender: TObject); begin WinExec(’Notepad.exe’,SW_MAXIMIZE); end; |
procedure TForm1.btnShellExecuteClick(Sender: TObject); begin ShellExecute(Application.Handle,’Open’,’NotePad.exe’,PChar(’C:\AutoExec.bat’),nil,SW_SHOWNORMAL); end; |
PI:TProcessInformation; SI:TStartUpInfo; MyHandle:Thandle; |
procedure TForm1.btnCreateProcessOpenClick(Sender: TObject); begin FillChar(SI,sizeof(SI),#0); with SI do begin cb:=sizeof(SI); dwFlags:=StartF_UsesTDHandles or STARTF_USESHOWWINDOW; lptitle:=nil; wShowWindow:=SW_Show; end; CreateProcess(PChar(’C:\WINNT\Notepad.exe’), nil,nil,nil,true,DETACHED_PROCESS,nil,nil,SI,PI); end; |
procedure TForm1.btnCreateProcessCloseClick(Sender: TObject); begin MyHandle:=OpenProcess(PROCESS_ALL_ACCESS, FALSE,PI.dwProcessId); TerminateProcess(MyHandle,0); end; |
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ShellAPI; type TForm1 = class(TForm) btnWinExec: TButton; btnCreateProcessOpen: TButton; btnCreateProcessClose: TButton; btnShellExecute: TButton; procedure btnWinExecClick(Sender: TObject); procedure btnCreateProcessOpenClick(Sender: TObject); procedure btnCreateProcessCloseClick(Sender: TObject); procedure btnShellExecuteClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; PI:TProcessInformation; SI:TStartUpInfo; MyHandle:Thandle; implementation {$R *.dfm} procedure TForm1.btnWinExecClick(Sender: TObject); begin WinExec(’Notepad.exe’,SW_MAXIMIZE); end; procedure TForm1.btnCreateProcessOpenClick(Sender: TObject); begin FillChar(SI,sizeof(SI),#0); with SI do begin cb:=sizeof(SI); dwFlags:=StartF_UsesTDHandles or STARTF_USESHOWWINDOW; lptitle:=nil; wShowWindow:=SW_Show; end; CreateProcess(PChar(’C:\WINNT\Notepad.exe’),nil,nil,nil,true,DETACHED_PROCESS,nil,nil,SI,PI); end; #p#分页标题#e# procedure TForm1.btnCreateProcessCloseClick(Sender: TObject); begin MyHandle:=OpenProcess(PROCESS_ALL_ACCESS, FALSE,PI.dwProcessId); TerminateProcess(MyHandle,0); //关闭进程 end; procedure TForm1.btnShellExecuteClick(Sender: TObject); begin ShellExecute(Application.Handle,’Open’,’NotePad.exe’,PChar(’C:\AutoExec.bat’),nil,SW_SHOWNORMAL); end; end. |
图2 程序运行的初始画面 |
图3 程序运行结果 |
评论 {{userinfo.comments}}
{{child.content}}
{{question.question}}
提交