SetForegroundWindow等不起作用!

解决方案 »

  1.   

    试试下面的代码,应该可以 CString strCaption = _T("WhatYouWant");
    CWnd* pwndFirst = CWnd::FindWindow(NULL, strCaption);
    if (pwndFirst)
    {
    CWnd* pwndPopup = pwndFirst->GetLastActivePopup();
    pwndFirst->SetForegroundWindow();
    pwndFirst->ShowWindow(SW_SHOWNORMAL);
    if (pwndFirst != pwndPopup)
    pwndPopup->SetForegroundWindow();
    return FALSE;
    }
      

  2.   

    楼上的代码是可以的。CString strCaption = _T("WhatYouWant");
    CWnd* pwndFirst = CWnd::FindWindow(NULL, strCaption);
    if (pwndFirst)
    {
    CWnd* pwndPopup = pwndFirst->GetLastActivePopup();
    pwndFirst->SetForegroundWindow();
    pwndFirst->ShowWindow(SW_SHOWNORMAL);
    if (pwndFirst != pwndPopup)
    pwndPopup->SetForegroundWindow();
    return FALSE;
    }
      

  3.   

    setforegroundwindow对Dialog不怎么灵,怪怪的,开始我也正不明白
      

  4.   


    ::SetWindowPos(this->m_hWnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
    ::SetWindowPos(this->m_hWnd, HWND_NOTOPMOST , 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
      

  5.   

    HWND tmphwnd=GetForegroundWindow();
    if(AttachThreadInput(GetCurrentThreadId(),GetWindowThreadProcessId(tmphwnd,NULL),1))
    {
      SetActiveWindow((HWND)h);
      AttachThreadInput(GetCurrentThreadId(),GetWindowThreadProcessId(tmphwnd,NULL),0);
    }