www.pudn.com > MultiMonitorDemo.rar > PrimaryForms.pas


unit PrimaryForms; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, StdCtrls, ComCtrls, Types; 
 
type 
  TPrimaryForm = class(TForm) 
    btnRefresh: TButton; 
    btnMoveTo: TButton; 
    btnMakeFullyVisible: TButton; 
    PageControl1: TPageControl; 
    TabSheet1: TTabSheet; 
    Label1: TLabel; 
    Label2: TLabel; 
    Label3: TLabel; 
    Label4: TLabel; 
    Label5: TLabel; 
    Label6: TLabel; 
    Label7: TLabel; 
    Label8: TLabel; 
    Label9: TLabel; 
    Label10: TLabel; 
    Label11: TLabel; 
    Label12: TLabel; 
    Label13: TLabel; 
    lblScreenHeight: TLabel; 
    lblScreenWidth: TLabel; 
    lblDesktopTop: TLabel; 
    lblDesktopLeft: TLabel; 
    lblDesktopHeight: TLabel; 
    lblDesktopWidth: TLabel; 
    lblWorkAreaTop: TLabel; 
    lblWorkAreaLeft: TLabel; 
    lblWorkAreaHeight: TLabel; 
    lblWorkAreaWidth: TLabel; 
    TabSheet2: TTabSheet; 
    Label24: TLabel; 
    Label14: TLabel; 
    Label15: TLabel; 
    Label16: TLabel; 
    Label17: TLabel; 
    lblMonitorTop: TLabel; 
    lblMonitorLeft: TLabel; 
    lblMonitorHeight: TLabel; 
    lblMonitorWidth: TLabel; 
    Label22: TLabel; 
    Label23: TLabel; 
    Label25: TLabel; 
    Label26: TLabel; 
    Label27: TLabel; 
    lblMonitorWorkAreaTop: TLabel; 
    lblMonitorWorkAreaLeft: TLabel; 
    lblMonitorWorkAreaHeight: TLabel; 
    lblMonitorWorkAreaWidth: TLabel; 
    cbMonitors: TComboBox; 
    Label18: TLabel; 
    lblPrimary: TLabel; 
    procedure FormCreate(Sender: TObject); 
    procedure btnRefreshClick(Sender: TObject); 
    procedure cbMonitorsChange(Sender: TObject); 
    procedure btnMoveToClick(Sender: TObject); 
    procedure btnMakeFullyVisibleClick(Sender: TObject); 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
var 
  PrimaryForm: TPrimaryForm; 
 
implementation 
 
{$R *.dfm} 
 
procedure TPrimaryForm.FormCreate(Sender: TObject); 
begin 
  btnRefreshClick(Sender); 
end; 
 
procedure TPrimaryForm.btnRefreshClick(Sender: TObject); 
var 
  i:Integer; 
begin 
  lblScreenHeight.Caption := IntToStr(Screen.Height); 
  lblScreenWidth.Caption := IntToStr(Screen.Width); 
 
  lblDesktopTop.Caption := IntToStr(Screen.DesktopTop); 
  lblDesktopLeft.Caption := IntToStr(Screen.DesktopLeft); 
  lblDesktopHeight.Caption := IntToStr(Screen.DesktopHeight); 
  lblDesktopWidth.Caption := IntToStr(Screen.DesktopWidth); 
 
  lblWorkAreaTop.Caption := IntToStr(Screen.WorkAreaTop); 
  lblWorkAreaLeft.Caption := IntToStr(Screen.WorkAreaLeft); 
  lblWorkAreaHeight.Caption := IntToStr(Screen.WorkAreaHeight); 
  lblWorkAreaWidth.Caption := IntToStr(Screen.WorkAreaWidth); 
 
  cbMonitors.Clear; 
  for i := 0 to Screen.MonitorCount - 1 do 
  begin 
    cbMonitors.AddItem(Format('Monitor %d', [i + 1]), nil); 
  end; 
  if Screen.MonitorCount > 0 then 
  begin 
    cbMonitors.ItemIndex := Monitor.MonitorNum; 
    cbMonitorsChange(Sender); 
  end; 
end; 
 
procedure TPrimaryForm.cbMonitorsChange(Sender: TObject); 
begin 
  if cbMonitors.ItemIndex >= 0 then 
  begin 
    if Screen.Monitors[cbMonitors.ItemIndex].Primary then 
      lblPrimary.Caption := 'True' 
    else 
      lblPrimary.Caption := 'False'; 
 
    lblMonitorTop.Caption := IntToStr(Screen.Monitors[cbMonitors.ItemIndex].Top); 
    lblMonitorLeft.Caption := IntToStr(Screen.Monitors[cbMonitors.ItemIndex].Left); 
    lblMonitorHeight.Caption := IntToStr(Screen.Monitors[cbMonitors.ItemIndex].Height); 
    lblMonitorWidth.Caption := IntToStr(Screen.Monitors[cbMonitors.ItemIndex].Width); 
 
    lblMonitorWorkAreaTop.Caption := IntToStr(Screen.Monitors[cbMonitors.ItemIndex].WorkareaRect.Top); 
    lblMonitorWorkAreaLeft.Caption := IntToStr(Screen.Monitors[cbMonitors.ItemIndex].WorkareaRect.Left); 
    lblMonitorWorkAreaHeight.Caption := IntToStr(Screen.Monitors[cbMonitors.ItemIndex].WorkareaRect.Bottom - Screen.Monitors[cbMonitors.ItemIndex].WorkareaRect.Top); 
    lblMonitorWorkAreaWidth.Caption := IntToStr(Screen.Monitors[cbMonitors.ItemIndex].WorkareaRect.Right - Screen.Monitors[cbMonitors.ItemIndex].WorkareaRect.Left); 
  end 
  else 
  begin 
    lblPrimary.Caption := ''; 
 
    lblMonitorTop.Caption := ''; 
    lblMonitorLeft.Caption := ''; 
    lblMonitorHeight.Caption := ''; 
    lblMonitorWidth.Caption := ''; 
 
    lblMonitorWorkAreaTop.Caption := ''; 
    lblMonitorWorkAreaLeft.Caption := ''; 
    lblMonitorWorkAreaHeight.Caption := ''; 
    lblMonitorWorkAreaWidth.Caption := ''; 
  end; 
end; 
 
procedure TPrimaryForm.btnMoveToClick(Sender: TObject); 
begin 
  if cbMonitors.ItemIndex >= 0 then 
  begin 
    if Monitor <> nil then 
    begin 
      Self.Left := Self.Left - Monitor.Left; 
      Self.Top := Self.Top - Monitor.Top; 
 
      Self.Left := Self.Left + Screen.Monitors[cbMonitors.ItemIndex].Left; 
      Self.Top := Self.Top + Screen.Monitors[cbMonitors.ItemIndex].Top; 
    end; 
  end; 
end; 
 
procedure TPrimaryForm.btnMakeFullyVisibleClick(Sender: TObject); 
begin 
  MakeFullyVisible(Screen.Monitors[cbMonitors.ItemIndex]); 
end; 
 
end.