Make your app to fill entire screen excluding taskbar  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 14/09/03

Tip accessed 813 times

 


Depending on the position and size of task bar, our application will have at its service a specific workspace in the screen that it should respect to don't step the own task bar.
We could get that available workspace by calling Window's API:


 var
   R: TRect;
 begin
   SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0);
   ...
   ...




With that, we could resize our form in the moment of its creation, by writing this on its OnCreate event:


 procedure TForm1.FormCreate(Sender: TObject);
 var
   R: TRect;
 begin
   SystemParametersInfo(SPI_GETWORKAREA, 0, @R, 0);
   SetBounds(R.Left, R.Top, R.Right-R.Left, R.Bottom-R.Top);
 end;



But, if the user wanted to resize the task bar or to put it in another place, our applicaction must be able to autoresize itself to fill the new available space.
We could do that by capturing the WM_SETTINGCHANGE message of Windows with this distinction Msg.Wparam=SPI_SETWORKAREA
So, let's capture that message...
We will put this line in the private area of the form.

 type
   TForm1 = class(TForm)
     procedure FormCreate(Sender: TObject);
   private
     { Private declarations }
     procedure WMSettingChange( var Msg: TMessage); message WM_SETTINGCHANGE;
   public
     { Public declarations }
   end;



And its declaration in the implementation of the form.


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





Thanks to Eduardo for the translation


Sent by: José Luis Montesinos Lüttecke



 type
   TForm1 = class(TForm)
     procedure FormCreate(Sender: TObject);
   private
     { Private declarations }
     procedure WMSettingChange( var Msg: TMessage); message WM_SETTINGCHANGE;
   public
     { Public declarations }
   end;





 type
   TForm1 = class(TForm)
     procedure FormCreate(Sender: TObject);
   private
     { Private declarations }
     procedure WMSettingChange( var Msg: TMessage); message WM_SETTINGCHANGE; override;
   public
     { Public declarations }
   end;





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

 end;






Updated at 14/09/2003