Thema: Delphi Monitor 2 Ansteuern?

Einzelnen Beitrag anzeigen

Bernd29bln

Registriert seit: 28. Feb 2005
Ort: Berlin
281 Beiträge
 
Delphi 7 Professional
 
#9

Re: Monitor 2 Ansteuern?

  Alt 19. Apr 2005, 11:23
Hallo,

er ruft die procedure nicht auf, wieso nicht?

Delphi-Quellcode:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    lbMonitorList: TListBox;
    procedure Button1Click(Sender: TObject);
    Procedure FillMonitorList;
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
Type
  TPOINTL = Packed Record
    x : DWORD;
    y : DWORD;
  End;
  TPrinterMonitor = Packed Record
    Case Integer Of
      0 : (Paper: Packed Record
            dmOrientation: SHORT;
            dmPaperSize: SHORT;
            dmPaperLength: SHORT;
            dmPaperWidth: SHORT;
            dmScale: SHORT;
            dmCopies: SHORT;
            dmDefaultSource: SHORT;
            dmPrintQuality: SHORT;
          End;);
      1 : (Monitor: Packed Record
            dmPosition : TPOINTL;
            dmDisplayOrientation : DWORD;
            dmDisplayFixedOutput : DWORD;
           End;)
  End;
  TDevModeA_new = packed record
    dmDeviceName: array[0..CCHDEVICENAME - 1] of AnsiChar;
    dmSpecVersion: Word;
    dmDriverVersion: Word;
    dmSize: Word;
    dmDriverExtra: Word;
    dmFields: DWORD;

    /// !!!
    Dual : TPrinterMonitor;
    /// !!!

    dmColor: SHORT;
    dmDuplex: SHORT;
    dmYResolution: SHORT;
    dmTTOption: SHORT;
    dmCollate: SHORT;
    dmFormName: array[0..CCHFORMNAME - 1] of AnsiChar;
    dmLogPixels: Word;
    dmBitsPerPel: DWORD;
    dmPelsWidth: DWORD;
    dmPelsHeight: DWORD;
    dmDisplayFlags: DWORD;
    dmDisplayFrequency: DWORD;
    dmICMMethod: DWORD;
    dmICMIntent: DWORD;
    dmMediaType: DWORD;
    dmDitherType: DWORD;
    dmICCManufacturer: DWORD;
    dmICCModel: DWORD;
    dmPanningWidth: DWORD;
    dmPanningHeight: DWORD;
  end;
//***************************************************************************************************
procedure TForm1.Button1Click(Sender: TObject);
Var
  lDevMode : TDevModeA_new;
  lRes : Cardinal;
begin
    FillChar(lDevMode, SizeOf(lDevMode), 0);

    lDevMode.dmSize := SizeOf(lDevMode);
    lDevMode.dmBitsPerPel := 32;
    lDevMode.dmDisplayFrequency := 85; // alles hard kodiert für meinen 2. Monitor
    lDevMode.dmPelsWidth := 1280;
    lDevMode.dmPelsHeight := 1024;
    lDevMode.Dual.Monitor.dmPosition.x := 1280; // die Weite/Auflösung des primären Monitors bzw. Lage des Monitors in Relation zum primären Monitor mit 0,0 oben links
    lDevMode.Dual.Monitor.dmPosition.y := 0;
    lDevMode.dmFields := DM_BITSPERPEL Or
                                          DM_DISPLAYFREQUENCY Or
                                          DM_PELSWIDTH Or
                                          DM_PELSHEIGHT Or
                                          DM_POSITION;

    lRes := ChangeDisplaySettingsEx( PChar('\\.\DISPLAY2'),
                             TDevMode(lDevMode),
                             0,
                             CDS_UPDATEREGISTRY,
                             0);

    If lres <> 0 Then
      ShowMessage('hat nicht geklappt');
end;
//***************************************************************************************************
Procedure TForm1.FillMonitorList;
Var
  Cntr : Cardinal;
  Info : TDisplayDevice;
  AdapterName : PChar;
  OldPos : Integer;
Const
  DISPLAY_DEVICE_ATTACHED_TO_DESKTOP = $00000001;
  DISPLAY_DEVICE_MULTI_DRIVER = $00000002;
  DISPLAY_DEVICE_PRIMARY_DEVICE = $00000004;
  DISPLAY_DEVICE_MIRRORING_DRIVER = $00000008;
  DISPLAY_DEVICE_VGA = $00000010;
Begin
  lbMonitorList.Items.Add('------------------ Displays ----------------');

  Cntr := 0;
  Info.cb := SizeOf(Info);
  While EnumDisplayDevices(Nil, Cntr, Info, 0) Do
  Begin
    lbMonitorList.Items.Add('* Device '+IntToStr(Cntr)+':');
    lbMonitorList.Items.Add(' DeviceName : '+Info.DeviceName);
    lbMonitorList.Items.Add(' DeviceString: '+Info.DeviceString);

    OldPos := lbMonitorList.Items.Add(' StateFlags: ');

    If ( Info.StateFlags And DISPLAY_DEVICE_ATTACHED_TO_DESKTOP ) = DISPLAY_DEVICE_ATTACHED_TO_DESKTOP Then
      lbMonitorList.Items.Add(' + Display Device Attached To Desktop')
    Else
      lbMonitorList.Items.Add(' - Display Device Attached To Desktop');

    If ( Info.StateFlags And DISPLAY_DEVICE_MULTI_DRIVER ) = DISPLAY_DEVICE_MULTI_DRIVER Then
      lbMonitorList.Items.Add(' + Display Device Multi Driver')
    Else
      lbMonitorList.Items.Add(' - Display Device Multi Driver');

    If ( Info.StateFlags And DISPLAY_DEVICE_PRIMARY_DEVICE ) = DISPLAY_DEVICE_PRIMARY_DEVICE Then
      lbMonitorList.Items.Add(' + Display Device Primary Device')
    Else
      lbMonitorList.Items.Add(' - Display Device Primary Device');

    If ( Info.StateFlags And DISPLAY_DEVICE_MIRRORING_DRIVER ) = DISPLAY_DEVICE_MIRRORING_DRIVER Then
      lbMonitorList.Items.Add(' + Display Device Mirroring Driver')
    Else
      lbMonitorList.Items.Add(' - Display Device Mirroring Driver');

    If ( Info.StateFlags And DISPLAY_DEVICE_VGA ) = DISPLAY_DEVICE_VGA Then
      lbMonitorList.Items.Add(' + Display Device VGA')
    Else
      lbMonitorList.Items.Add(' - Display Device VGA');


    AdapterName := StrAlloc(SizeOf(Info.DeviceName));
    StrCopy(AdapterName, Info.DeviceName);
    EnumDisplayDevices(AdapterName, 0, Info, 0);
    ShowMessage(SysErrorMessage(GetLastError));
    lbMonitorList.Items.Insert(OldPos, ' Monitorname : ' + Info.DeviceString);
    StrDispose(AdapterName);

    Inc(Cntr);
  End;
End;


end.
MfG
Bernd
Es ist keine Schande, nichts zu wissen, wohl aber, nichts lernen zu wollen.
Sokrates
  Mit Zitat antworten Zitat