[Lazarus] Obtaining screen geometry
Alexander Grau
alex at grauonline.de
Wed Jun 23 10:28:12 CEST 2010
Brad Campbell schrieb:
> G'day all,
>
> My application remembers where it was previously by doing a simple
> save of the current geometry. Top/Left/Width/Height. This appears to
> have worked well for a while now, but one of the users has just
> reported he ordinarily uses a dual head setup with my little app on
> the right hand screen.
>
> Recently after he had unplugged the right hand screen, the app
> proceeded to put itself there anyway (off the edge of the accessible
> desktop). Is there an easy way to detect the current screen width, so
> if I sense my geometry is going to be off the edge I can provide a
> sane default instead?
>
> This app runs on Win32, GTK2 & Carbon, so I assume the problem will
> manifest itself on all three, but in this instance it's running on a Mac.
>
> Regards,
> Brad
Hello Brad,
Below is how we center our main form when it is created (FormCreate) -
you can see from it, how we can ask for the screen width/height -
hopefully this will work with dual screen setups too!
Regards,
Alexander
// always keep space around the window for dock panels (OSX/Win7 etc.)
// this is the desired size (considering the space around the window)
w:=round(screen.width - 150);
h:=round(screen.height - 150);
// this calculates the best size keeping aspect
CalcResizeKeepAspect(1024, 768, w, h);
height:=max(600, h);
width:=max(800, w);
More information about the Lazarus
mailing list