Question

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();
 }

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

Était-ce utile?

La solution

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;

Autres conseils

FMX has no multi-monitor support yet. You will have to write platform specific code and switch behaviour using the platform conditional defines.

In XE7, there is now a global Screen variable which has a Screen.Displays[] property that you can use to get information about the available displays. The Screen.DisplayCount property can tell you how many displays there are. You have to add "FMX.Forms" to your USES clause to use this.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top