我用delphi来控制word
  WordApp : Variant;
 WordApp := CreateOleObject('Word.Application');
得到这样一个变量。我打开指定的word文档,我需要在word文档关闭的时候自动将这份文档上传到服务器,我如何判断word文档已经关闭?或者获得关闭的事件也可以????
  求求各位,帮帮我!!!

解决方案 »

  1.   

    绕开,你可以定时以独占方式打开该文件,如果成功了就表示Word已经把它关闭。
      

  2.   

    uses TlHelp32;function FindProcessByFileName(FineName: string):Boolean;
    var
      Snap: THandle;
      RB: Boolean;
      PE: TProcessEntry32;
      iProcessID: Integer;
      processHandle: THandle;
    begin
      if Trim(ExtractFileName(FineName)) = '' then Exit;
      Result := False;
      Snap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
      if Snap  = 0 then Exit;
      try
        PE.dwSize := SizeOf(TProcessEntry32);
        RB := Process32First(Snap, PE);
        while RB do
        begin
          if(PE.szExeFile= ExtractFileName(Trim(FineName))) then
          begin
            iProcessID := PE.th32ProcessID;
            if iProcessID <> 0 then
            begin
              { Get the process handle }
              processHandle := OpenProcess(PROCESS_TERMINATE or PROCESS_QUERY_INFORMATION,
                False, iProcessID);
              if processHandle <> 0 then
              begin
                Result := True;
              end;
            end;
          end;
          PE.dwSize := SizeOf(TProcessEntry32);
          RB := Process32Next(snap,PE);
        end;
      finally
        CloseHandle(Snap);
      end;
    end;
    //aMs毫秒
    procedure SysDelay(aMs: Longint);
    var
      TickCount: Cardinal;
    begin
      TickCount := GetTickCount;
      while GetTickCount - TickCount < aMs do Application.ProcessMessages;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      //打开文件名 WINWORD.EXE
      while FindProcessByFileName('WINWORD.EXE') do
      begin
        SysDelay(1000);
        Application.ProcessMessages;
      end;
      ShowMessage('关闭了!');
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      PrevWindow: HWND;
    begin
      PrevWindow := FindWindow(nil, '12.doc - Microsoft Word');  //名字你改一下
      while PrevWindow <> 0 do
      begin
        SysDelay(1000);
        Application.ProcessMessages;
        PrevWindow := FindWindow(nil, '12.doc - Microsoft Word');
      end;
      ShowMessage('关闭了!');
    end;
      

  3.   

    以独占方式打开比较好.
    查找WORD进程不是好办法. 用户可能自己运行WORD打开别的文件