Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable form rising to the top

I want a form that when I set at the bottom of the z-order it stays there. I tried:

SetWindowPos(Handle,HWND_BOTTOM,Left,Top,Width,Height,SWP_NOZORDER);

and when I overlap it with some other apps it stays at the bottom as I need. However when I click on it, it rises to the top. I then tried:

SetWindowPos(Handle, HWND_BOTTOM, Left, Top, Width, Height,
             SWP_NOACTIVATE or SWP_NOZORDER);

and various other switches from this website... http://msdn.microsoft.com/en-us/library/ms633545.aspx

But it still rises to the top.

like image 937
user983145 Avatar asked Dec 28 '22 10:12

user983145


1 Answers

SetWindowPos sets the position of a window only when it is called, it does not establish a state. Handling WM_WINDOWPOSCHANGING is the correct way to do this:

While this message is being processed, modifying any of the values in WINDOWPOS affects the window's new size, position, or place in the Z order. An application can prevent changes to the window by setting or clearing the appropriate bits in the flags member of WINDOWPOS.


type
  TForm1 = class(TForm)
    ..
  private
    procedure WindowPosChanging(var Msg: TWMWindowPosMsg);
        message WM_WINDOWPOSCHANGING;
  end;

..

procedure TForm1.WindowPosChanging(var Msg: TWMWindowPosMsg);
begin
  if Msg.WindowPos.flags and SWP_NOZORDER = 0 then
    Msg.WindowPos.hwndInsertAfter := HWND_BOTTOM;
  inherited;
end;
like image 103
Sertac Akyuz Avatar answered Dec 29 '22 23:12

Sertac Akyuz