We help IT Professionals succeed at work.

Forms

Wim_B
Wim_B asked
on
Hello,

Does anybody know how you can make a form, which is always on top or bottom of the screen.
When I execute another application maximized, this application or my application don't overlap each other, but the other application adapt to my application.

Greetings,

Wim
Comment
Watch Question

Tomas Helgi JohannssonDatabase Administrator / Software Engineer
CERTIFIED EXPERT

Commented:
Hi!

Set the FormStyle to fsStayOnTop.
That should do the trick.

Regards,
Tomas Helgi

Author

Commented:
When I set FormStyle to fsStayOnTop, other applications don't adapt to my application when they are maximized.
Example: The Windows Task Bar don't overlap other applications, but other applications adapt to the Windows Task Bar.

Do you know what I mean?

Commented:
Have a look at the Description for SPI_SETWORKAREA parameter to Function SystemParametersInfo;

In that helpfile i directed you to earlier.

Regards
//raidos
Here is what I used to accomodate taskbars. It adjusts the window to the work area available.

unit Main;

interface

uses
  Windows, Messages, Forms;

type
  TFormMain = class(TForm)
    procedure FormShow(Sender: TObject);
    procedure FormResize(Sender: TObject);

  private
    procedure WMSettingChange(var Msg: TMessage); message WM_SETTINGCHANGE;

  protected

  end;
var
  FormMain: TFormMain;

implementation

{$R *.DFM}

// returns available work area

function GetWindowsWorkArea: TRect;
begin
  SystemParametersInfo(SPI_GETWORKAREA, 0, @Result, 0);
end;


//respond to any change of work area dimensions during runtime...

procedure TFormMain.WMSettingChange(var Msg: TMessage);
var
  R: TRect;
begin
  if (Msg.WParam = SPI_SETWORKAREA) then
  begin
    R := GetWindowsWorkArea;
    SetBounds(R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top);
  end;
  Msg.Result := 0;
end;

//in an OnFormShow and OnResize event get available work area,
//because your form won't get WM_SETTINGCHANGE at startup...

procedure TFormMain.FormShow(Sender: TObject);
var
  R: TRect;
begin
  R := GetWindowsWorkArea;
  SetBounds(R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top);
end;

procedure TFormMain.FormResize(Sender: TObject);
var
  R: TRect;
begin
  R := GetWindowsWorkArea;
  SetBounds(R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top);
end;

end.

Commented:
I suggest to use Epsylon ideea .

Commented:
This asumes the current form is to be made "Topmost":

SetWindowPos(self.handle, HWND_TOPMOST ,0,0,self.Width,self.height,SWP_SHOWWINDOW);


Good luck!!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.