我正在用 Delphi 编写屏幕保护程序。我想要的是在每台显示器上全屏显示一个 TpresentationFrm。为此,我编写了以下(不完整的)程序:
program ScrTemplate;
uses
...
{$R *.res}
type
TScreenSaverMode = (ssmConfig, ssmDisplay, ssmPreview, ssmPassword);
function GetScreenSaverMode: TScreenSaverMode;
begin
// Some non-interesting code
end;
var
i: integer;
presentationForms: array of TpresentationFrm;
begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
case GetScreenSaverMode of
ssmConfig:
Application.CreateForm(TconfigFrm, configFrm);
ssmDisplay:
begin
SetLength(presentationForms, Screen.MonitorCount);
for i := 0 to high(presentationForms) do
begin
Application.CreateForm(TpresentationFrm, presentationForms[i]);
presentationForms[i].BoundsRect := Screen.Monitors[i].BoundsRect;
presentationForms[i].Visible := true;
end;
end
else
ShowMessage(GetEnumName(TypeInfo(TScreenSaverMode), integer(GetScreenSaverMode)));
end;
Application.Run;
end.
执行代码时ssmDisplay
,确实创建了两个表单(是的,我正好有两个监视器)。但它们都出现在第一台监视器上(索引 0,但不是主监视器)。
单步执行代码时,我发现它们Screen.Monitors[i].BoundsRect
是正确的,但由于某种原因,表单的边界不正确:
Watch Name Value (TRect: Left, Top, Right, Bottom, ...)
Screen.Monitors[0].BoundsRect (-1680, 0, 0, 1050, (-1680, 0), (0, 1050))
Screen.Monitors[1].BoundsRect (0, 0, 1920, 1080, (0, 0), (1920, 1080))
presentationForms[0].BoundsRect (-1680, 0, 0, 1050, (-1680, 0), (0, 1050))
presentationForms[1].BoundsRect (-1920, -30, 0, 1050, (-1920, -30), (0, 1050))
第一种形式获得所需的位置,但第二种形式没有。它不是从 x=0 到 1920,而是占用 x=-1920 到 0,即它出现在第一个监视器上,在第一个窗体上方。怎么了?完成我想要的正确程序是什么?