简体   繁体   中英

Correct way to maximize form in delphi (without caption)

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.

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. Eg

with Screen.WorkAreaRect do
  Form1.SetBounds(Left, Top, Right - Left, Bottom - Top);

One additional hint. The task bar can also be located on the right or the left of the screen (not only top and bottom). So you must additionally figure out where the task bar is.

I would suggest you look into the Delphi implementation of SetWidnowState. In Delphi7 it is this part of the code:

procedure TCustomForm.SetWindowState(Value: TWindowState);
const
  ShowCommands: array[TWindowState] of Integer =
    (SW_SHOWNORMAL, SW_MINIMIZE, SW_SHOWMAXIMIZED);
begin
  if FWindowState <> Value then
  begin
    FWindowState := Value;
    if not (csDesigning in ComponentState) and Showing then
      ShowWindow(Handle, ShowCommands[Value]);
  end;
end;

The ShowWindow is a Win32 library call:

function ShowWindow; external user32 name 'ShowWindow';

where user32 = 'user32.dll'; if I'm not mistaking. So dig into this library, maybe there is some info of TaskBar somewhere.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM