Entwickler-Ecke

Open Source Projekte - Helligkeit von Windows regeln - GammaChanger [6 KB]


retnyg - Mi 09.03.05 21:20
Titel: Helligkeit von Windows regeln - GammaChanger [6 KB]
ein kleines Programm (6 KB) zum Regulieren der Helligkeit des Desktops.

Sehr nützlich wenn einem ein Spiel wie Quake3 oder Unreal Tournament im Direct3D- oder OpenGL- Modus abgestürzt ist, und einem einen strahlend hellen Desktop hinterlässt.

Kommandozeilenparameter: EINE ZAHL
wird keine Zahl angegeben, so wird einfach der Windows-Default-Wert (128) eingestellt.

download hier [http://krazz.net/retnyg/gammachange.zip]


ScorpionKing - So 03.04.05 19:12

echt klasse! super tool!

MfG, ScorpionKing!


toms - So 03.04.05 19:26

Wichtiger Hinweis:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/icm/icm_8ckw.asp

GetDeviceGammaRamp succeeds only for devices with drivers that support downloadable gamma ramps in hardware.


retnyg - Mi 06.04.05 12:02

auf nachfrage von invulnerabilis habe ich ne VCL-Version meiner GammaRamp Unit erstellt:
gammaramp.pas hat folgendes geschrieben:

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:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
unit gammaramp;
// translated from a c++ source on
// http://www.nirsoft.net/vc/change_screen_brightness.html
// original code by Nir Sofer
// translation by retnyg
interface

uses windows;

CONST NULL = 0;

type

  //LPVOID = ^PVOID;
  LPVOID = Pointer;
  PVOID = array[0..2of array [0..255of word;
  Type_SetDeviceGammaRamp = function(DC:HDC; lpRamp:LPVOID):boolean; stdcall;

  PgammaRamp = ^TGammaRamp;
  TGammaRamp = class(TObject)
  protected
    hGDI32:HMODULE;
    hScreenDC:HDC;
    pGetDeviceGammaRamp,pSetDeviceGammaRamp: Type_SetDeviceGammaRamp;
//    function pGetDeviceGammaRamp(DC:HDC; lpRamp:LPVOID):boolean;
//    function pSetDeviceGammaRamp(DC:HDC; lpRamp:LPVOID):boolean;
    //Type_SetDeviceGammaRamp;

  public
    function LoadLib:boolean;
    procedure FreeLib;
    function LoadLibraryIfNeeded:boolean;
    function SetDeviceGammaRamp(DC:HDC; lpRamp:LPVOID):boolean;
    function GetDeviceGammaRamp(DC:HDC; lpRamp:LPVOID):boolean;
//    function SetDeviceGammaRamp:Type_SetDeviceGammaRamp;
//    function GetDeviceGammaRamp:Type_SetDeviceGammaRamp;
    function SetBrightness(dc:HDC; wBrightness:WORD):boolean;
    constructor Create;
    destructor Destroy; virtual;
  end;

//function NewGammaRamp: PGammaRamp;

implementation

Constructor TGammaramp.Create;
begin
  //Initialize all variables.
  hGDI32 := NULL;
  hScreenDC := NULL;
//  @result.pGetDeviceGammaRamp := nil;
//  @result.pSetDeviceGammaRamp := nil;
end;



function TGammaRamp.LoadLib:boolean;
begin
  result := FALSE;
  FreeLib;
  //Load the GDI library.
  hGDI32 := LoadLibrary('gdi32.dll');
  if (hGDI32 <> NULL) then begin

  //Get the addresses of GetDeviceGammaRamp and SetDeviceGammaRamp API functions.
    @pGetDeviceGammaRamp :=GetProcAddress(hGDI32, 'GetDeviceGammaRamp');
    @pSetDeviceGammaRamp :=GetProcAddress(hGDI32, 'SetDeviceGammaRamp');
  //Return TRUE only if these functions exist.
    if (@pGetDeviceGammaRamp = nilor (@pSetDeviceGammaRamp = nilthen
      FreeLib()
    else result := TRUE;
  end;
end;


procedure TGammaRamp.FreeLib;
begin
  if (hGDI32 <> NULL) then begin
    FreeLibrary(hGDI32);
    hGDI32 := NULL;
  end;
end;

function TGammaRamp.LoadLibraryIfNeeded:boolean;
begin
  result := FALSE;
  if (hGDI32 = NULL) then LoadLib();
  if (@pGetDeviceGammaRamp <> Niland (@pSetDeviceGammaRamp <> Nilthen
    result:=true;
end;

function TGammaRamp.SetDeviceGammaRamp(DC:HDC; lpRamp:LPVOID):boolean;
//Call to SetDeviceGammaRamp only if this function is successfully loaded.
begin
  if (LoadLibraryIfNeeded) then
   result:= pSetDeviceGammaRamp(DC, lpRamp)
  else result := FALSE;
end;

function TGammaRamp.GetDeviceGammaRamp(DC:HDC; lpRamp:LPVOID):boolean;
//Call to GetDeviceGammaRamp only if this function is successfully loaded.
begin
  if (LoadLibraryIfNeeded) then result:= pGetDeviceGammaRamp(DC, lpRamp)
  else result := FALSE;
end;


function TGammaRamp.SetBrightness(DC:HDC;wBrightness: WORD):boolean;
{
  Changes the brightness of the entire screen.
  This function may not work properly in some video cards.

  The wBrightness value should be a number between 0 and 255.
  128 = Regular brightness
  above 128 = brighter
  below 128 = darker

    If hDC is NULL, SetBrightness automatically load and release
  the display device context for you.

}

var hGammaDC : HDC;
    GammaArray: PVOID;
    iIndex, iArrayValue: integer;
begin
  result := FALSE;
  // hdc hgammadc = hDC
  //Load the display device context of the entire screen if hDC is NULL.
  if (DC = NULL) then hGammaDC := GetDC(NULL);
  if (hGammaDC <> NULL) then begin
  //Generate the 256-colors array for the specified wBrightness value.
  //WORD GammaArray[3][256];
     for iIndex := 0 to 255 do begin
       iArrayValue := iIndex * (wBrightness + 128);
       if (iArrayValue > 65535then
         iArrayValue := 65535;
       GammaArray[0,iIndex] := WORD(iArrayValue);
       GammaArray[1,iIndex] := WORD(iArrayValue);
       GammaArray[2,iIndex] := WORD(iArrayValue);
     end;
    //Set the GammaArray values into the display device context.
    result := SetDeviceGammaRamp(hGammaDC, @GammaArray);
  end;
  if (DC = NULL) then ReleaseDC(NULL, hGammaDC);
end;

destructor TGammaRamp.Destroy;
begin
  FreeLib;
  inherited;
end;

initialization

finalization

end.



democode:

Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
var rampe: Tgammaramp;
begin
   rampe := Tgammaramp.Create;
   rampe.SetBrightness(0,64);
   rampe.FreeLib;
   rampe.free;
end;