How to block a window ?
-
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.
-
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.
Only one window can be the active window. We can't activate another window but still have the first active - That would mean there would be two active windows. What are you trying to achieve? Steve
-
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.
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!
-
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!
This is possible and actually very easy. See http://blogs.msdn.com/oldnewthing/archive/2003/10/29/55479.aspx Steve
-
This is possible and actually very easy. See http://blogs.msdn.com/oldnewthing/archive/2003/10/29/55479.aspx Steve
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
-
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.
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] -
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
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 aWH_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 -
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] -
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.
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 -
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
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 itsWndProc
. 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 theWPARAM
- it isFALSE
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 callingSetWindowPos( 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 -
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.
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 itsWndProc
. 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 theWPARAM
- it isFALSE
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 callingSetWindowPos( 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 -
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 itsWndProc
. 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 theWPARAM
- it isFALSE
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 callingSetWindowPos( 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 BiswasI 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