tags:

views:

2478

answers:

3

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.

A: 

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.

Drejc
+5  A: 

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);
Ben Daniel
A: 

You might find some of the answers to this question relevant:

http://stackoverflow.com/questions/14451/what-is-the-best-way-to-make-a-delphi-application-completely-full-screen

Roddy