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. How to block a window ?

How to block a window ?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
12 Posts 6 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.
  • L leenmie

    We can set a window "always on top" by using SetWindowPos() with HWND_TOPMOST. I wonder is there a way to make a window is not only "always on top" but also "always activated". It means that window will be always activated, but we will still be able to activate another windows. Plz help me solve this problem. Tnx alot.

    R Offline
    R Offline
    Roger Stoltz
    wrote on last edited by
    #3

    What do you mean by "activated"? Usually "activated" means that the window has the input focus which means that no other window will get keyboard input for instance. Is this really what you want? (I don't think so, but that's just me...) Only one window at any given time can be "active" in that sense. Perhaps you mean that the title bar of the window should still look as if the window is "active" even if another window has got the input focus. That's another thing and should be possible, but I don't have a solution for it. However, I don't consider it very user friendly since the user will have multiple windows that seems to have input focus. What is it you want to accomplish? -- Roger


    It's supposed to be hard, otherwise anybody could do it!

    S 1 Reply Last reply
    0
    • R Roger Stoltz

      What do you mean by "activated"? Usually "activated" means that the window has the input focus which means that no other window will get keyboard input for instance. Is this really what you want? (I don't think so, but that's just me...) Only one window at any given time can be "active" in that sense. Perhaps you mean that the title bar of the window should still look as if the window is "active" even if another window has got the input focus. That's another thing and should be possible, but I don't have a solution for it. However, I don't consider it very user friendly since the user will have multiple windows that seems to have input focus. What is it you want to accomplish? -- Roger


      It's supposed to be hard, otherwise anybody could do it!

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #4

      This is possible and actually very easy. See http://blogs.msdn.com/oldnewthing/archive/2003/10/29/55479.aspx Steve

      L 1 Reply Last reply
      0
      • S Stephen Hewitt

        This is possible and actually very easy. See http://blogs.msdn.com/oldnewthing/archive/2003/10/29/55479.aspx Steve

        L Offline
        L Offline
        leenmie
        wrote on last edited by
        #5

        Tnx alot. Two windows cant be activated. But could we make a window always activated ??? I try to use PostMessage() with WM_MOUSEACTIVATE in a while loop but it make my program run very slowly and the result is not always as I want. Anyone have a solution ? -- modified at 6:45 Friday 13th January, 2006

        S K 2 Replies Last reply
        0
        • L leenmie

          We can set a window "always on top" by using SetWindowPos() with HWND_TOPMOST. I wonder is there a way to make a window is not only "always on top" but also "always activated". It means that window will be always activated, but we will still be able to activate another windows. Plz help me solve this problem. Tnx alot.

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #6

          overload the WM_KILLFOCUS of your windows, and then, call WM_SETFOCUS from within... this way, whenever the window looses the focus, it gets it back


          TOXCCT >>> GEII power
          [toxcct][VisualCalc 2.20][VisualCalc 3.0]

          L 1 Reply Last reply
          0
          • L leenmie

            Tnx alot. Two windows cant be activated. But could we make a window always activated ??? I try to use PostMessage() with WM_MOUSEACTIVATE in a while loop but it make my program run very slowly and the result is not always as I want. Anyone have a solution ? -- modified at 6:45 Friday 13th January, 2006

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #7

            Do you want your window to be the only activated window in the whole system or just within your application? Either way you could use the SetWindowsHookEx API to install a WH_CBT hook to do this. If it's system wide the hook procudure will have to live in a DLL further complicating you life. Steve

            1 Reply Last reply
            0
            • T toxcct

              overload the WM_KILLFOCUS of your windows, and then, call WM_SETFOCUS from within... this way, whenever the window looses the focus, it gets it back


              TOXCCT >>> GEII power
              [toxcct][VisualCalc 2.20][VisualCalc 3.0]

              L Offline
              L Offline
              leenmie
              wrote on last edited by
              #8

              In function WindowProc(), I switch msg WM_KILLFOCUS and then, I PostMessage WM_SETFOCUS (i try SetFocus() function too), but it cant keep the focus for my window. When I click another windows, my window lose the focus. Is there anything wrong ?

              1 Reply Last reply
              0
              • L leenmie

                We can set a window "always on top" by using SetWindowPos() with HWND_TOPMOST. I wonder is there a way to make a window is not only "always on top" but also "always activated". It means that window will be always activated, but we will still be able to activate another windows. Plz help me solve this problem. Tnx alot.

                F Offline
                F Offline
                FarPointer
                wrote on last edited by
                #9

                Map the WM_NCACTIVATE ,and in that set any of your child controls to set focus ;- void CTestDlg::OnNcActivate( BOOL bActive ) { int a; c_edit.SetFocus ();//c_edit is a control variable of edit control ::SendMessage (this->m_hWnd ,WM_ACTIVATE,0,0); //CDialog::OnNcActivate(true ); } -- modified at 9:50 Friday 13th January, 2006

                1 Reply Last reply
                0
                • L leenmie

                  Tnx alot. Two windows cant be activated. But could we make a window always activated ??? I try to use PostMessage() with WM_MOUSEACTIVATE in a while loop but it make my program run very slowly and the result is not always as I want. Anyone have a solution ? -- modified at 6:45 Friday 13th January, 2006

                  K Offline
                  K Offline
                  Koushik Biswas
                  wrote on last edited by
                  #10

                  I am assuming you are writing the code for the window you want to keep always activated. If yes, you can handle "WM_ACTIVATEAPP" in its WndProc. This message is sent to any window that is about to lose focus or to gain focus, the difference between losing and gaining focus is the WPARAM - it is FALSE if it islosing focus. Thus, you can use that message to trap the fact that you are about to lose focus (some other window is trying to come on top). Once you sense that, you can take corrective action by calling SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); ShowWindow( hWnd, SW_SHOWNORMAL ); That should return the window to active state - quite rude to other windows though! Now, assuming that you are NOT directly writing the code of this window, you can write a small hidden program that will always run in the background, and constantly call GetForegroundWindow() [see here[^]] or GetTopWindow() [see here[^]], and compare the HWND value it gets with the handle of your window. To do that, it must first get the HWND handle of your window, which it can initially get by calling FindWindow(). If it ever sees that the top window is something else than your window, it can call the same functions as described above with the handle of your window to bring it on top again. Disclaimer - I have not tried this actually. Let me know if this works. Koushik Biswas -- modified at 19:55 Friday 13th January, 2006

                  1 Reply Last reply
                  0
                  • L leenmie

                    We can set a window "always on top" by using SetWindowPos() with HWND_TOPMOST. I wonder is there a way to make a window is not only "always on top" but also "always activated". It means that window will be always activated, but we will still be able to activate another windows. Plz help me solve this problem. Tnx alot.

                    K Offline
                    K Offline
                    Koushik Biswas
                    wrote on last edited by
                    #11

                    I am assuming you are writing the code for the window you want to keep always activated. If yes, you can handle "WM_ACTIVATEAPP" in its WndProc. This message is sent to any window that is about to lose focus or to gain focus, the difference between losing and gaining focus is the WPARAM - it is FALSE if it islosing focus. Thus, you can use that message to trap the fact that you are about to lose focus (some other window is trying to come on top). Once you sense that, you can take corrective action by calling SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); ShowWindow( hWnd, SW_SHOWNORMAL ); That should return the window to active state - quite rude to other windows though! Now, assuming that you are NOT directly writing the code of this window, you can write a small hidden program that will always run in the background, and constantly call GetForegroundWindow() [see here[^]] or GetTopWindow() [see here[^]], and compare the HWND value it gets with the handle of your window. To do that, it must first get the HWND handle of your window, which it can initially get by calling FindWindow(). If it ever sees that the top window is something else than your window, it can call the same functions as described above with the handle of your window to bring it on top again. Disclaimer - I have not tried this actually. Let me know if this works. Koushik Biswas

                    L 1 Reply Last reply
                    0
                    • K Koushik Biswas

                      I am assuming you are writing the code for the window you want to keep always activated. If yes, you can handle "WM_ACTIVATEAPP" in its WndProc. This message is sent to any window that is about to lose focus or to gain focus, the difference between losing and gaining focus is the WPARAM - it is FALSE if it islosing focus. Thus, you can use that message to trap the fact that you are about to lose focus (some other window is trying to come on top). Once you sense that, you can take corrective action by calling SetWindowPos( hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); ShowWindow( hWnd, SW_SHOWNORMAL ); That should return the window to active state - quite rude to other windows though! Now, assuming that you are NOT directly writing the code of this window, you can write a small hidden program that will always run in the background, and constantly call GetForegroundWindow() [see here[^]] or GetTopWindow() [see here[^]], and compare the HWND value it gets with the handle of your window. To do that, it must first get the HWND handle of your window, which it can initially get by calling FindWindow(). If it ever sees that the top window is something else than your window, it can call the same functions as described above with the handle of your window to bring it on top again. Disclaimer - I have not tried this actually. Let me know if this works. Koushik Biswas

                      L Offline
                      L Offline
                      leenmie
                      wrote on last edited by
                      #12

                      I try the first, it make the window "always on top", not "always activated". The second, I think it will not succeed. Because it is not really "always activated" : another window will be activated (by a click ex.), and then, we activate the window we want. That's what you do, but it's not the achieve. Tnx alot. -- modified at 21:48 Friday 13th January, 2006

                      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