Click here to Skip to main content
15,915,160 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am attempting to make one window stay in front of another window always.
The window on top has the Always On Top attribute set to True. When the window behind loses focus I am disabling the Always on top using

Win32.SetWindowPos(getChatHandle(pid), (IntPtr)Win32.SpecialWindowHandles.HWND_NOTOPMOST, 0, 0, 0, 0, Win32.SetWindowPosFlags.SWP_NOMOVE | Win32.SetWindowPosFlags.SWP_NOSIZE | Win32.SetWindowPosFlags.SWP_NOACTIVATE);
I tried replacing with the HWND_BOTTOM also, that has the tendency of hiding the window that should be on top.
The HWND_NOTOPMOST leaves the window on top, on top of the newly selected window witch is not desired.

I think WM_INACTIVE works fine the problem originated as described above.

Original question:

I have found the WM_ACTIVATE message, it receives wParam to indicate if it is active(also for mouse) or inactive.

The problem occurs on WA_INACTIVE it doesn't trigger as expected.

It occurs if another window is clicked in the taskbar, or a simple click on the window title section.

It doesn't occur if the user clicks another window client area, one of the system buttons (minimize, maximize, close), or clicks without releasing.

PS: I considered using the style changed, for when it loses the active window drawing style, that does trigger, unfortunately I haven't found out which flag determines that.

Thank you.
Posted
Updated 12-Aug-11 1:56am
v2

you can use the message WM_NCACTIVATE instead. If you change your window style you should call SetWindowPos(hwnd,0,0,0,0,0, SWP_NOZORDER| SWP_NOSIZE| SWP_NOMOVE| SWP_FRAMECHANGED);.
Regards.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Aug-11 1:13am    
Hard to say for 100%, it looks it should work, my 5.
--SA
I managed to find the solution, using SetWindowPos twice,
-first to set the window on HWND_BOTTOM
-second to set the window on HWND_TOP or above the window which I'm working with, depending on the GetForegroundWindow
Seems to work fine, needs more tunning.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900