外部程式 |
尚未結案
|
m0210
一般會員 發表:31 回覆:29 積分:17 註冊:2002-08-23 發送簡訊給我 |
|
banson1716
高階會員 發表:55 回覆:182 積分:167 註冊:2002-04-14 發送簡訊給我 |
//如何關閉外部程式(記事本為例) // 尋找已開啟"記事本"視窗
procedure TForm1.Button2Click(Sender: TObject);
begin
ShellExecute(handle,'open','notepad.exe',nil,nil,SW_ShowNormal);
end; // 關閉已開啟"記事本"視窗
procedure TForm1.Button4Click(Sender: TObject);
begin
Npad := FindWindow(nil, '未命名 - 記事本');
if npad <> 0 then
SendMessage(npad, WM_CLOSE, 0, 0);
Close;
end;
|
banson1716
高階會員 發表:55 回覆:182 積分:167 註冊:2002-04-14 發送簡訊給我 |
試試
uses shellapi;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute(handle,'open','notepad.exe',nil,nil,SW_ShowNormal);
ShellExecute(handle,'open','PBRUSH.exe',nil,nil,SW_ShowNormal);
ShellExecute(handle,'open','CALC.exe',nil,nil,SW_ShowNormal);
end; procedure TForm1.Button2Click(Sender: TObject);
var npad:HWND;
begin
// == 記事本===
Npad := FindWindow(nil, '未命名 - 記事本');
if npad <> 0 then
SendMessage(npad, WM_CLOSE, 0, 0);
// == 小畫家===
Npad := FindWindow(nil, '未命名 - 小畫家');
if npad <> 0 then
SendMessage(npad, WM_CLOSE, 0, 0);
// == 小算盤===
Npad := FindWindow(nil, '小算盤');
if npad <> 0 then
SendMessage(npad, WM_CLOSE, 0, 0);
end;
|
m0210
一般會員 發表:31 回覆:29 積分:17 註冊:2002-08-23 發送簡訊給我 |
|
banson1716
高階會員 發表:55 回覆:182 積分:167 註冊:2002-04-14 發送簡訊給我 |
我只知道用此寫死的方法 var npad1,npad2, npad3:HWND;
begin
Npad1 := FindWindow(nil, '未命名 - 記事本');
if npad1 = 0 then
Exit
else
if npad1 <> 0 then
SendMessage(npad1, WM_CLOSE, 0, 0); Npad2 := FindWindow(nil, '未命名 - 小畫家');
if npad2 = 0 then
Exit
else
if npad2 <> 0 then
SendMessage(npad2, WM_CLOSE, 0, 0); Npad3 := FindWindow(nil, '小算盤');
if npad3 = 0 then
Exit
else
if npad3 <> 0 then
SendMessage(npad3, WM_CLOSE, 0, 0);
end;
|
懷舊的人
高階會員 發表:28 回覆:152 積分:141 註冊:2003-01-08 發送簡訊給我 |
|
banson1716
高階會員 發表:55 回覆:182 積分:167 註冊:2002-04-14 發送簡訊給我 |
試試範例
uses TLHelp32
function KillTask(ExeFileName: string): integer;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile))=UpperCase(ExeFileName))or(UpperCase(FProcessEntry32.szExeFile)=UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),FProcessEntry32.th32ProcessID),0));
ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end; procedure TForm1.Button1Click(Sender: TObject);
var
snapshot:THandle;
processinfo:PROCESSENTRY32; //在use中添加TLHelp32
status:boolean;
Names:string;
begin
ListBox1.Items.Clear;
processinfo.dwSize:=sizeof(processinfo);
snapshot:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); //CreateToolhelp32Snapshot創建一個快照
status := Process32First (snapshot,processinfo) ;
while (status) do
begin
Names:=processinfo.szExeFile;
ListBox1.Items.Add(processinfo.szExeFile);
status := Process32Next (snapshot, processinfo) ;
end;
end; procedure TForm1.Button2Click(Sender: TObject);
var
name:string;
begin
if listbox1.SelCount<>0 then
begin
name:=listbox1.Items.Strings[listbox1.ItemIndex];
KillTask(name);
end;
end;
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |