Board index » delphi » maximize main window under windows 95

maximize main window under windows 95

When I set WindowState = wsMaximized under NT in the main form of my
application, it opened correctly but not under Windows 95.
Sincerely
 

Re:maximize main window under windows 95


Hi Erez,

as far as I know, the only way to correctly maximize a form is to use the
API call SPI_GETWORKAREA, e.g.

var
x: pointer;
r: TRect;
begin
x := Addr(r);
SystemParametersInfo(SPI_GETWORKAREA, 0, x, 0);
Left := 0;
Width := r.Right;
     ....

HTH
Uwe

Erez <e...@monfort.co.il> schrieb in im Newsbeitrag:
80qvoq$dj...@forums.borland.com...

Quote
> When I set WindowState = wsMaximized under NT in the main form of my
> application, it opened correctly but not under Windows 95.

Re:maximize main window under windows 95


Quote
In article <80qvoq$dj...@forums.borland.com>, Erez wrote:
> When I set WindowState = wsMaximized under NT in the main form of my
> application, it opened correctly but not under Windows 95.

What does it do under Win95?

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:maximize main window under windows 95


On Tue, 16 Nov 1999 14:48:24 +0100, "Peter Below (TeamB)"

Quote
<100113.1...@compuXXserve.com> wrote:
>What does it do under Win95?

I have the same problem, the main form opens up with left and top not
being equal to 0. Its width and height are OK (same as desktop), but
it's off-setted towards the right and the bottom of the screen.

When you manually restore the window to it's design-size and then
maximize it again, it insists of going back to the same off-center
position.

I have a suspicion that this occurs when the MDI form has
position=poDefault and WindowState = wsMaximised, and when it is
itself is inherited from an ancestor that has different values in
these properties. I'm not sure though, still testing... I'll let you
know if I can confirm anything more about this (short in time at the
moment).

If anyone can help us, please do! Thanks...

Re:maximize main window under windows 95


Quote
In article <38317eae.31936582@pchemmis>, Bart Loosvelt wrote:
> I have the same problem, the main form opens up with left and top not
> being equal to 0. Its width and height are OK (same as desktop), but

That has a simple cause: you have set the forms Position property to
poScreenCenter or poDesktopCenter. That is not compatible with a
startup WindowsState wsMaximized since the centering is done *after*
the form has been maximized.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:maximize main window under windows 95


On Tue, 16 Nov 1999 19:43:51 +0100, "Peter Below (TeamB)"

Quote
<100113.1...@compuXXserve.com> wrote:
>That has a simple cause: you have set the forms Position property to
>poScreenCenter or poDesktopCenter. That is not compatible with a
>startup WindowsState wsMaximized since the centering is done *after*
>the form has been maximized.

No I have not, the position IS poDefault (I'm aware that these two
properties clash)! And anyway, if that was the cause then surely if I
would at run time restore the MDI form's size to its default
(not-maximized) size, and then maximize it again it should be
correctly maximized, no? Well, it isn't. Instead it just goes back to
its off-center position, about 1/3 down and to the right on the screen
diagonal. I will look for a reproducible description of the problem as
soon as I have time.

Best regards,
Bart Loosvelt

Re:maximize main window under windows 95


Quote
On Tue, 16 Nov 1999 09:13:08 +0200, "Erez" <e...@monfort.co.il> wrote:
>When I set WindowState = wsMaximized under NT in the main form of my
>application, it opened correctly but not under Windows 95.
>Sincerely

I found a workaround that will work in NT and on Win95 according to
our tests. First, you must override the WndProc of your form:

interface

TMyMDIForm = class(TForm)
private
  { Private declarations }
protected
  { Protected declarations}
  procedure WndProc(var Message: TMessage); override;
public
  { Public declarations }
end;

(This will affect performance somewhat... this procedure will be run
for each windows event that your window receives but it's probably a
negligable slowdown - delphi uses WndProc as well you know...)

Then, you declare the WndProc as follows in the implementation
section:

procedure TMyMDIForm.WndProc(var Message: TMessage);
var
  Rec: TRect;
  Borderwidth: integer;
begin
  inherited;
  //Patch that will correctly maximize the MDI form, on Win95
  //as well as WinNT (almost certainly Delphi bug).
  if (Message.Msg = WM_SIZE) and (Message.wParam = SIZE_MAXIMIZED)
then begin
    SystemParametersInfo(SPI_GETBORDER, 0, @Borderwidth, 0);
    SystemParametersInfo(SPI_GETWORKAREA, 0, @Rec, 0);
    Self.Left := Rec.Left - Borderwidth - 3;
    Self.Top := Rec.Top - Borderwidth - 3;
  end;
end;

I don't know what's the origin of the '3' constant in the calculation
of the left and top parameters but the above workaround will function
regardless of the border size that has been set on the machine your
program runs on.

Many thanks Uwe for pointing us in the right direction.

TeamB I'm quite sure it is a bug in Delphi! We did some tests and
never were able to reproduce it but it _was_ consistently there in the
project in which we didn't want it ;-). Maybe tell Borland they should
check how they compute the Left and Top properties for maximized MDI
forms. Their Width and Height seem ok (probably because these come
packed in with the WM_SIZE event) but they seem to mess up the
calculation of the Left and Top in some weird cases.

Best regards,
Bart

Re:maximize main window under windows 95


Quote
In article <38325dbb.2596984@pchemmis>, Bart Loosvelt wrote:
> No I have not, the position IS poDefault

Curious. Do you use the Constraints property of the form or do you
handle the WM_GETMINMAXINFO message?

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Re:maximize main window under windows 95


On Wed, 17 Nov 1999 18:47:13 +0100, "Peter Below (TeamB)"

Quote
<100113.1...@compuXXserve.com> wrote:
>Curious. Do you use the Constraints property of the form or do you
>handle the WM_GETMINMAXINFO message?

Indeed we do handle WM_GETMINMAXINFO! It's a leftover from code we had
written before Delphi 4 introduced the Constraints property. Could
that cause these problems? I will try to remove it and see what
happens.

Best regards,
Bart

Re:maximize main window under windows 95


Quote
In article <3833a857.843653@pchemmis>, Bart Loosvelt wrote:
> Indeed we do handle WM_GETMINMAXINFO! It's a leftover from code we had
> written before Delphi 4 introduced the Constraints property. Could
> that cause these problems?

Certainly, it allows you to modify the size and position of the
maximized window.

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Other Threads