How to show a firemonkey form on second monitor

 

Questions


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?

 

 

————————————————-

Answer

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;

c++builder,c++builder-xe2,delphi,firemonkey

Facebook Comments

Post a comment