Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. My unsolved "Restore window" question, help me plz!

My unsolved "Restore window" question, help me plz!

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fantasy1215
    wrote on last edited by
    #1

    When right click my tray icon, show the menu, And there is a menu item "Restore window". When click this menu item, it should restore window. My code implement "Restore window" below:

    void CWinSearchDlg::OnTrayRestoreWnd()
    {
    DestroyTray();
    ShowWindow(SW_SHOW);
    if (CWnd::GetActiveWindow() != this)
    {
    SetActiveWindow();
    AfxMessageBox(_T("SetActiveWindow"));
    }
    else
    {
    AfxMessageBox(_T("no SetActiveWindow")); //it goes here
    }
    BOOL bRet = FALSE;
    bRet = SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
    if (bRet)
    AfxMessageBox(_T("SetWindowPos true"));//it goes here
    else
    AfxMessageBox(_T("SetWindowPos false"));

    bRet = FALSE;
    bRet = SetForegroundWindow();
    if (bRet)
    	AfxMessageBox(\_T("true SetForegroundWindow"));//it goes here
    else
    	AfxMessageBox(\_T("false SetForegroundWindow"));
    
    bRet = FALSE;
    bRet = ::BringWindowToTop(this->GetSafeHwnd());
    if (bRet)
    	AfxMessageBox(\_T("BringWindowToTop true"));//it goes here
    else
    	AfxMessageBox(\_T("BringWindowToTop false"));
    

    }

    I've tried the code in blue font, but when restore the window, It doesn't bring to the top. Please give me a sign!

    I 1 Reply Last reply
    0
    • F fantasy1215

      When right click my tray icon, show the menu, And there is a menu item "Restore window". When click this menu item, it should restore window. My code implement "Restore window" below:

      void CWinSearchDlg::OnTrayRestoreWnd()
      {
      DestroyTray();
      ShowWindow(SW_SHOW);
      if (CWnd::GetActiveWindow() != this)
      {
      SetActiveWindow();
      AfxMessageBox(_T("SetActiveWindow"));
      }
      else
      {
      AfxMessageBox(_T("no SetActiveWindow")); //it goes here
      }
      BOOL bRet = FALSE;
      bRet = SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
      if (bRet)
      AfxMessageBox(_T("SetWindowPos true"));//it goes here
      else
      AfxMessageBox(_T("SetWindowPos false"));

      bRet = FALSE;
      bRet = SetForegroundWindow();
      if (bRet)
      	AfxMessageBox(\_T("true SetForegroundWindow"));//it goes here
      else
      	AfxMessageBox(\_T("false SetForegroundWindow"));
      
      bRet = FALSE;
      bRet = ::BringWindowToTop(this->GetSafeHwnd());
      if (bRet)
      	AfxMessageBox(\_T("BringWindowToTop true"));//it goes here
      else
      	AfxMessageBox(\_T("BringWindowToTop false"));
      

      }

      I've tried the code in blue font, but when restore the window, It doesn't bring to the top. Please give me a sign!

      I Offline
      I Offline
      Iain Clarke Warrior Programmer
      wrote on last edited by
      #2

      Without digging through that (I'm lazy), I don't see any ShowWindow command. How did you hide the dialog in the first place? There are tray program examples aplenty on CP, so you may be able to see how they did it. Iain.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups