[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Available Code Version??

Posted on 2009-05-14
1
Medium Priority
?
303 Views
Last Modified: 2013-11-05
Hi there,

Please see this code attached below
http://www.nirsoft.net/vc/change_screen_brightness.html
is there a Delphi version of this?
0
Comment
Question by:_Nameless_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
KillerCode earned 500 total points
ID: 24392474
unit GammaRamp;
// translated from a c++ source on
// http://www.nirsoft.net/vc/change_screen_brightness.html
// translation by retnyg

interface

uses windows,kol;

CONST NULL = 0;

type

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

  PgammaRamp = ^TGammaRamp;
  TGammaRamp = Object(TObj)
  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;
    destructor Destroy; virtual;
  end;

function NewGammaRamp: PGammaRamp;

implementation

function NewGammaRamp: PGammaRamp;
begin
      //Initialize all variables.
  new(result,create);
  Result.hGDI32 := NULL;
  result.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 = nil) or (@pSetDeviceGammaRamp = nil) then
      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 <> Nil) and (@pSetDeviceGammaRamp <> Nil) then
    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 > 65535) then
         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;

end.


///Example Program
program Project1;

{$APPTYPE CONSOLE}

uses
  Kol,
  gammaramp in 'gammaramp.pas';

var
  rampe: PGammaRamp;
  x: integer;
begin
  UseInputOutput;
  writeln('GammaChanger 1.0 :: coded by retnyg ::');
  if paramcount = 0 then begin
    x := 128;
    writeln('Syntax: GammaChange xxx');
    writeln('i.e. GammaChange 64');
    writeln('now setting gamma to 128 (windows default)');
  end
  else begin
    x:=str2int(paramstr(1));
    writeln('setting gamma to ' + paramstr(1));
  end;
  rampe := NewGammaRamp;
  rampe.SetBrightness(0,x);
  rampe.FreeLib;
end.

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question