hwnd是我当前程序的子进程的主窗口句柄,我在父进程的主框架被激活时调用SetWindowPos(hwnd,HWND_TOPMOST,....),SetForegroundWindow(hwnd)的时候子进程窗口并没有被调到最前,不知道有没有大侠遇到过这样的情况,请帮忙指点迷津

解决方案 »

  1.   

    光用SetForegroundWindow是不能把窗口提到最前面的。下面的代码是把自己的窗口提到最前面,换一下窗口句柄就应该可以了。        DWORD ID1,ID2;
            ID1=::GetWindowThreadProcessId(::GetForegroundWindow(),NULL);
            ID2=::GetWindowThreadProcessId(m_hWnd,NULL);    
            ::AttachThreadInput(ID1,ID2,TRUE);
            ::SetForegroundWindow(m_hWnd);
            ::AttachThreadInput(ID1,ID2,FALSE);
      

  2.   

    使用SetWindowPos,接着使用SetForegroundWindow,有些时候必须这样才行:
    SetWindowPos(hWnd,HWND_TOP,//MOST,
                 wWindowLeft,wWindowTop,0,0,
       SWP_NOSIZE|SWP_SHOWWINDOW);
    SetForegroundWindow(hWnd);
    不行再加上SetFocus( hWnd );
    如果要把其它进程的窗口带到前台需要调用 AttachThreadInput, 
    下面的内容来自 vckbase---------------------
    如何在2K/xp下使窗口获取焦点
    在2K/XP下我们可以用 AttachThreadInput 和SetForegroundWindow来有效的获取焦点。//捕捉并设置当前焦点窗口为我们的窗口
    AttachThreadInput(
        GetWindowThreadProcessId(
            ::GetForegroundWindow(),NULL),
        GetCurrentThreadId(),TRUE);//置我们的为焦点窗口
    SetForegroundWindow();
    SetFocus(); //释放thread
    AttachThreadInput(
        GetWindowThreadProcessId(
            ::GetForegroundWindow(),NULL),
        GetCurrentThreadId(),FALSE);
      

  3.   

    SetForegroundWindow只能使窗口获得焦点,并不能弹到最前面
    BringtoTop
      

  4.   

    SetWindowPos(&wndBottom,0,0,0,0,SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);//先放到最后
    SetWindowPos(&wndTop,0,0,0,0,SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE);//在调就可以了