::SetWindowPos(ydh_hwnd[T_hwnd],HWND_BOTTOM,0,0,0,0,SWP_SHOWWINDOW   |   SWP_NOMOVE   |   SWP_NOSIZE);
::SetWindowPos(ydh_hwnd[T_hwnd],HWND_TOP,400,150,600,500,SWP_SHOWWINDOW );
                 //这两个一起使用也不行. ::SetForegroundWindow(ydh_hwnd[T_hwnd]);
::BringWindowToTop(ydh_hwnd[T_hwnd]);
::SetFocus(ydh_hwnd[T_hwnd]);   
::SendMessage(ydh_hwnd[T_hwnd],WM_SHOWWINDOW,0,0); ydh_hwnd 数组,保存了当前所有应用程序的句柄, 以上方法都用过了. 有部分可以成功切换. 有部分不行(窗口显示不出来,但是被窗口激活了的) , 然后我点击windows"开始"的任务栏 来切换窗口 都可以顺利切换(请问是windows是用什么语句呢,为什么这么有效) .  奇怪的是用"开始"的任务栏切换过的窗口, 又可以用我的程序来顺利切换了.

解决方案 »

  1.   

    SetForegroundWindow必须在特定情况下才有用 不知道是不是因为这个原因:
    Starting with Microsoft Windows 98 and Windows 2000, the system restricts which processes can set the foreground window. A process can set the foreground window only if one of the following conditions is true: 
    The process is the foreground process. 
    The process was started by the foreground process. 
    The process received the last input event. 
    There is no foreground process. 
    The foreground process is being debugged. 
    The foreground is not locked (see LockSetForegroundWindow). 
    The foreground lock time-out has expired (see SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo). 
    Windows 2000/XP: No menus are active. 
    试试LockSetForegroundWindow()看
      

  2.   

    对于已经最小化的窗口,应该用ShowWindow( SW_RESTORE )来恢复;对于没有最小化的,用ShowWindow( SW_SHOW )即可;所以应该先判断一下该窗口是否已经最小化。获取窗口状态可以用GetWindowPlacement函数。
      

  3.   

    自己解决了. 原来这样就可以了 ::SetForegroundWindow(ydh_hwnd[T_hwnd]);
    ::ShowWindow(ydh_hwnd[T_hwnd],SW_SHOWNORMAL);