为了限制程序只有一个实例运行。 第二次运行的时候我想把已经启动的那个窗口跳到顶层。 
但如果它是最小化状态。 就跳不出来了。 我该怎么做?已经尝试了 BringWindowToTop()  SetForegroundWindow()  SetActiveWindow() 等等。 
貌似都没有把这个最小化的窗口弹出来。 请教有做过这方面的朋友说一声。 多谢。 

解决方案 »

  1.   

    ShowWindow()先把窗口显示出来,因为最小化的窗口是隐藏的.
      

  2.   

    showwindow 
     setwindowpos
      

  3.   


    if(pMainWnd->IsIconic())
    pMainWnd->ShowWindow(SW_RESTORE);
    pMainWnd->SetActiveWindow();
    pMainWnd->BringWindowToTop();
    pMainWnd->SetForegroundWindow();
      

  4.   

    ::ShowWindow(hWndPrevious,SW_RESTORE);
    ::SetForegroundWindow(hWndPrevious);
    ::SetForegroundWindow(::GetLastActivePopup(hWndPrevious));

    这几句完全可以。
    就是只有托盘的也可以出来。
    要找到hWndPrevious
      

  5.   

    以前用过 ShowWindow() 
      

  6.   

    HWND hWnd = ::FindWindow(NULL, WINDOW_NAME);
    if(hWnd!=NULL)//already exist
    {

    if(::IsIconic(hWnd))
    ::ShowWindow(hWnd,SW_SHOWNORMAL);
    ::SetForegroundWindow(hWnd);
    ::SetActiveWindow(hWnd);

    }
    else//open a new process
    {
    CString str;
    char Path[MAX_PATH];
    GetModuleFileName(NULL,Path,MAX_PATH);
    *(strrchr(Path,'\\'))=0;
    str.Format("%s\\xx.exe",Path);
    ShellExecute(NULL, _T("open"), str, NULL,NULL, SW_SHOW);
    }
      

  7.   

    http://blog.csdn.net/raymonzhao/archive/2007/07/30/1716716.aspx
      

  8.   

    用 9 楼 joey_zoy 兄的方法解决好了。 哈哈。 
    谢谢joey_zoy。 
    谢谢大家。 
      

  9.   

    首先ShowWindow(SW_RESTORE), 然后SetForegroundWindow
      

  10.   

    ShowWindow(handle,SW_MAXIMIZE);
    SetForegroundWindow(handle);
      

  11.   

    if(::IsIconic(hWnd)) 
    ::ShowWindow(hWnd,SW_SHOWNORMAL); 
    ::SetForegroundWindow(hWnd); 
    ::SetActiveWindow(hWnd);