Wednesday, May 9, 2012

Keeping Screen Resolution in Mind

I'm redoing an old Delph 5 app that forced a screen resolution of 640 x 480 on the users. At the time this application was deveopled that screen resolution was acceptable but not anymore. Todays endless arrays of screen resolutions brings on new challenges. One of the things I plan on doing at application start is interrogate the current screen resolution and set my application screen size to a ratio of 80%.

I'm amazed at how much information is available. Here is a nice graph that shows the top 10 screen resolutions in use from 2008 through 2012.


Add MultiMon to the uses clause The button click event lets you move the program between two monitors to get the screen resolution.
procedure TScreenResolution.Button1Click(Sender: TObject);
  MonInfo: TMonitorInfo;
  ScreenW, ScreenH : integer;
  MonInfo.cbSize := SizeOf(MonInfo);
  GetMonitorInfo(MonitorFromWindow(Handle, MONITOR_DEFAULTTONEAREST), @MonInfo);
  ScreenW :=  MonInfo.rcMonitor.Right  - MonInfo.rcMonitor.Left;
  ScreenH :=  MonInfo.rcMonitor.Bottom - MonInfo.rcMonitor.Top;
  Label2.Caption := IntToStr(ScreenW);
  Label4.Caption := IntToStr(ScreenH);
Semper Fi - Gunny Mike

FireMonkey Update - 05/13/2012:

I'd like to thank Whiler from StackOverflow for a FireMonkey example using FX.Platform:


  1. Checked out code in Xe2 - works fine.

    Tried it in FireMonkey out of curiosity and while I didn't get any errors (other than having to change Labelx.Caption to Labelx.Text) the information was garbage and didn't change between monitors.
    Curious that the MultiMon is supported but functions differently. Being a FireMonkey nube I'm probably just missing something.

    1. Your test is not good... It compile because you only tested it with Windows platform... If you add the OSX platform, the unit doesn't exist yet...

      As explain in the thread mentionned Gunny Mike above, Multi-monitor is not yet supported by FMX.

      Maybe with XE3... wait and see...

  2. @El Steve-o - Thanks for the heads up on FireMonkey. If you do find some FireMonkey code that works please post a comment.