全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2377
推到 Plurk!
推到 Facebook!

外部程式

尚未結案
m0210
一般會員


發表:31
回覆:29
積分:17
註冊:2002-08-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-01-30 00:40:09 IP:211.22.xxx.xxx 未訂閱
我由自己的程式開啟不定數目的應用程式(例如小畫家..計算機..等),想要在自己的程式的程式結束時,一併關閉那些外部程式,請問該如何作?
banson1716
高階會員


發表:55
回覆:182
積分:167
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-01-30 00:57:25 IP:61.223.xxx.xxx 未訂閱
//如何關閉外部程式(記事本為例) // 尋找已開啟"記事本"視窗 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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-01-31 19:38:25 IP:61.223.xxx.xxx 未訂閱
試試 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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-02-08 23:25:51 IP:211.22.xxx.xxx 未訂閱
感謝banson17162的提供~但是否有方法不用一個一個指定要關閉的程式呢? 假設是否有類似 For i= 0 to xxx
banson1716
高階會員


發表:55
回覆:182
積分:167
註冊:2002-04-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-02-09 16:50:43 IP:61.223.xxx.xxx 未訂閱
我只知道用此寫死的方法 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

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-02-10 15:27:13 IP:152.104.xxx.xxx 未訂閱
非常簡單 1. 記錄你所啟動的 ProcessID 2. 至於要如何記錄,就是改用 CreateProcess 來啟動程式 ,就可以了
banson1716
高階會員


發表:55
回覆:182
積分:167
註冊:2002-04-14

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-02-11 13:10:12 IP:61.223.xxx.xxx 未訂閱
試試範例 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;
系統時間:2024-05-04 4:02:56
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!