因为一个exe可以开很多个,类名和名字都一样的
那么如果要对其中某一个发送消息
只能根据pid了吧?
我想根据pid进行回车及其esc之类的操作
有办法吗?
如果只开一个exe的时候用sendmessage 就可以 
如果很多个的时候呢?

解决方案 »

  1.   

    根据进程ID号来获取窗体句柄:function GetHwndFromProcess(ProcessId: DWORD): HWND;
      function _EnumWindowsProc(P_HWND: Cardinal; lParam: Cardinal): Boolean; stdcall;
      var
        PID: DWORD;
      begin
        GetWindowThreadProcessId(P_HWND, @PID);
        if PCardinal(lParam)^ <> PID then
          Result := True
        else
        begin
          Result := False;
          PCardinal(lParam+4)^ := P_HWND;
        end;
      end;
    var
      Buffer: array[0..1] of Cardinal;
    begin
      Result := 0;
      Buffer[0] := ProcessId;
      Buffer[1] := 0;
      EnumWindows(@_EnumWindowsProc, Integer(@Buffer));
      if Buffer[1] > 0 then Result := Buffer[1];
    end;
      

  2.   

    仔细看看那个EXE同时运行还有其他什么不同的地方没