如何在第二个监视器上显示Firemonkey表单

如何在第二个监视器上显示Firemonkey表单

问题描述:

我正在尝试使用带有以下代码的C ++ Builder在第二台显示器上显示FireMonkey表单:

I am trying to display a FireMonkey form on a second monitor, using C++Builder with following code:

 void __fastcall ShowFormOnScreen( int OutMon )
 { 
   MyForm->Top = 0;
   MyForm->BorderStyle = bsNone;
   MyForm->WindowState = wsNormal;
   MyForm->Left   = Screen->Monitors[OutMon]->Left;
   MyForm->Height = Screen->Monitors[OutMon]->Height;
   MyForm->Width  = Screen->Monitors[OutMon]->Width;
   MyForm->Show();
 }

不幸的是,Screen对象没有Monitors属性,那么如何在FireMonkey中做到这一点?

Unfortunately, the Screen object does not have the Monitors property, so how can do this in FireMonkey?

对于Windows,您可以使用EnumDisplayMonitors查找第二个监视器. 这需要一个回调函数,它将从找到的每个监视器接收信息. 下面的Delphi中的示例在第二个监视器上显示第二个Firemonkey表单并使背景变黑

For windows you can use EnumDisplayMonitors to locate the second monitor. This needs a callback function which will receive the information from each monitor found. Example in Delphi below which displays a second Firemonkey form on the second monitor and makes the background black

// Callback function in function MonitorCount
function MonCountCB(hm: HMONITOR; dc: HDC; r: PRect; l: LPARAM): Boolean; stdcall;
var
  mInfo : MonitorInfoEx;
//  SecondaryRect: RECT;
begin

  minfo.cbSize := sizeof(mInfo);
  GetMonitorInfo(hm, @mInfo);

  if mInfo.dwFlags <> MONITORINFOF_PRIMARY then
  begin
     MonitorForm.Left := mInfo.rcWork.Left;
     MonitorForm.Top := mInfo.rcWork.Top;
     MonitorForm.Width := mInfo.rcWork.Width;
     MonitorForm.Height := mInfo.rcWork.Height;
  end;

  inc(Integer(pointer(l)^));
  result := true;
end;


procedure TForm1.CornerButton1Click(Sender: TObject);
var
  MonitorCount : Integer;
begin
  EnumDisplayMonitors(0,nil,MonCountCB, Integer(@MonitorCount));
  MonitorForm.Viewport3D1.Color := TAlphaColors.Black;
  MonitorForm.Show;
end;