I blogged about how and where Delphi stores the desktop settings before. Back then I described the values as percentages of “the monitor” without being precise about which monitor and exactly which area. Since then I have nailed down the details. This applies to at least Delphi 12.
The “percentage” values given in the file, like this …
[Main Window] Left=-25271 Top=-6205 Width=12089 Height=18462
…, are 1/10000 of the primary monitor’s work area. Not its full resolution, and not relative to the monitor the window is actually on. The work area is the screen area minus the taskbar.
If your displays have different resolutions, this can be confusing, because the stored numbers are normalized to the primary monitor regardless of where the window actually lives. My setup looks like this:
- The main (primary) display has a resolution of 1920×1200 pixels.
- There is a secondary display with a resolution of 3840×2160 pixels.
- The high resolution display is placed to the left of my main display, aligned at the bottom.
- The desktop coordinate origin (0,0) is always at the top left corner of the primary monitor.
- That means the upper left corner of the high resolution display has negative X and Y coordinates.
To convert the stored values back to pixel coordinates, GExperts reads them and applies the work area scaling:
L := Ini.ReadInteger(SECTION, 'Left', 0); T := Ini.ReadInteger(SECTION, 'Top', 0); w := Ini.ReadInteger(SECTION, 'Width', 0); h := Ini.ReadInteger(SECTION, 'Height', 0); R := Screen.PrimaryMonitor.WorkareaRect; L := L * (R.Right - R.Left) div 10000; T := T * (R.Bottom - R.Top) div 10000; w := w * (R.Right - R.Left) div 10000; h := h * (R.Bottom - R.Top) div 10000;
A couple of things to keep in mind:
- If the primary monitor’s work area changes (taskbar moved or resized, or a different monitor becomes the primary), the same stored values will decode to different pixel positions.
- Because the values are integers divided by 10000, there is some rounding involved. Don’t expect to round-trip a window position to the exact pixel.
I use this calculation in the GExperts Reselect Desktop expert to work around a Delphi IDE bug that mangles window positions on multi-monitor setups.
