How to show a firemonkey form on second monitor

穿精又带淫゛_ 提交于 2019-12-23 19:02:37

问题


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?


回答1:


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;



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/9242998/how-to-show-a-firemonkey-form-on-second-monitor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!