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. When My program restore window from Tray, Why not bring to the top?

When My program restore window from Tray, Why not bring to the top?

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 3 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);
    ::BringWindowToTop(this->GetSafeHwnd());
    ::SetForegroundWindow(this->GetSafeHwnd());
    ::SetActiveWindow(this->GetSafeHwnd());
    }

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

    PJ ArendsP M 2 Replies 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);
      ::BringWindowToTop(this->GetSafeHwnd());
      ::SetForegroundWindow(this->GetSafeHwnd());
      ::SetActiveWindow(this->GetSafeHwnd());
      }

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

      PJ ArendsP Offline
      PJ ArendsP Offline
      PJ Arends
      wrote on last edited by
      #2

      Try using CWnd::SetWindowPos

      Within you lies the power for good; Use it!

      F 1 Reply Last reply
      0
      • PJ ArendsP PJ Arends

        Try using CWnd::SetWindowPos

        F Offline
        F Offline
        fantasy1215
        wrote on last edited by
        #3

        Thank for your reply first. SetWindowPos Not Working too. I even try to put them in different order. Please do me a favor.

        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);
          ::BringWindowToTop(this->GetSafeHwnd());
          ::SetForegroundWindow(this->GetSafeHwnd());
          ::SetActiveWindow(this->GetSafeHwnd());
          }

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

          M Offline
          M Offline
          Malli_S
          wrote on last edited by
          #4

          Did you check the return values for the above (Red colored) function calls ? The other possibility is that (if the functions return success), the window might have brought up to top, but your some other code might be changing the order again. Or, calling SetForegroundWindow() before displaying your context menu might help you.

          -Malli...! :rose:****

          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