tips
[Top] [All Lists]

Has the user changed their monitor resolution?

To: "REALbasic Tips" <realbasic-tips at lists dot realsoftware dot com>
Subject: Has the user changed their monitor resolution?
From: Geoff Perlman <geoff at realsoftware dot com>
Date: Fri, 07 Jul 2000 15:32:27 -0500
It's common practice for an application to determine if the user has changed their monitor resolution. If the resolution has changed, windows may need to be repositioned as they may no longer be on screen (if the user has lowered
the resolution for example).

You can easily check to see if the user has changed the resolution of any monitor attached to their computer using the Screen class. This class has properties that indicate the width and height of the screen number passed.
To implement this:

1. Add a new class based on Application to your project (if you don't
already have one).
2. Add these two properties to your app class:
LastScreenWidth as Integer
LastScreenHeight as Integer

3. In the Open event of your application class, set these two properties to
the current width and height of Screen 0 (the users main screen):

  lastScreenWidth = Screen(0).width
  lastScreenHeight = Screen(0).height

4. Add a new method called "ResolutionChanged" to your application class and
have it return a boolean. Here's the code for the method:

  if lastScreenWidth <> Screen(0).width or lastScreenHeight <>
Screen(0).height then
    lastScreenWidth = Screen(0).width
    lastScreenHeight = Screen(0).height
    return true
  else
    return false
  end if

5. Since the Paint event of the frontmost window executes when the monitor
resolution is changed, you can call your ResolutionChanged method in the
Paint event of your windows to determine if you need to take action or not.

If you want to determine if the resolutions of other monitors have been
changed, the code will be a bit more complicated. I've kept it to the main
monitor for the purposes of this tip.

This tip was inspired by Blair Hope.
--

Geoff Perlman
President & CEO
REAL Software, Inc.
http://www.realsoftware.com
mailto:geoff at realsoftware dot com
Phone: 512-263-1233 x711
Fax:   512-263-1441



 - - - - - - - - - -
Got a useful tip to share? Send it to us at:
REALbasic-tips at lists dot realsoftware dot com dot
For list commands, send "Help" in the body of a message to
<requests at lists dot realsoftware dot com>



<Prev in Thread] Current Thread [Next in Thread>
  • Has the user changed their monitor resolution?, Geoff Perlman <=