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. Stay On Top - Advice Needed

Stay On Top - Advice Needed

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 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.
  • N Offline
    N Offline
    Norman Bates
    wrote on last edited by
    #1

    I have an application that allows users to select "stay on top"...however if another application presents a message box (crital error for example), I'd like to trap that and force that message box into the foreground...does anyone have advice on the best way to implement such a feature? TIA! Regards, Norm:confused:

    V H 2 Replies Last reply
    0
    • N Norman Bates

      I have an application that allows users to select "stay on top"...however if another application presents a message box (crital error for example), I'd like to trap that and force that message box into the foreground...does anyone have advice on the best way to implement such a feature? TIA! Regards, Norm:confused:

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      Interesting. How do you going to determine a normal message box from one that conveys "critical error?" Kuphryn

      1 Reply Last reply
      0
      • N Norman Bates

        I have an application that allows users to select "stay on top"...however if another application presents a message box (crital error for example), I'd like to trap that and force that message box into the foreground...does anyone have advice on the best way to implement such a feature? TIA! Regards, Norm:confused:

        H Offline
        H Offline
        Hosam Aly Mahmoud
        wrote on last edited by
        #3

        I hope I will not waste your time. I am a beginner and had never tried making my window on top, but I think that you do it by setting the window's style. I have an idea, but I do not know whether it is correct or applicable. If an application presents a message box, then your application will lose focus. May be you could handle WM_KILLFOCUS (or OnKillFocus()) and test the window getting focus for its style. If the style contains on top (and maybe message box style), put it somehow in front of your app (I think you would need to change your app's Z-order to make it after the message box). Hope this helps, and sorry for anything wrong I may have said.

        Hosam Aly Mahmoud

        H 1 Reply Last reply
        0
        • H Hosam Aly Mahmoud

          I hope I will not waste your time. I am a beginner and had never tried making my window on top, but I think that you do it by setting the window's style. I have an idea, but I do not know whether it is correct or applicable. If an application presents a message box, then your application will lose focus. May be you could handle WM_KILLFOCUS (or OnKillFocus()) and test the window getting focus for its style. If the style contains on top (and maybe message box style), put it somehow in front of your app (I think you would need to change your app's Z-order to make it after the message box). Hope this helps, and sorry for anything wrong I may have said.

          Hosam Aly Mahmoud

          H Offline
          H Offline
          Hosam Aly Mahmoud
          wrote on last edited by
          #4

          As I tried to look it up, I saw that you may be able to handle it as follows:

          case WM_KILLFOCUS:
          if ( wParam != 0 )
          {
          WINDOWINFO wi;
          GetWindowInfo( (HWND)wParam, &wi ); // sorry, did not check for errors
          if ( (wi.dwExStyle & WS_EX_TOPMOST) == WS_EX_TOPMOST )
          {
          SetWindowPos( (HWND)wParam, HWND_TOP,
          0, 0, 0, 0, // ignored
          SWP_NOMOVE | SWP_NOSIZE |
          SWP_NOOWNERZORDER | SWP_NOSENDCHANGING );
          }
          }
          return 0;

          Hope this helps (and hope I am not wrong!).

          Hosam Aly Mahmoud

          N 1 Reply Last reply
          0
          • H Hosam Aly Mahmoud

            As I tried to look it up, I saw that you may be able to handle it as follows:

            case WM_KILLFOCUS:
            if ( wParam != 0 )
            {
            WINDOWINFO wi;
            GetWindowInfo( (HWND)wParam, &wi ); // sorry, did not check for errors
            if ( (wi.dwExStyle & WS_EX_TOPMOST) == WS_EX_TOPMOST )
            {
            SetWindowPos( (HWND)wParam, HWND_TOP,
            0, 0, 0, 0, // ignored
            SWP_NOMOVE | SWP_NOSIZE |
            SWP_NOOWNERZORDER | SWP_NOSENDCHANGING );
            }
            }
            return 0;

            Hope this helps (and hope I am not wrong!).

            Hosam Aly Mahmoud

            N Offline
            N Offline
            Norman Bates
            wrote on last edited by
            #5

            Thanks, just what I needed! I'll check the wi.dwStyle for WS_POPUP or WS_POPUPWINDOW and if that window's RECT intersects my window will set the appropriate Z-Order for these two windows. best regards, norm

            H 1 Reply Last reply
            0
            • N Norman Bates

              Thanks, just what I needed! I'll check the wi.dwStyle for WS_POPUP or WS_POPUPWINDOW and if that window's RECT intersects my window will set the appropriate Z-Order for these two windows. best regards, norm

              H Offline
              H Offline
              Hosam Aly Mahmoud
              wrote on last edited by
              #6

              I am happy it worked! :-D

              Hosam Aly Mahmoud

              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