- 1 year ago
How to get real display resolution in Delphi 7 regardless of scale factor?
In Delphi 7, you can use the GetDeviceCaps
function from the Windows API to retrieve the real display resolution regardless of the scale factor. Here's an example of how you can do this:
delphifunction GetRealDisplayResolution: TPoint;
var
DC: HDC;
begin
DC := GetDC(0);
try
Result.X := GetDeviceCaps(DC, HORZRES);
Result.Y := GetDeviceCaps(DC, VERTRES);
finally
ReleaseDC(0, DC);
end;
end;
In the above code, the GetRealDisplayResolution
function uses the GetDeviceCaps
function to retrieve the horizontal and vertical resolution of the display in device units, regardless of the scale factor.
To use this function, simply call it and store the result in a TPoint
variable:
delphivar
DisplayResolution: TPoint;
begin
DisplayResolution := GetRealDisplayResolution;
// Use DisplayResolution.X and DisplayResolution.Y as needed
end;
Please note that Delphi 7 is an older version, and newer versions of Delphi provide more convenient ways to obtain the display resolution, taking into account DPI scaling and multiple monitors. If possible, consider upgrading to a newer version of Delphi for more robust and up-to-date display resolution handling.