我在程序中用winexec('c:\windows\calc.exe',sw_show)调用了windows的计算器,
在退出程序时我想关闭计算器程序,请问各位高手我应该怎么做?thank you very
much!!!!!!!

解决方案 »

  1.   

    应该是采用API来关闭它的进程吧!具体用哪个我忘了!:(
      

  2.   

    杀死一个进程    
      {For Windows 9x/ME/2000/XP } 
    usesTlhelp32;function KillTask(ExeFileName: string): Integer;constPROCESS_TERMINATE = $0001;varContinueLoop: BOOL;FSnapshotHandle: THandle;FProcessEntry32: TProcessEntry32;beginResult := 0;FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);FProcessEntry32.dwSize := SizeOf(FProcessEntry32);ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);while Integer(ContinueLoop) <> 0 dobeginif ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =UpperCase(ExeFileName))) thenResult := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),FProcessEntry32.th32ProcessID),0));ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);end;CloseHandle(FSnapshotHandle);end;procedure TForm1.Button1Click(Sender: TObject);beginKillTask('notepad.exe');end;{ For Windows NT/2000/XP }procedure KillProcess(hWindowHandle: HWND);varhprocessID: INTEGER;processHandle: THandle;DWResult: DWORD;beginSendMessageTimeout(hWindowHandle, WM_CLOSE, 0, 0,SMTO_ABORTIFHUNG or SMTO_NORMAL, 5000, DWResult);if isWindow(hWindowHandle) thenbegin// PostMessage(hWindowHandle, WM_QUIT, 0, 0);{ Get the process identifier for the window}GetWindowThreadProcessID(hWindowHandle, @hprocessID);if hprocessID <> 0 thenbegin{ Get the process handle }processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,False, hprocessID);if processHandle <> 0 thenbegin{ Terminate the process }TerminateProcess(processHandle, 0);CloseHandle(ProcessHandle);end;end;end;end;procedure TForm1.Button2Click(Sender: TObject);beginKillProcess(FindWindow('notepad',nil));end;
      

  3.   

    不用这么麻烦了,我改用shellexecute(handle,'open','c:\windows\calc.exe',nil,nil,sw_show)
    然后var hnd:Thandle;

    hnd:=findwindow(nil,'计算器');
    if hnd<>0 then
    sendmessage(hnd,wm_close,0,0);
    即可!
    不过我还是给分!!!