Autor Beitrag
Passi077
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Mo 27.02.06 17:35 
Hi,

ich möchte gerne Per Delphi meinen 2. Monitor, der standardmäßig der Sekundärmonitor ist, zum Primärmonitor machen und auf diesem die Auflösung ändern.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button1Click(Sender: TObject);
var
  lpDisplayDevice: TDisplayDevice;
  dwFlags: DWORD;
  cc: DWORD;
begin
 lpdisplaydevice.cb := sizeof(lpdisplaydevice);
 dwflags := 0;
 cc:= 0;
 while EnumDisplayDevices(nil, cc, lpDisplayDevice , dwFlags) do
  begin
    inc(cc);
    listbox1.items.add(lpdisplaydevice.DeviceString);
  end;
end;


Mit dem obigen Code lese ich die DeviceNamen aus, damit ich für den nachfolgenden Code den Namen des Displays weiß.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.Button2Click(Sender: TObject);
var
 DeviceMode: TDeviceModeA;
begin

 DeviceMode.dmPelsWidth := 1280;
 DeviceMode.dmPelsHeight := 720;
 DeviceMode.dmBitsPerPel := 32;

 ChangeDisplaySettingsEx(pchar(listbox1.items[0]), DeviceMode, NULL, CDS_SET_PRIMARY, 0);

end;


Mit diesem Code möchte ich nun die Auflösung ändern und den Monitor zum Primärmonitor machen. Funktioniert aber leider nicht so recht.. es kommt die Fehlermeldung:

ausblenden Quelltext
1:
Variante des Typs (Null) konnte nicht in Typ(Int64) konvertiert werden.					


Kann ich nicht so viel mit anfangen, deshalb wende ich mich an euch ;).

MSDN Eintrag

Ich hoffe, ihr könnt mir helfen!

Danke + Grüße,
Passi
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 27.02.06 17:43 
Übergib mal statt NULL einfach 0 ;-) Steht doch in der Deklaration (HWND = DWORD) ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Mo 27.02.06 17:48 
Ah ok, dann ist der Fehler immerhin schonmal erledigt.

Jetzt kommt leider eine Zugriffsverletzung im Modul GDI32.dll ...

Jemand eine Idee woran das liegen könnte ^^?
NeoInDerMATRIX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 245

Win95, Win98(+se), WinNT, Win2000, WinME, WinXP(+pro), VISTA, Linux(SuSe), DOS [MultiMon(3)], Vista
D6 PeE + (FP 2.0l) + D3 Pe + D2005+ D2006 Arch
BeitragVerfasst: Mi 01.03.06 19:32 
Hi,

also da wo BenBE sagte du sollst NULL mit "0" ersetzen ist nicht koreckt bitte mit NIL ersetzen!!!
Ween das nicht geht, dann sag bescheid dann zeige ich dir wie das geht! Arbeite auch gerade an sowas in der art. *g*

Cu
Neo
Passi077 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 125

Win XP
D7 Pers
BeitragVerfasst: Do 02.03.06 18:48 
Huhu, danke für die Antwort!

Funktioniert leider trotzdem nicht. Das seltsame ist, dass die Zugriffsverletzung nicht immer kommt, und wenn sie nicht kommt passiert aber gar nix :(

Für weitere Hilfe wär ich dankbar!

Grüße
Passi
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 02.03.06 19:10 
Les Dir doch bitte einmal die Hinweise im MSDN durch. Außerdem sollte man Variablen (auch Records) immer initialisieren ... Wie das in diesem Fall geht, siehe MSDN ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
NeoInDerMATRIX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 245

Win95, Win98(+se), WinNT, Win2000, WinME, WinXP(+pro), VISTA, Linux(SuSe), DOS [MultiMon(3)], Vista
D6 PeE + (FP 2.0l) + D3 Pe + D2005+ D2006 Arch
BeitragVerfasst: Fr 03.03.06 17:22 
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:
Function TOScrMonitor.SetScreenMode(AModeNum: Integer): Boolean;
Var
    Dev: TDevMode;
Begin
    // Neo: we think that M$ always make errors
    Result := False;
    // Neo: reset os error
    DbgResetOSError;
    // Neo: we reset to desktop
    If AModeNum = -1 Then
    Begin
        // Neo: call api for reset, also give NUL value
        Result := ChangeDisplaySettingsEx(PChar(DeviceName), TDevMode(Nil^), 0, 0, Nil) = disp_Change_Successful;
        // Neo: mark monitor for desktop mode
        FullScreen := False;
        // Neo: ?? an error
        DbgLastOSError;
        // Neo: have a nice day, leave this code
        Exit;
    End;
    // Neo: chack max bound for required screenmode
    If AModeNum > ModeCount Then
        Exit;
    // Neo: konvert screenmode data to devmode record
    Dev := OScrScreenModeToDevMode(Modes[AModeNum]);
    // Neo: call api and report error if required
    Case ChangeDisplaySettingsEx(PChar(DeviceName), Dev, 0, CDS_FULLSCREEN, Nil) Of
        disp_Change_Successful: Result := True;
        //      disp_Change_BadDualView: OmorphiaDebugStr(vl_Error, '', 'The settings change was unsuccessful because the system is DualView capable.');
        disp_Change_BadFlags: OmorphiaDebugStr(vl_Error, '', 'An invalid set of flags was passed in.');
        disp_Change_BadMode: OmorphiaDebugStr(vl_Error, '', 'The graphics mode is not supported.');
        disp_Change_BadParam: OmorphiaDebugStr(vl_Error, '', 'An invalid parameter was passed in in. This can include an invalid flag or combination of flags.');
        DISP_CHANGE_FAILED: OmorphiaDebugStr(vl_Error, '', 'The display driver failed the specified graphics mode.');
        disp_Change_NotUpdated: OmorphiaDebugStr(vl_Error, '', 'Unable to write settings to registry.');
        disp_Change_Restart: OmorphiaDebugStr(vl_Error, '', 'The Computer must be restarted for the graphics mode to work. (This may show an error for use tScrScreen Class)')
    Else
        // Neo: if we run this, an error not known is present
        DbgLastOSError;
    End;
    // Neo: mark monitor as fullscreen
    FullScreen := Result;
End;


Pass dir das mal an! Bin jetzt zu faul das ganze zu vereinfachen.

Cu
Neo
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 03.03.06 17:27 
Das ist ne Methode aus einer Klasse, die bestimmte Daten bereits vorbereitet hat. Die funzt für alle Monitore. Pass Dir die Klaase einfach nach deinen Bedürfnissen an.

Siehe viewcvs.omorphia.de/...urce/OScrMinotor.pas

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.