toonboon Posted August 27, 2012 Posted August 27, 2012 (edited) Allright so from the following reddit thread I've started to work on something that does exactly what OP asks: http://www.reddit.com/r/AskReddit/comments/ywqq3/is_there_a_way_to_make_my_laptop_wallpaper_a/ Is there a way to make my laptop wallpaper a color based on my battery life? The code I got so far is working out pretty well, the hex values for the colours I'm getting are the correct values for the corresponding power level. The only issue I'm having is with the WinAPI_SetSysColors function, because it turns my redish colours into blueish colours. If anyone knows what's up and/or how to fix this, then that'd be greatly appreciated! Code below expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> $bDebug = True If $bDebug Then HotKeySet("{ESC}", "_Terminate") Global $iOldBatteryLevel = 0 $hEnd = 0x33cc33 $hStart = 0xcc3333 Global $start_r = Dec(StringMid(Hex($hStart), 3, 2)) Global $start_g = Dec(StringMid(Hex($hStart), 5, 2)) Global $start_b = Dec(StringMid(Hex($hStart), 7, 2)) Global $end_r = Dec(StringMid(Hex($hEnd), 3, 2)) Global $end_g = Dec(StringMid(Hex($hEnd), 5, 2)) Global $end_b = Dec(StringMid(Hex($hEnd), 7, 2)) While 1 Dim $info $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!.rootcimv2") $objBatt = $objWMIService.ExecQuery("Select * from Win32_Battery") For $object In $objBatt $iBatteryLevel = $object.EstimatedChargeRemaining Next ;~ If $iBatteryLevel <> $iOldBatteryLevel Then _GetBackgroundColor() _SetBackgroundColor(_GetColor($iBatteryLevel)) ;~ $iOldBatteryLevel = $iBatteryLevel ;~ EndIf Sleep(5000) WEnd Func _GetColor($iPowerLevel) $red = Round($start_r - ($start_r - $end_r) * ($iPowerLevel / (100))); $green = Round($start_g - ($start_g - $end_g) * ($iPowerLevel / (100))); $blue = Round($start_b - ($start_b - $end_b) * ($iPowerLevel / (100))); $color = StringRight(Hex($red), 2) & StringRight(Hex($green), 2) & StringRight(Hex($blue), 2) ClipPut($color) Return '0x' & $color Exit EndFunc ;==>_GetColor Func _GetBackgroundColor() Return _WinAPI_GetSysColor($COLOR_BACKGROUND) EndFunc ;==>_GetBackgroundColor Func _SetBackgroundColor($bColor) Local $iError = 0 _WinAPI_SetSysColors($COLOR_BACKGROUND, $bColor) If @error Then $iError = 1 EndIf Return SetError($iError, 0, $bColor) EndFunc ;==>_SetBackgroundColor Func _Terminate() Exit EndFunc ;==>_Terminate EDIT: Additionally, when I PixelGetColor the background and use _WinAPI_SetSysColors to set the background to the colour PixelGetColor gave me the background gets set to the correct color I tried to set it to at first. Wierd right? Edited August 27, 2012 by toonboon [right]~What can I say, I'm a Simplistic person[/right]
wyzzard Posted August 28, 2012 Posted August 28, 2012 Well I'm no expert on this but looking at the _WinAPI_SetSysColors example they use 255 (FF in hex) for red and 65535 (FFFF) for yellow (which is 255 red and 255 green) so I'm thinking that maybe it needs the colors in blue/green/red order instead of red/green/blue which would be the obvious way to do it. red would be 0x0000FF = 255 yellow (255 red and 255 green) would be 0x00FFFF which implies that blue must be 0xFF0000 I haven't tried any tests though so don't take my word on it, but based on what you say the colors are doing, it does sound like the red and blue components are swapped to me. Using the PixelGetColor probably gets them in the correct order and you send it without changing the order so it works like you think it should. Hope this helps
Moderators Melba23 Posted August 28, 2012 Moderators Posted August 28, 2012 (edited) toonboon,wyzzard is quite correct - the function calls a DLL which needs BGR while AutoIt uses RGB. I use this SRE to change the values: ConsoleWrite( StringRegExpReplace("0xEDF3FE","(.{2})(.{2})(.{2})(.{2})","$1$4$3$2") & @CRLF)But you can also do it like this if you prefer:Func _ColorConvert($nColor) ; RGB to BGR or BGR to RGB Return _ BitOR(BitShift(BitAND($nColor, 0x000000FF), -16), _ BitAND($nColor, 0x0000FF00), _ BitShift(BitAND($nColor, 0x00FF0000), 16)) EndFuncM23 Edited November 11, 2013 by Melba23 Forum stripped backslashes - replaced by $ Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now