tags:

views:

56

answers:

1

This question is more academic than practical and doesn't involve any one specific language. For the sake of discussion, we'll use Win32 API.

What is the most appropriate way to create a window with the following behavior goals:

  • Z-Order is lower than every other window except the desktop surface.
  • Cannot be made to appear on a higher z-order than other windows through mouse or keyboard clicks.

Assumption may be made that the window is borderless.

+2  A: 

There are two basic approaches here :-

  1. make your window the 'child' of the desktop.
  2. make your window simply refuse to accept focus or activation :-

The wonder of the windows window manager is that there isn't one. Rather, there is an appearance of a window manager as a result of the emergent behavior of all the windows in the system - namely how they react to messages - which in 99% of cases is handeld by DefWindowProc.

Which means that you can subvert a lot of normal window manager type behaviour by handling messages before DefWindowProc. If you create a window, and position it using the relevent flags at the bottom of the z-order with SetWindowPos, and then handle messages like WM_WINDOWPOSCHANGING, you can ensure that your window never receives activation or focus and always - even when other apps call SetWindowPos - always has the z-bottom flag set.

both approaches are problematic as its very difficult to find out what the desktop window is. GetDesktopWindow returns a handle to a window that is only ever visible if explorer crashes. The rest of the time, the visible desktop is a window created by explorer - ultimately a syslistview control. Spy++ + Findwindow will get you a handle to the window you want to be above.

Chris Becke