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

Windows specific forum
jrw
User
User
Posts: 24
Joined: Fri Jul 18, 2003 6:25 pm

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

Post 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?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

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

Post 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...
jrw
User
User
Posts: 24
Joined: Fri Jul 18, 2003 6:25 pm

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

Post 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.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post 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!
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

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

Post 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
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post 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 :)
"Have you tried turning it off and on again ?"
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

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

Post by Kwai chang caine »

Works fine on VISTA
Thanks LUIS 8)
ImageThe happiness is a road...
Not a destination
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

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

Post 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.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

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

Post 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:
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

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

Post by MachineCode »

c4s wrote:so is the post you've quoted. ;)
And your point is?
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

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

Post 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 ;-)
"Have you tried turning it off and on again ?"
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

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

Post 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!
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Post Reply