Recent

Author Topic: how to detect a change in screen resolution in lazarus  (Read 10485 times)

Blue1987

  • Full Member
  • ***
  • Posts: 165
how to detect a change in screen resolution in lazarus
« on: January 06, 2011, 07:04:07 pm »
in order to detect a displaychange in delphi I can create a message handler to trap the windows WM_DISPLAYCHANGE message...

something like...
**************************************************
type
    TForm1 = class(TForm)
...
    private
      procedure DetectDisplayChange(var Message:TMessage) ; message WM_DISPLAYCHANGE;
 ...
 procedure
  TForm1.DetectDisplayChange(var Message: TMessage) ;
 begin
    ShowMessage('hello world!') ;
    inherited;
 end;

**************************************************

I was wondering if there was an equivalent multi-platform procedure in Lazarus... (maybe using lmessages....)


thank you,
Paolo


typo

  • Hero Member
  • *****
  • Posts: 3051
Re: how to detect a change in screen resolution in lazarus
« Reply #1 on: January 06, 2011, 07:27:59 pm »
Well, you could simply verify Screen.Width and Screen.Height when your program starts.

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: how to detect a change in screen resolution in lazarus
« Reply #2 on: January 06, 2011, 07:32:47 pm »
Well, you could simply verify Screen.Width and Screen.Height when your program starts.

i.e. , using a Ttimer with interval 1 and checking every millisec?
(I need to be allerted when there is a change in the display resolution)
« Last Edit: January 06, 2011, 07:34:58 pm by Blue1987 »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: how to detect a change in screen resolution in lazarus
« Reply #3 on: January 06, 2011, 07:34:08 pm »
When your program starts, for instance on the OnShow event handler.
« Last Edit: January 06, 2011, 07:38:29 pm by typo »

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: how to detect a change in screen resolution in lazarus
« Reply #4 on: January 06, 2011, 07:40:02 pm »
When your program starts. for instance on the OnShow event handler.

ehr... I maybe do not understand your answer...

suppose the initial resolution is 1024x768 when the application starts.
suppose now that while working, the user changes the display resolution to 800x600...
I would like to be informed that the resolution has changed, so that I can resize some components...

I can save the initial values of screen.width and screen.height when the application starts (i.e. onFormCreate) and then check every millisec if it keeps being the same or it has changed...
... but I do not think it is a good solution to my problem.

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: how to detect a change in screen resolution in lazarus
« Reply #5 on: January 06, 2011, 07:43:58 pm »
You can use OnActivate event handler too and other events. This solution would be cross-platform.

Do you expect the user changes screen resolution while using your program?
« Last Edit: January 06, 2011, 07:46:41 pm by typo »

mas steindorff

  • Hero Member
  • *****
  • Posts: 554
Re: how to detect a change in screen resolution in lazarus
« Reply #6 on: January 06, 2011, 07:48:30 pm »
I can save the initial values of screen.width and screen.height when the application starts (i.e. onFormCreate) and then check every millisec if it keeps being the same or it has changed...
... but I do not think it is a good solution to my problem.
Your right about evey millisec, but the screen interfaces with the slowest element of the system... the human.  if it is busy changing the res, then having a 1 to 5 second delay probably will not be that much of a problem as it's eyes may take that long to find the program again. 
windows 10 &11, Ubuntu 21+ IDE 3.4 general releases

Blue1987

  • Full Member
  • ***
  • Posts: 165
Re: how to detect a change in screen resolution in lazarus
« Reply #7 on: January 06, 2011, 08:19:16 pm »
You can use OnActivate event handler too and other events. This solution would be cross-platform.

Do you expect the user changes screen resolution while using your program?

It is a videogame, and I do not trust on the smartness of what a videogamer can do ;- )
I would like it to be robust to whatever one can do!

(it is a football manager game http://www.megaupload.com/?d=BBQ3DS97 , of course not complete for now, ver0.4.0.2 ... but I am working on it just in my free time ... and sorry if it is only available in italian) (but when I finish I'll release it open source, and anyone will be able to translate it)


... ehr... by the way... I thought I could use LMessages (so that I do not have to slow down the application), but "LM_displaychange" doesn't seem to be the right translation of "WM_displaychange"... but I must admit I am just a beginner programmer (as well as a beginner english speaker), so maybe there's something I do wrong!

 

TinyPortal © 2005-2018