我想通过查找EXE文件名的方法找到进程,并能切换进去,弹出窗体。即像WIN2K里面的进程管理器一样选中某一进程名,点“切换”就可以切换到进程里面并且把进程的主窗体弹到最上面?请各位大虾赐教!

解决方案 »

  1.   

    可以用EXE文件名找到对应的进程ID,这个我已做到了。不过就是不能实现像任务管理器一样,点击之后,弹出这个进程的主窗体。
    枚举子窗体能枚举出所有这个程序的窗体,但是找对应窗体的句柄时总找不到,也就弹不起。
    困惑中
      

  2.   

    procedure SwitchToThisWindow(hWnd:HWND;bRestore:Boolean);stdcall;external 'user32.dll';function AllowSetForegroundWindow( dwProcessId:DWORD): BOOL; stdcall;function ForceForegroundWindow(hWnd: THandle): BOOL;
    var
    hCurWnd: THandle;
    begin
      hCurWnd := GetForegroundWindow;
      AttachThreadInput(GetWindowThreadProcessId(hCurWnd, nil), GetCurrentThreadId, True);
      Result := SetForegroundWindow(hWnd);
    AttachThreadInput(GetWindowThreadProcessId(hCurWnd, nil), GetCurrentThreadId, False);end;
      

  3.   

    呵呵
    你看看进程管理器中列举的不都是每个进程主窗体的caption吗
    SetForegroundWindow(FindWindow(nil,pchar('进程切换怎么实现 - Tencent Explorer')));