怎么关闭其它的程序啊??

解决方案 »

  1.   

    用FindWindow();获得其他程序的句柄
    然后发消息
    SendMessage(Handle,WM_CLOSE,0,0);
      

  2.   

    找到该程序的句柄(Handle),然后发送消息WM_CLOSE。
    例如:
    var
      Wnd:THandle;
    begin
      Wnd := FindWindow('notepad',nil); //关闭笔记本程序
      SendMessage(Wnd,WM_CLOSE,0,0);
    end;
      

  3.   

    以前摘抄的:
    use 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);
    begin
       KillTask('notepad.exe');
    end;
      

  4.   

    其中,FindWindow有两个参数,第一个为改程序的类名,第二个为程序的窗口标题。
    可以任写一个,另一个为nil。要得到程序的类名可以使用SPY++程序(VC带),或是WinSight32程序(delphi带)。
    如果FindWindow返回0,表示找不到该程序
      

  5.   

    下面给出一段在 Delphi 中关闭“计算器”程序为例: 
    var 
    HWndCalculator : HWnd; 
    begin 
    // find the exist calculator window 
    HWndCalculator := Winprocs.FindWindow(nil, '计算器'); // close the exist Calculator 
    if HWndCalculator <> 0 then 
    SendMessage(HWndCalculator, WM_CLOSE, 0, 0); 
    end; 
    就是先查找现在已经打开的窗体的名字,得到句柄,然后发送消息关闭它