Autor Beitrag
Nano-Ware
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 7



BeitragVerfasst: Mi 18.04.12 17:02 
Hey,

ich möchte ein kleines Tool schreiben, welches den primären mit dem sekundären Monitor vertauscht. Ich bin schon auf die Funktion "ChangeDisplaySettingsEx" gestoßen, aber nicht herausfinden können, wie ich sie nun verwende. Währe nett, wenn ihr helfen könntet!

Danke
Perlsau
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 19.04.12 09:59 
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Do 19.04.12 14:26 
msdn.microsoft.com/d...d183413%28v=VS.85%29

So wie ich das sehe musst du dir erst die Display-Namen mit EnumDisplayDevices holen. Die kannst du dann an die ChangeDisplaySettingsEx-Funktion übergeben.

Das könnte dir auch weiterhelfen: www.delphi-forum.de/...schirm_103168,0.html
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10181
Erhaltene Danke: 1254

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 19.04.12 23:59 
Moin!

Da ich zufällig auch gerade in dieser Ecke unterwegs bin, hier mal mein aktueller Test-Code:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
unit Unit1;

interface

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

{ State-Flags: // http://msdn.microsoft.com/en-us/library/dd183569(v=vs.85).aspx

DISPLAY_DEVICE_ACTIVE

  DISPLAY_DEVICE_ACTIVE specifies whether a monitor is presented as being "on"
  by the respective GDI view. Windows Vista: EnumDisplayDevices will only
  enumerate monitors that can be presented as being "on."

DISPLAY_DEVICE_MIRRORING_DRIVER

  Represents a pseudo device used to mirror application drawing for remoting or
  other purposes. An invisible pseudo monitor is associated with this device.
  For example, NetMeeting uses it. Note that GetSystemMetrics (SM_MONITORS) only
  accounts for visible display monitors.

DISPLAY_DEVICE_MODESPRUNED

  The device has more display modes than its output devices support.

DISPLAY_DEVICE_PRIMARY_DEVICE

  The primary desktop is on the device. For a system with a single display card,
  this is always set. For a system with multiple display cards, only one device
  can have this set.

DISPLAY_DEVICE_REMOVABLE

  The device is removable; it cannot be the primary display.

DISPLAY_DEVICE_VGA_COMPATIBLE

  The device is VGA compatible.
}

const
  DISPLAY_DEVICE_ACTIVE              = DWORD($00000001);
  DISPLAY_DEVICE_MIRRORING_DRIVER    = DWORD($00000008);
  DISPLAY_DEVICE_MODESPRUNED         = DWORD($08000000);
  DISPLAY_DEVICE_PRIMARY_DEVICE      = DWORD($00000004);
  DISPLAY_DEVICE_REMOVABLE           = DWORD($00000020);
  DISPLAY_DEVICE_VGA_COMPATIBLE      = DWORD($00000010);

type
  TDispFlag = record
    Bits: DWORD;
    Name: String;
  end;

  TDisplayDevice = packed record
    cb: DWORD;
    DeviceName: array[0..31of AnsiChar;
    DeviceString: array[0..127of AnsiChar;
    StateFlags: DWORD;
    DeviceID: array[0..127of AnsiChar;
    DeviceKey: array[0..127of AnsiChar;
  end;

  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure ListBox1DblClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

const
  DispFlags: array[0..5of TDispFlag = (
    (Bits: DISPLAY_DEVICE_ACTIVE; Name: 'DISPLAY_DEVICE_ACTIVE'),
    (Bits: DISPLAY_DEVICE_MIRRORING_DRIVER; Name: 'DISPLAY_DEVICE_MIRRORING_DRIVER'),
    (Bits: DISPLAY_DEVICE_MODESPRUNED; Name: 'DISPLAY_DEVICE_MODESPRUNED'),
    (Bits: DISPLAY_DEVICE_PRIMARY_DEVICE; Name: 'DISPLAY_DEVICE_PRIMARY_DEVICE'),
    (Bits: DISPLAY_DEVICE_REMOVABLE; Name: 'DISPLAY_DEVICE_REMOVABLE'),
    (Bits: DISPLAY_DEVICE_VGA_COMPATIBLE; Name: 'DISPLAY_DEVICE_VGA_COMPATIBLE')
  );

function EnumDisplayDevices(Unused: Pointer; iDevNum: DWORD;
  var lpDisplayDevice: TDisplayDevice; dwFlags: DWORD): BOOL; stdcall;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function EnumDisplayDevices; external user32 name 'EnumDisplayDevicesA';

procedure TForm1.Button1Click(Sender: TObject);
  var
    DisplayDevice: TDisplayDevice;
    iDevNum: DWORD;
begin
  DisplayDevice.cb := SizeOf(DisplayDevice);
  iDevNum:= 0;
  // http://msdn.microsoft.com/en-us/library/dd162609(v=vs.85).aspx
  while EnumDisplayDevices(NIL, iDevNum, DisplayDevice, 0do begin
    ListBox1.Items.Add(DisplayDevice.DeviceString);
    Inc(iDevNum);
  end;
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
  var
    i: Integer;
    DisplayDevice: TDisplayDevice;
    tmp: String;
begin
  DisplayDevice.cb := SizeOf(DisplayDevice);
  i := ListBox1.ItemIndex;
  if (i >= 0then begin
    if EnumDisplayDevices(NIL, i, DisplayDevice, 0then begin
      Memo1.Clear;
      Memo1.Lines.Add('DeviceName: '+DisplayDevice.DeviceName);
      Memo1.Lines.Add('DeviceString: '+DisplayDevice.DeviceString);
      Memo1.Lines.Add('StateFlags: '+IntToHex(DisplayDevice.StateFlags,8));
      tmp := '';
      for i := 0 to High(DispFlags) do
        if (DisplayDevice.StateFlags and DispFlags[i].Bits) <> 0 then
          tmp := tmp +DispFlags[i].Name +',';
      Memo1.Lines.Add('StateFlags: '+tmp);
      Memo1.Lines.Add('DeviceID: '+DisplayDevice.DeviceID);
      Memo1.Lines.Add('DeviceKey: '+DisplayDevice.DeviceKey);
    end
    else
      ShowMessage('Fehler bei EnumDisplayDevices('+IntToStr(i)+')!');
  end;
end;

end.
Vielleicht kannst du damit was anfangen. :nixweiss:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.