Page 1 of 1

How do I change the brightness/contrast/gamma of the desktop

Posted: Fri Jul 18, 2003 6:27 pm
by jrw
Ive looked everywhere but cannot find how to change the brightness,contrast and gamma of the windows desktop. Ive looked at the win32 api help file and I still cannot find a call which will do this.


Is this possible?

Re: How do I change the brightness/contrast/gamma of the des

Posted: Fri Jul 18, 2003 7:44 pm
by GPI
jrw wrote:Ive looked everywhere but cannot find how to change the brightness,contrast and gamma of the windows desktop. Ive looked at the win32 api help file and I still cannot find a call which will do this.


Is this possible?
Mabye because windows can't do this, because your VGA-driver will add this features.

And i Don't like programms, that change my complete PC...

Re: How do I change the brightness/contrast/gamma of the des

Posted: Sat Jul 19, 2003 2:34 am
by jrw
GPI wrote:
jrw wrote:Ive looked everywhere but cannot find how to change the brightness,contrast and gamma of the windows desktop. Ive looked at the win32 api help file and I still cannot find a call which will do this.


Is this possible?
Mabye because windows can't do this, because your VGA-driver will add this features.

And i Don't like programms, that change my complete PC...
So you dont like powerstrip? ...

I just want to write a small utility to change the gamma/desktop and have several profiles.

Re: How do I change the brightness/contrast/gamma of the des

Posted: Wed Aug 31, 2005 11:18 pm
by luis
jrw wrote:Ive looked everywhere but cannot find how to change the brightness,contrast and gamma of the windows desktop. Ive looked at the win32 api help file and I still cannot find a call which will do this.

Is this possible?
Try looking for Get/SetDeviceGammaRamp in the WinAPI

http://msdn.microsoft.com/library/defau ... m_0yi8.asp

http://www.nirsoft.net/vc/change_screen_brightness.html

I had the same idea some time ago :-)

Ciao!

Re: How do I change the brightness/contrast/gamma of the des

Posted: Wed Mar 16, 2011 11:09 pm
by Mistrel
I'm also looking to use this API but I keep getting a "The parameter is incorrect" error. Does anyone have some working sample code?

I want to adjust the gamma for everything displayed to the screen, not just one window:

Code: Select all

Procedure.s ShowAPIError(CustomError=#False, ErrorCode=0)
  Protected Buffer.s
  Protected NumberOfChars
  
  If Not CustomError
    ErrorCode=GetLastError_()
  EndIf
  
  Buffer.s=Space(4096)
  NumberOfChars=FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM,0,ErrorCode,0,Buffer.s,Len(Buffer.s),0)
  
  ProcedureReturn Left(Buffer.s,NumberOfChars-2)
EndProcedure

; Mem=AllocateMemory(SizeOf(Byte)*3)
; PokeL(Mem+SizeOf(Byte)*0,140)
; PokeL(Mem+SizeOf(Byte)*0,140)
; PokeL(Mem+SizeOf(Byte)*0,140)

; Dim GammaRamp(3,256)

Mem=AllocateMemory(SizeOf(Byte)*3*256)

Debug SetDeviceGammaRamp_(GetDC_(0),@Mem)

Debug ShowAPIError()

Repeat
  Delay(1)
ForEver

Re: How do I change the brightness/contrast/gamma of the des

Posted: Wed Mar 16, 2011 11:39 pm
by luis
Try this:

Code: Select all

Procedure.s ShowAPIError(CustomError=#False, ErrorCode=0)
  Protected Buffer.s
  Protected NumberOfChars
 
  If Not CustomError
    ErrorCode=GetLastError_()
  EndIf
 
  Buffer.s=Space(4096)
  NumberOfChars=FormatMessage_(#FORMAT_MESSAGE_FROM_SYSTEM,0,ErrorCode,0,Buffer.s,Len(Buffer.s),0)
 
  ProcedureReturn Left(Buffer.s,NumberOfChars-2)
EndProcedure



value = 64

Dim iGammaRamp.w(2,255)

For i = 0 To 255
 iArrayValue = i * (value + 128)

 If iArrayValue > 65535
    iArrayValue  = 65535
 EndIf
  
 iGammaRamp(0,i) = iArrayValue  
 iGammaRamp(1,i) = iArrayValue  
 iGammaRamp(2,i) = iArrayValue   

Next

Debug SetDeviceGammaRamp_(GetDC_(0),@iGammaRamp())

Debug ShowAPIError()

Repeat
  Delay(1)
ForEver
It works on my nVidia card.


EDIT: WOW, just noticed I have posted code for an API I was talking about 6 years ago, and that one was my first post too ! The circle is complete :)

Re: How do I change the brightness/contrast/gamma of the des

Posted: Thu Mar 17, 2011 9:02 am
by Kwai chang caine
Works fine on VISTA
Thanks LUIS 8)

Re: How do I change the brightness/contrast/gamma of the des

Posted: Thu Mar 17, 2011 9:13 am
by MachineCode
jrw wrote:Ive looked at the win32 api help file and I still cannot find a call which will do this
The Win32.hlp file has HUNDREDS of missing APIs. It's really old. Use the online MSDN search instead.

Re: How do I change the brightness/contrast/gamma of the des

Posted: Thu Mar 17, 2011 10:31 am
by c4s
MachineCode wrote:
jrw wrote:Ive looked at the win32 api help file and I still cannot find a call which will do this
The Win32.hlp file has HUNDREDS of missing APIs. It's really old. Use the online MSDN search instead.
...so is the post you've quoted. ;)


Btw: Nice code, working great on XP. But how can I set the gamma level back to normal? :shock:

Re: How do I change the brightness/contrast/gamma of the des

Posted: Thu Mar 17, 2011 10:53 am
by MachineCode
c4s wrote:so is the post you've quoted. ;)
And your point is?

Re: How do I change the brightness/contrast/gamma of the des

Posted: Thu Mar 17, 2011 1:53 pm
by luis
c4s wrote: But how can I set the gamma level back to normal? :shock:
I used this code:

http://www.nirsoft.net/vc/change_screen_brightness.html

value = 128 normal, < 128 darker, > 128 lighter

I suppose you can also use the GetDeviceGammaRamp() api to save the current settings and restore them if needed.

You can also alter RGB components separately to enhance/reduce a specific color channel.

BTW: this api was listed in the good old win32.hlp ;-)

Re: How do I change the brightness/contrast/gamma of the des

Posted: Thu Mar 17, 2011 8:50 pm
by c4s
luis wrote:
c4s wrote: But how can I set the gamma level back to normal? :shock:
I used this code:

http://www.nirsoft.net/vc/change_screen_brightness.html

value = 128 normal, < 128 darker, > 128 lighter

I suppose you can also use the GetDeviceGammaRamp() api to save the current settings and restore them if needed.

You can also alter RGB components separately to enhance/reduce a specific color channel.

BTW: this api was listed in the good old win32.hlp ;-)
I already saw GetDeviceGammaRamp_() but it doesn't make much sense after successfully testing your code. ;)

Well, I found it out myself by testing some values after I wrote my question. I just wasn't sure about 127 or 128...thanks anyway!