4

I'm building something which needs to detect when things change with the monitor configuration. This includes Monitor added/removed, Monitor position moved (compared to main screen), or when Monitor resolution has changed. The most ideal way would be catching some windows messages, if any, which are triggered when such events occur. This information will be used to keep a real-time record of the monitor sizes/positions at any given time. For example, when a monitor's resolution is increased, my app will catch this right away and make its own adjustments to accommodate for the change. How do I catch these events?

I'm also trying to avoid using VCL (such as Vcl.Forms.Screen.MonitorCount) which is why I prefer to catch a Windows Message.

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327

1 Answers1

11

The most obvious message I can think of is WM_DISPLAYCHANGE which is sent, at least, when the resolution is changed.

Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • 3
    At which point you can use [EnumDisplayMonitors](http://msdn.microsoft.com/en-us/library/dd162610%28v=VS.85%29.aspx) to detect new information like position, size, count, and so forth. +1. – Ken White Jun 12 '12 at 22:19
  • 2
    or just recreate the global `Screen` variable: `Screen.Free; Screen := TScreen.Create(nil);` – Ondrej Kelle Jun 13 '12 at 07:13
  • 1
    Newer Delphi versions (De 10.2) offers the method `Screen.UpdateDisplayInformation` so you do not need to recreate the screen object – Schneider Infosystems Ltd Feb 19 '19 at 13:21
  • @SchneiderInfosystemsLtd - UpdateDisplayInformation is only available for FMX. – Gabriel May 24 '20 at 09:53