[Lazarus] Detecting desktop area size

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Detecting desktop area size

Bart
Hi,

Is there any (more or less) reliable way to detect the size of the
desktop (that is: on the active screen, the space a form can occupy so
that it will take in account the presence of a taskbar etc.)

I need something like this to keep a form that I create at runtime in
view on the desktop (it's initial size and widht/height) depend on the
contents it must display).

I know how to do it on Windows.
Linux (GTK2) and MAC would be nice.

Bart

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

zeljko
On Thursday 31 of March 2011 01:06:48 Bart wrote:

> Hi,
>
> Is there any (more or less) reliable way to detect the size of the
> desktop (that is: on the active screen, the space a form can occupy so
> that it will take in account the presence of a taskbar etc.)
>
> I need something like this to keep a form that I create at runtime in
> view on the desktop (it's initial size and widht/height) depend on the
> contents it must display).
>
> I know how to do it on Windows.
> Linux (GTK2) and MAC would be nice.

GetMonitorInfo(), GetSystemMetrics() SM_CXSCREEN,
SM_CYSCREEN,SM_CXVIRTUALSCREEN,SM_CYVIRTUALSCREEN doesn't help ?

>
> Bart
>
> --
> _______________________________________________
> Lazarus mailing list
> [hidden email]
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Paul Ishenin-2
In reply to this post by Bart
31.03.2011 7:06, Bart пишет:
> Is there any (more or less) reliable way to detect the size of the
> desktop (that is: on the active screen, the space a form can occupy so
> that it will take in account the presence of a taskbar etc.)
..
> I know how to do it on Windows.
> Linux (GTK2) and MAC would be nice.

TScreen.Monitors[i].WorkareaRect

Best regards,
Paul Ishenin


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Bart
In reply to this post by zeljko
On 3/31/11, zeljko <[hidden email]> wrote:
> GetMonitorInfo(), GetSystemMetrics() SM_CXSCREEN,
> SM_CYSCREEN,SM_CXVIRTUALSCREEN,SM_CYVIRTUALSCREEN doesn't help ?

On Windows GetSystemMetrics does return the size the (virtual) desktop
has, but it does not subtract the space occupied by the Windows
TaskBar (see: http://msdn.microsoft.com/en-us/library/ms724385(v=vs.85).aspx).
You have to use SystemparametersInfo(SPI_GETWORKAREA, 0, @WorkArea, 0
); with WorkArea being of type TRect;

Bart

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Bart
In reply to this post by Paul Ishenin-2
On 3/31/11, Paul Ishenin <[hidden email]> wrote:
>
> TScreen.Monitors[i].WorkareaRect

I'll take a look.

Bart

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Bart
In reply to this post by Paul Ishenin-2
On 3/31/11, Paul Ishenin <[hidden email]> wrote:
> TScreen.Monitors[i].WorkareaRect

This seems to work for Win and Linux/GTK2.

This raises yet another question though.
How do I know on which monitor my form is?
(I only have one monitor, so I cannot test this)

Bart

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Sven Barth
Am 31.03.2011 16:15, schrieb Bart:
> On 3/31/11, Paul Ishenin<[hidden email]>  wrote:
>> TScreen.Monitors[i].WorkareaRect
>
> This seems to work for Win and Linux/GTK2.
>
> This raises yet another question though.
> How do I know on which monitor my form is?
> (I only have one monitor, so I cannot test this)

What about this:

Screen.MonitorFromWindow(YourForm.Handle);

It returns a TMonitor.

Regards,
Sven

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Martin Frb
On 31/03/2011 15:35, Sven Barth wrote:

> Am 31.03.2011 16:15, schrieb Bart:
>> On 3/31/11, Paul Ishenin<[hidden email]>  wrote:
>>> TScreen.Monitors[i].WorkareaRect
>>
>> This seems to work for Win and Linux/GTK2.
>>
>> This raises yet another question though.
>> How do I know on which monitor my form is?
>> (I only have one monitor, so I cannot test this)
>
> What about this:
>
> Screen.MonitorFromWindow(YourForm.Handle);
>
> It returns a TMonitor.

Note that each monitor has it's own set of coordinates, which may be
negative.

eg 2 monitor left to right may be

m1 TopRight x: -1200, y:0
m2 TopRight x: 0, y:0

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Kjow
In reply to this post by Sven Barth
2011/3/31 Sven Barth <[hidden email]>:
> What about this:
>
> Screen.MonitorFromWindow(YourForm.Handle);
>
> It returns a TMonitor.
>
> Regards,
> Sven

Maybe a little OT, but is it possible to change screen resolution
(e.g. on a native 19200x1200 set 800x600) in a crossplatform way?
I need this for fullscreen apps (opengl in first).

Thanks!
Kjow

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Sven Barth
Am 31.03.2011 17:15, schrieb Kjow:

> 2011/3/31 Sven Barth<[hidden email]>:
>> What about this:
>>
>> Screen.MonitorFromWindow(YourForm.Handle);
>>
>> It returns a TMonitor.
>>
>> Regards,
>> Sven
>
> Maybe a little OT, but is it possible to change screen resolution
> (e.g. on a native 19200x1200 set 800x600) in a crossplatform way?
> I need this for fullscreen apps (opengl in first).

I'm not really confident in this, but I believe if you tell OpenGL to be
fullscreen in that or that resolution it will switch to that automatically.

Regards,
Sven

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Bart
In reply to this post by Sven Barth
On 3/31/11, Sven Barth <[hidden email]> wrote:
> What about this:
>
> Screen.MonitorFromWindow(YourForm.Handle);
>
> It returns a TMonitor.

Thanks.

Bart

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Reimar Grabowski
In reply to this post by Sven Barth
On Thu, 31 Mar 2011 17:32:10 +0200
Sven Barth <[hidden email]> wrote:

> I'm not really confident in this, but I believe if you tell OpenGL to be
> fullscreen in that or that resolution it will switch to that automatically.
No, it does not, because you don't give such information to OpenGL. Resolution switching or making windows fullscreen is not the task of OpenGL.

R.
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Paul Ishenin
In reply to this post by Bart
31.03.2011 22:15, Bart wrote:
> On 3/31/11, Paul Ishenin<[hidden email]>  wrote:
>> TScreen.Monitors[i].WorkareaRect
> This seems to work for Win and Linux/GTK2.
This was tested on OSX during the development too.
> This raises yet another question though.
> How do I know on which monitor my form is?
> (I only have one monitor, so I cannot test this)
Looks like search does not work on your PC anymore.

Look at TForm.Monitor property.

Best regards,
Paul Ishenin

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Bart
On 4/1/11, Paul Ishenin <[hidden email]> wrote:
> This was tested on OSX during the development too.

Nice.

> Looks like search does not work on your PC anymore.
(Well, it is slow on my 10 year old machine, but is still works most
of the time.
I also searched the forum and wiki.)

> Look at TForm.Monitor property.

Well, I did just that, but I just couldn't figure it out.
I finally used something like
Screen.MonitorFromPoint(ClientToSCreen(Self.BoundsRect.TopLeft)) to
get the monitor the form was currently on...

Just thougth to ask if someone had a simpler solution ;-)

Thanks to all for the help.

Bart

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Hans-Peter Diettrich
In reply to this post by Kjow
Kjow schrieb:

> Maybe a little OT, but is it possible to change screen resolution
> (e.g. on a native 19200x1200 set 800x600) in a crossplatform way?
> I need this for fullscreen apps (opengl in first).

Are you sure that you want to use an digital monitor (TFT...) in
anything but its native resolution? CRTs can be configured to a wide
range of resolutions, but nowadays flatscreens, with addressable pixels,
require soft-/hardware interpolation when abused for a different resolution.

DoDi


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Hans-Peter Diettrich
In reply to this post by Paul Ishenin
Paul Ishenin schrieb:

>> How do I know on which monitor my form is?
>> (I only have one monitor, so I cannot test this)
> Looks like search does not work on your PC anymore.
>
> Look at TForm.Monitor property.

A form/window actually can span multiple monitors.

DoDi


--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Kjow
In reply to this post by Hans-Peter Diettrich
2011/4/1 Hans-Peter Diettrich <[hidden email]>:
> Are you sure that you want to use an digital monitor (TFT...) in anything
> but its native resolution? CRTs can be configured to a wide range of
> resolutions, but nowadays flatscreens, with addressable pixels, require
> soft-/hardware interpolation when abused for a different resolution.
>
> DoDi

Yes, some 3D apps need to make compromises to have better performances
instead of best quality. :)

Kjow

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Detecting desktop area size

Paul Ishenin
In reply to this post by Hans-Peter Diettrich
01.04.2011 19:32, Hans-Peter Diettrich wrote:
> Paul Ishenin schrieb:
>
>>> How do I know on which monitor my form is?
>>> (I only have one monitor, so I cannot test this)
>> Looks like search does not work on your PC anymore.
>>
>> Look at TForm.Monitor property.
>
> A form/window actually can span multiple monitors.
Yes, and TForm.Monitor returns one where the biggest part of the form is
located.

Best regards,
Paul Ishenin

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus