var
FindHandle:HWND;
begin
FindHandle:=FindWindow('QQ.exe',nil);
if(FindHandle<>0)then
  begin
  showmessage('OK');
  SendMessage(FindHandle,WM_CLOSE,0,0);
  exit;
  end;
  showmessage('没有找到QQ程序');
end;
明明我打开着QQ,但是还不提示'没有找到QQ程序'.应该怎么做呢?

解决方案 »

  1.   

    FindWindow('QQ.exe',nil)
    这样找qq的方法是不行的!
      

  2.   

    用程序监视进程,如果进程名称为:QQ.exe就关掉.
    function TJinChenForm.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;
    end;procedure TForm1.TimerTimer(Sender: TObject);
    var  Proc   :TPROCESSENTRY32 ;
          Snap   :THandle;
          str_proc_msg:string;begin   TaskList.Items.Clear;
       Snap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS,0);
       Proc.dwSize := SizeOf(TProcessEntry32);
       Process32First(Snap,Proc);
      repeat
         TaskList.Items.Add(proc.szExeFile);
       //  my_stringList1.Append(proc.szExeFile);
       until (not Process32Next(Snap,Proc));   result:=true;
         //result:=true;    WINWORD.EXE  MSACCESS.EXE
       if TaskList.Items.IndexOf('QQ.exe')>-1 then
      begin
             killtask('QQ.exe');
       end ;
      end;  
      

  3.   

    以上程序好像在win98下无效呀!!!