我想让线程以外的一个程序获得焦点,怎么弄,谢谢。

解决方案 »

  1.   

    我可以得到我切换线成的句柄,我有好些窗口,它们都不是在一个线程之内。
    发送sendkeys  "%{TAB}"是另外一回事。
      

  2.   

    哦原来如此。那就用这个:SetForegroundWindowThe SetForegroundWindow function puts the thread that created the specified window into the foreground and activates the window. Keyboard input is directed to the window, and various visual cues are changed for the user. The system assigns a slightly higher priority to the thread that created the foreground window than it does to other threads. BOOL SetForegroundWindow(
      HWND hWnd   // handle to window to bring to foreground
    );
      

  3.   

    SetForegroundWindow倒是可以。可是当焦点在另外一个线程上面的时候就切不回来了。要切到的窗体只是在那里闪个不停。(调试的时候可以,但是建立EXE文件执行就不成了。)
      

  4.   

    那就再来一下好了:BringWindowToTop
    The BringWindowToTop function brings the specified window to the top of the Z order. If the window is a top-level window, it is activated. If the window is a child window, the top-level parent window associated with the child window is activated. BOOL BringWindowToTop(
      HWND hWnd   // handle to window
    );
      

  5.   

    我两台机子都试了.系统:win2K
    winXP
      

  6.   

    怎么我试了就没问题呢?系统是 WIN98要不你不要用SetForegroundWindow , 直接用 BringWindowToTop
      

  7.   

    运行的时候你点其它线程的窗体,就切不回去了。直接用 BringWindowToTop 连闪都不闪,没反应。