Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way to maximize form in delphi (without caption)

Tags:

winapi

delphi

I have a form without caption, using on double click to maximize : Code looks like this:

procedure xxxxxx; 
begin
    if Form1.WindowState=wsNormal then
       begin
        Form1.WindowState:=wsMaximized;
        Form1.SetBounds(0,0,screen.Width,screen.Height-getHeightOfTaskBar);
       end
       else
       begin
         Form1.WindowState:=wsNormal;
       end;

       ShowTrayWindow;
end;
function getHeightOfTaskBar : integer;
var hTaskBar:HWND;
    rect : TRect;
begin
     hTaskbar := FindWindow('Shell_TrayWnd', Nil );
     if hTaskBar<>0 then
        GetWindowRect(hTaskBar, rect);

     Result:=rect.bottom - rect.top;
end;

This works good, except that I have to figure out where is task bar to reset SetBounds ...

What is the correct way to do this?

Thanks.

like image 482
Irfan Mulic Avatar asked Dec 19 '08 06:12

Irfan Mulic


1 Answers

Sounds okay but like Drejc pointed out, the taskbar can appear anywhere, so too could additional docked sidebars like Google Desktop, Winamp, etc.

Instead perhaps use something like Screen.WorkAreaRect to get the client area of the screen. E.g.

with Screen.WorkAreaRect do
  Form1.SetBounds(Left, Top, Right - Left, Bottom - Top);
like image 107
CodeAndCats Avatar answered Nov 06 '22 11:11

CodeAndCats