pixelsearch Posted October 22, 2019 Posted October 22, 2019 (edited) Hi everybody I discovered 2 different ways for reverting to a background color. Here is a script that will show these 2 ways : expandcollapse popup#include <ColorConstants.au3> #include <GuiButton.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPIGdi.au3> Global $aButton_Caption[5] = _ ["Click me : Label will get a green background", _ "Click me : Reverting background color (_WinAPI_GetBkColor)", _ "Click me : Label will get a green background... again", _ "Click me : Reverting background color ($CLR_DEFAULT)", _ "Bye"] $hGUI = GUICreate("2 ways to revert back color ?", 324, 134, -1, -1, _ -1, $WS_EX_TOPMOST) $idButton = GUICtrlCreateButton($aButton_Caption[0], _ 8, 91, 307, 25) $idLabel = GUICtrlCreateLabel("Just a test label placed here", _ 93, 40, 136, 17, $SS_CENTER) GUISetState(@SW_SHOW) ; ++++++++++++ ; Keep the GUI background color in a variable. ; Gui MUST be visible (not hidden or minimized) for this function to work properly $hDC = _WinAPI_GetDC($hGUI) $iGuiBackColor = _WinAPI_GetBkColor($hDC) GUISetState(@SW_DISABLE, $hGUI) MsgBox($MB_TOPMOST, "RGB Gui background color", _ $iGuiBackColor & " (Hex " & Hex($iGuiBackColor) & ")") GUISetState(@SW_ENABLE, $hGUI) _WinAPI_ReleaseDC($hGUI, $hDC) ; ++++++++++++ $iCount = 0 While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) Exit Case $idButton $iCount += 1 Switch $iCount Case 1 GUICtrlSetBkColor($idLabel, 0xDDFFDD) ; light green Case 2 GUICtrlSetBkColor($idLabel, $iGuiBackColor) ; 0xE0DFE3 grey on my PC Case 3 GUICtrlSetBkColor($idLabel, 0xDDFFDD) ; light green... again Case 4 GUICtrlSetBkColor($idLabel, $CLR_DEFAULT) ; 0xFF000000 Case 5 GUIDelete($hGUI) Exit EndSwitch _GUICtrlButton_SetText($idButton, $aButton_Caption[$iCount]) EndSwitch WEnd Until a couple of days, I used theĀ _WinAPI_GetBkColor() way, based on one of Guinness script. Then I found recently that using $CLR_DEFAULT could do exactly the same, as you can notice in the preceding script, also in this script, where $CLR_DEFAULT is used with good results during the WM_NOTIFY function. So the question is : can we simply rely only on $CLR_DEFAULT and forget the _WinAPI_GetBkColor() way, which requires a bit more code and include files ? In case you launch the preceding script, you probably won't get the same $iGuiBackColor as mine, which is 0xE0DFE3 meaning a grey background. Depending on your windows background color, you'll get another value in MsgBox but it doesn't matter, as long as your background color is correctly reverted twice. Edited October 22, 2019 by pixelsearch "I think you are searching a bug where there is no bug... don't listen to bad advice."
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