AutoHotkey Community

It is currently May 26th, 2012, 7:14 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: May 21st, 2008, 8:27 am 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
I'm trying to success my long hope. Lexikos adviced me on this issue
basically i'm trying to use these two API GetDeviceGammaRamp & SetDeviceGammaRamp
Code:
;from MSDN
;lpRamp : Pointer to a buffer containing the gamma ramp to be set. The gamma ramp is specified in three arrays of 256 WORD elements each, which contain the mapping between RGB values in the frame buffer and digital-analog-converter (DAC) values. The sequence of the arrays is red, green, blue. The RGB values must be stored in the most significant bits of each WORD to increase DAC independence.

BOOL WINAPI GetDeviceGammaRamp(
  HDC hDC,
  LPVOID lpRamp
);

BOOL WINAPI SetDeviceGammaRamp(
  HDC hDC,
  LPVOID lpRamp
);
my poorly try is here
Code:
hDC := DllCall("GetDC", "Int", 0)
VarSetCapacity(Gamma, 1536)
Result := DllCall("GetDeviceGammaRamp", "UInt", hdc, "UInt", &Gamma)
it returns 1 which is boolen True but i don't get the values in Gamma variable
i really don't get the numget/numput things.
but can anyone make me advance on this issue? i'm trying this simple dllcall for over a month :(
hope i get advance this time.

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Last edited by heresy on June 10th, 2008, 1:26 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2008, 12:30 pm 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3328
Location: Simi Valley, CA
Code:
hDC := DllCall("GetDC", "UInt", 0)
VarSetCapacity(Gamma, 256 * 3 * 2)
Result := DllCall("GetDeviceGammaRamp", "UInt", hdc, "UInt", &Gamma)
loop 768
   result .= (Mod(A_Index-1, 16) ? "`t" : "`n") NumGet(Gamma, 2*A_Index-1, "UShort")
msgbox % result

Though I'm not sure what you'd do with such a thing...

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2008, 2:15 pm 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
thanks for answer [VxE] and hi again.
you're the only answerer for this issue for past one month :(
as i told you, my goal is controlling brightness
i thought like GetDeviceGammaRamp would store 'current gamma' into variable.
but it seems not. what should i pass to SetDeviceGammaRamp then?
Code:
hDC := DllCall("GetDC", "UInt", 0)
VarSetCapacity(Gamma, 256 * 3 * 2)
Result := DllCall("GetDeviceGammaRamp", "UInt", hdc, "UInt", &Gamma)
loop 768
   result .= (Mod(A_Index-1, 16) ? "`t" : "`n") NumGet(Gamma, 2*A_Index-1, "UShort")
msgbox % result
NewGamma := NumGet(Gamma, 2*768-1, "UShort")
Result := DllCall("SetDeviceGammaRamp", "UInt", hdc, "UInt", &NewGamma)
msgbox % result ;failed
although i don't fully understand Numget/Numput things i was trying to get the value at the end of array and pass to SetDeviceGammaRamp
but failed. i just can't believe that we don't have wrapper for this. :(

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2008, 5:22 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
There are various ways to alter the gamma ramp, but what nirsoft does is this:
Code:
br := 128   ; brightness, in the range of 0 - 255, where 128 is normal
VarSetCapacity(gr, 512*3)
Loop,   256
{
   If  (nValue:=(br+128)*(A_Index-1))>65535
        nValue:=65535
   NumPut(nValue, gr,      2*(A_Index-1), "Ushort")
   NumPut(nValue, gr,  512+2*(A_Index-1), "Ushort")
   NumPut(nValue, gr, 1024+2*(A_Index-1), "Ushort")
}
hDC := DllCall("GetDC", "Uint", 0)
DllCall("SetDeviceGammaRamp", "Uint", hDC, "Uint", &gr)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2008, 10:37 pm 
Offline
User avatar

Joined: October 7th, 2006, 8:45 am
Posts: 3328
Location: Simi Valley, CA
lulz:
Code:
br := 128   ; brightness, in the range of 0 - 255, where 128 is normal
#WheelUp::
#WheelDown::
br += (InStr(A_ThisHotkey, "down") ? -8 : 8 )
If ( br > 256 )
   br := 256
If ( br < 0 )
   br := 0
VarSetCapacity(gr, 512*3)
Loop,   256
{
   If  (nValue:=(br+128)*(A_Index-1))>65535
        nValue:=65535
   NumPut(nValue, gr,      2*(A_Index-1), "Ushort")
   NumPut(nValue, gr,  512+2*(A_Index-1), "Ushort")
   NumPut(nValue, gr, 1024+2*(A_Index-1), "Ushort")
}
hDC := DllCall("GetDC", "Uint", 0)
DllCall("SetDeviceGammaRamp", "Uint", hDC, "Uint", &gr)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
return

so that's how it works :P

_________________
Ternary (a ? b : c) guide     TSV Table Manipulation Library
Post code inside [code][/code] tags!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 2:01 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
BTW, I was not aware of (G)SetDeviceGammaRamp API before. I only knew IDirectDrawGammaControl object which I suspect the above APIs are wrapping.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 7:04 am 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
Thanks for the answer Sean and welcome back.

that's exactly what i was trying for past few weeks. it works perfectly!
now we have wrapper for Gamma Ramp. :)
this thread will be referenced many times from now as an answer thread for all the brightness control questions
i just couldn't believe that nobody was interesting on brightness control since autohotkey's born
once again, thanks for your help almighty Sean and thanks to [VxE] too.
--------
for studying purpose.
i coudln't get the Loop part. i just don't get that where the 65535 came from.
i mean why is it 256*256-1? if anyone can enlighten me on this. please

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 2:30 pm 
heresy wrote:
i just don't get that where the 65535 came from. i mean why is it 256*256-1?

65535, 0xFFFF in hex, is the highest possible unsigned short integer. If omitting the step, the actually assigned values for integers greater than 65535 will be totally different (lower) ones as the hi-word part will be truncated when casted into ushort. E.g., 65536 will be 0, 65537 will be 1 etc. I think this will result in failure.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 2:31 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
The above post was by me.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 22nd, 2008, 4:29 pm 
Offline

Joined: March 11th, 2008, 11:36 pm
Posts: 291
Thanks for your help Sean
i didn't aware of that because i haven't experienced static typing languages before
much appreciated and it was good to see you coming back

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 23rd, 2008, 12:40 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
heresy wrote:
Thanks for your help Sean
i didn't aware of that because i haven't experienced static typing languages before
much appreciated and it was good to see you coming back

I can't stay in front of computer for long now, so I'm dubious that I'll be able to visit the forum frequently. Anyway thanks for the warm welcome.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2009, 11:52 pm 
I added a progress bar to change the brightness, but I have it slightly wrong shows progress, who can help

Code:
#NoTrayIcon    ; не отображать иконку скрипта в трее
#MaxHotkeysPerInterval 200
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
SetBatchLines -1

br := 128   ; brightness, in the range of 0 - 255, where 128 is normal

#F2::
#F1::
Brght_Step = 8

; -------------------
; START CONFIGURATION
; -------------------
; The percentage by which to raise or lower the volume each time
; How long to display the volume level bar graphs (in milliseconds)
vol_DisplayTime = 1500
; Transparency of window (0-255)
vol_TransValue = 200
; Bar's background colour
vol_CW = EEEEEE   
vol_Width = 200  ; width of bar
vol_Thick = 20   ; thickness of bar
; Bar's screen position
vol_PosX := A_ScreenWidth/2 - vol_Width/2
vol_PosY := A_ScreenHeight/1.8 - vol_Thick/2
; --------------------
; END OF CONFIGURATION
; --------------------
vol_BarOptionsMaster = 1:B1 ZH%vol_Thick% ZX8 ZY4 W%vol_Width% X%vol_PosX% Y%vol_PosY% CW%vol_CW%


br += (InStr(A_ThisHotkey, "F1") ? -Brght_Step : Brght_Step )
If ( br > 256 )
   br := 256
If ( br < 0)
   br := 0
VarSetCapacity(gr, 512*3)
Loop,   256
{
   If  (nValue:=(br+128)*(A_Index-1))>65535
        nValue:=65535
   NumPut(nValue, gr,      2*(A_Index-1), "Ushort")
   NumPut(nValue, gr,  512+2*(A_Index-1), "Ushort")
   NumPut(nValue, gr, 1024+2*(A_Index-1), "Ushort")
}
hDC := DllCall("GetDC", "Uint", 0)
DllCall("SetDeviceGammaRamp", "Uint", hDC, "Uint", &gr)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)


vol_ShowBars:
; Get volumes in case the user or an external program changed them:
vol_Master := br
if vol_Master <> 128
{
  vol_Colour = Blue   
  vol_Text = Brightness
}
else
{
;  vol_Colour = Red
  vol_Text = Brightness (normal)

}


; To prevent the "flashing" effect, only create the bar window if it doesn't already exist:
IfWinNotExist, BrightnessOSDxyz
{
    Progress, %vol_BarOptionsMaster% CB%vol_Colour% CT%vol_Colour%, , %vol_Text%, BrightnessOSDxyz
    WinSet, Transparent, %vol_TransValue%, BrightnessOSDxyz
}


Progress, 1:%vol_Master% , , %vol_Text%
SetTimer, vol_BarOff, %vol_DisplayTime%
return


vol_BarOff:
SetTimer, vol_BarOff, off
Progress, 1:Off
return


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 5th, 2010, 7:36 pm 
Offline

Joined: June 14th, 2009, 7:48 pm
Posts: 331
Just what I was looking for :
How to solve my Gamma problem.
Control Gamma's monitor with AHK
Spent much time to find a way to do it.
Thank you a lot.
It's far above my head.

I tried to change the bar color to show blue when below 128

Red when above
Green when 128 (Normal)
Add a F1 hotkey to reset to normal 128
Changes F1 F2 hotkey to - +
All those 3 shortcuts are the default PowerStrip Shortcut.
Failed in everything.
But anyways it'll do what's needed : control Gamma.


GGG RRR EEE AAA TTT ! ! !
Yeah :P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 5th, 2010, 8:53 pm 
Will this provide the option/configuration to display the desktop in greyscale, if yes - how?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 6th, 2010, 6:23 am 
Offline

Joined: June 14th, 2009, 7:48 pm
Posts: 331
Well, I did change the progress bar color to
Blue when below 128
Green when 128 (Normal)
Red when above
And Hotkeys are
F1:: ; reduce the brightness F1
F2:: ; increase the brightness F2
here is the code :
Code:
;#NoTrayIcon    don't display the script icon in the tray
#MaxHotkeysPerInterval 200
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force



SetBatchLines -1



br := 128   ; brightness, in the range of 0 - 255, where 128 is normal

F1:: ; reduce the brightness  F1
F2:: ; increase the brightness F2
Brght_Step = 8

; -------------------
; START CONFIGURATION
; -------------------
; The percentage by which to raise or lower the volume each time
; How long to display the volume level bar graphs (in milliseconds)
vol_DisplayTime = 1500
; Transparency of window (0-255)
vol_TransValue = 200
; Bar's background colour
vol_CW = EEEEEE   
vol_Width = 200  ; width of bar
vol_Thick = 20   ; thickness of bar
; Bar's screen position
vol_PosX := A_ScreenWidth/2 - vol_Width/2
vol_PosY := A_ScreenHeight/1.8 - vol_Thick/2
; --------------------
; END OF CONFIGURATION
; --------------------
vol_BarOptionsMaster = 1:B1 ZH%vol_Thick% ZX8 ZY4 W%vol_Width% X%vol_PosX% Y%vol_PosY% CW%vol_CW%


br += (InStr(A_ThisHotkey, "F1") ? -Brght_Step : Brght_Step )
If ( br > 256 )
   br := 256
If ( br < 0)
   br := 0
VarSetCapacity(gr, 512*3)
Loop,   256

{
   If  (nValue:=(br+128)*(A_Index-1))>65535
        nValue:=65535
   NumPut(nValue, gr,      2*(A_Index-1), "Ushort")
   NumPut(nValue, gr,  512+2*(A_Index-1), "Ushort")

   NumPut(nValue, gr, 1024+2*(A_Index-1), "Ushort")
}
hDC := DllCall("GetDC", "Uint", 0)
DllCall("SetDeviceGammaRamp", "Uint", hDC, "Uint", &gr)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)


vol_ShowBars:
; Get volumes in case the user or an external program changed them:
vol_Master := br
if vol_Master > 128
{
  vol_Colour = Red   
  vol_Text = Brightness
}
if vol_Master < 128
{
  vol_Colour = Blue   
  vol_Text = Brightness
}

else
{
if vol_Master = 128
  vol_Colour = Green
  vol_Text = Brightness (normal)

}


; To prevent the "flashing" effect, only create the bar window if it doesn't already exist:

IfWinNotExist, BrightnessOSDxyz
{
    Progress, %vol_BarOptionsMaster% CB%vol_Colour% CT%vol_Colour%, , %vol_Text%, BrightnessOSDxyz
    WinSet, Transparent, %vol_TransValue%, BrightnessOSDxyz
}


Progress, 1:%vol_Master% ,, %vol_Text%
SetTimer, vol_BarOff, %vol_DisplayTime%

return


vol_BarOff:
SetTimer, vol_BarOff, off


Progress, 1:Off
return

Finally I progressed a bit to make the code do more of what I want :oops: :
F1:: ; reduce the brightness F1
F2:: ; Reset to 50%
F3:: ; increase the brightness F3
Display Brighness progression in %
The progression is ok now. In the previous code the display was not accurate.
I moved the bar down center just above the task bar : It was in the screen center, eventually masking watching movie when called.
Lost color changing.
eg: 50% : green, increase : red, decrease : blue.
I still plan to have it back someday, when able to do it.
Code:
;#NoTrayIcon    don't display the script icon in the tray
#MaxHotkeysPerInterval 200
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
SetBatchLines -1
F2:: ; Set Brightness back to 50 % F2
br := 120 ; brightness, in the range of 0 - 255, where 128 is normal



F1:: ; reduce the brightness  F1
F3:: ; increase the brightness F3
Brght_Step = 8

; -------------------
; START CONFIGURATION
; -------------------
; The percentage by which to raise or lower the volume each time
; How long to display the volume level bar graphs (in milliseconds)
vol_DisplayTime = 1500
; Transparency of window (0-255)
vol_TransValue = 200
; Bar's background colour
vol_CW = EEEEEE   
vol_Width = 300  ; width of bar
vol_Thick = 20   ; thickness of bar
; Bar's screen position
vol_PosX := A_ScreenWidth/2 - vol_Width/2
vol_PosY := A_ScreenHeight/1.08 - vol_Thick/2
; --------------------
; END OF CONFIGURATION
; --------------------
vol_BarOptionsMaster = 1:B1 ZH%vol_Thick% ZX8 ZY4 W%vol_Width% X%vol_PosX% Y%vol_PosY% CW%vol_CW%


br += (InStr(A_ThisHotkey, "F1") ? -Brght_Step : Brght_Step )
If ( br > 256 )
   br := 256 
If ( br < 0)
   br := 0   
VarSetCapacity(gr, 512*3)
Loop, 256
{
   If  (nValue:=(br+128)*(A_Index-1))>65535
        nValue:=65535
   NumPut(nValue, gr,      2*(A_Index-1), "Ushort")
   NumPut(nValue, gr,  512+2*(A_Index-1), "Ushort")
   NumPut(nValue, gr, 1024+2*(A_Index-1), "Ushort")
}
hDC := DllCall("GetDC", "Uint", 0) ;NULL for entire screen
DllCall("SetDeviceGammaRamp", "Uint", hDC, "Uint", &gr)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)




vol_ShowBars:
; Get volumes in case the user or an external program changed them:
vol_Master := (br/2.5)
vbr := (br*100)//256 
if vol_Master = 128
{
  vol_Colour = Green
  vol_Text = Brightness %vbr%`%
}

if vol_Master > 128
{
  vol_Colour = Red   
  vol_Text = Brightness %vbr%`%
}
if vol_Master < 128
{
  vol_Colour = Blue

  vol_Text = Brightness %vbr%`%
}

; To prevent the "flashing" effect, only create the bar window if it doesn't already exist:
IfWinNotExist, BrightnessOSDxyz
{
    Progress, %vol_BarOptionsMaster% CB%vol_Colour% CT%vol_Colour%, , %vol_Text%, BrightnessOSDxyz
    WinSet, Transparent, %vol_TransValue%, BrightnessOSDxyz
}


Progress, 1:%vol_Master% ,, %vol_Text%
SetTimer, vol_BarOff, %vol_DisplayTime%
return


vol_BarOff:
SetTimer, vol_BarOff, off
Progress, 1:Off
return

Thanks to all the coders, see previous posts, for this useful code.


Last edited by awannaknow on May 13th, 2010, 9:54 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], bobbysoon, kkkddd1 and 66 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group