使用API,对所有窗口进行枚举(EnumWindows),在回调函数中对获得的每个窗口(窗口的
Handle)处理即可!
var
HWndCalculator : HWnd;
begin
HWndCalculator := Winprocs.FindWindow(nil, 'iexplore.exe'); Calculator
if HWndCalculator <> 0 then
SendMessage(HWndCalculator, WM_CLOSE, 0, 0);
end;
//还有一个
procedure KillProcess(dwProcessId: DWORD);
var
ProcHandle: THandle;
begin
ProcHandle := OpenProcess(1, FALSE, dwProcessID);
try
if ProcHandle <> 0 then
begin
if TerminateProcess(ProcHandle, $FFFFFFFF) then
WaitForSingleObject(ProcHandle, INFINITE);
end;
finally
CloseHandle(ProcHandle);
end;
end;