具有多个显示器的FireMonkey应用程序



我需要获取显示我的应用程序的显示器的屏幕比例。多平台运行时TPlatFormServices有一个名为IFMXScreenService的服务,该服务返回屏幕缩放 (GetScreenScale(。

问题是它只为主监视器返回它。我需要为运行应用程序的任何监视器获取它。

以下是我获取IFMXScreenService的C++代码。如何修改它以获取活动显示器的屏幕服务?

if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXScreenService)) == true)
{
pScreenService_ = TPlatformServices::Current->GetPlatformService(__uuidof(IFMXScreenService));
}                         

现在,我只是在Windows下作弊,并将以下例程添加到我的基窗体类中:

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TFormBase::GetScaleFactor()
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
double TFormBase::GetScaleFactor(void)
{
double fScale = 0.0;
#ifdef WIN32
TPoint objTopLeft = TPoint(Left,Top);
HMONITOR hMonitor = MonitorFromPoint(objTopLeft,MONITOR_DEFAULTTONULL);
if (hMonitor != NULL)
{
DEVICE_SCALE_FACTOR nScaleFactor;
if (GetScaleFactorForMonitor(hMonitor,&nScaleFactor) == S_OK)
{
fScale = static_cast<double> ((static_cast<int> (nScaleFactor))) / 100.0;
}
}
if (fScale == 0.0)
{
fScale = ScreenService->ScreenScale;
}
#else
fScale = ScreenService->ScreenScale;
#endif
return fScale;
}

我不知道如何在C++生成器中执行此操作,在德尔福中,我按如下方式执行此操作

function GetScreenshotZoom(APoint: TPoint): Single; overload;
var
Monitor: HMonitor;
DpiX, DpiY: Cardinal;
begin
if TOSVersion.Check(6, 3) then
begin
Monitor := Winapi.MultiMon.MonitorFromPoint(APoint, MONITOR_DEFAULTTONEAREST);
GetDPIForMonitor(Monitor, MDT_Default, DpiX, DpiY);
Result := DpiX / StandardDpi;
end
else
Result := 1;
end;
uses Winapi.ShellScaling, Winapi.ShlObj, Winapi.MultiMon;
function GetScreenScale(sc:integer): Single;
var
Monitor: HMonitor;
Scale: DEVICE_SCALE_FACTOR;
p:TPoint;
begin
result:=1;
p.X:=Screen.Displays[sc].BoundsRect.Left;
p.Y:=Screen.Displays[sc].BoundsRect.Top;
Monitor:=MonitorFromPoint(p,MONITOR_DEFAULTTONULL);
if (GetScaleFactorForMonitor(sc,Scale)=S_OK) then
begin
result:=(100.0 / Integer(Scale));
if result=0 then
result:=1;
end;
end;

最新更新