How to make an always-on-bottom window

Does anyone know how to make a "always at the bottom" of a window or a window attached to the desktop? It should receive focus and mouseclicks, but should remain at the bottom of the Z-order. It would be great if he remained on the desktop, even when the user did everything possible or showed the work on the desktop.

Both delphi and C # solutions (or partial solutions / hints) would be great.

+5
source share
3 answers

Warning . It has been suggested that you can accomplish this by calling SetParent and setting the window to be a child of the desktop. If you do this, you get Win32 Window Manager to combine the input desktop queue with your child window, which is bad - Raymond Chen explains why.

Also, keep in mind that calling SetWindowPos with HWND_BOTTOM is incomplete. You should do this when your window changes zorder. Refer to the WM_WINDOWPOSCHANGING event, view SWP_NOZORDER for more information.

+12
source

SetWindowPos can create AlwaysOnTop windows. Most likely, this can give the opposite result. Try something in this direction:

[DllImport("user32.dll")]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X,
   int Y, int cx, int cy, uint uFlags);


 public const uint SWP_NOSIZE          = 0x0001;
 public const uint SWP_NOMOVE          = 0x0002;
 public const uint SWP_NOACTIVATE      = 0x0010;
 public const int HWND_BOTTOM = 1;


SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);

Note:

  • ( , )
  • , , , show desktop . , , "" API.

: , , - - .

+7

Here is the solution for the ATL window. If you can apply for C #, this will help you.


BEGIN_MSG_MAP(...)
   ...
   MESSAGE_HANDLER(WM_WINDOWPOSCHANGING, OnWindowPosChanging)
   ...
END_MSG_MAP()

LRESULT OnWindowPosChanging(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)

{

    if (_bStayOnBottom)
    {
        auto pwpos = (WINDOWPOS*)lParam;

        pwpos->hwndInsertAfter = HWND_BOTTOM;

        pwpos->flags &= (~SWP_NOZORDER);

    }
    return 0;
}
+1
source

All Articles