WildByDesign Posted Friday at 04:21 PM Posted Friday at 04:21 PM I'm working on a workaround for dark mode checkbox theming issues. I'm using a simple label to click on to check and uncheck the checkbox. The only thing really missing is when holding the cursor over the Label, it would be better if that can trigger the hover state of the checkbox. Does anyone know of a way to achieve this? Example code to work with: expandcollapse popup#include <GUIConstantsEx.au3> $hGUI = GUICreate("Checkbox Example", 300, 200) ;GUISetBkColor(0x808080) $ExampleCheckbox = GUICtrlCreateCheckbox(" ", 50, 100, -1, -1) $hExampleCheckbox = GUICtrlGetHandle($ExampleCheckbox) $aPos = ControlGetPos($hGUI, "", $ExampleCheckbox) $ExampleCheckboxPosV = $aPos[1] $ExampleCheckboxPosH = $aPos[0] + $aPos[2] $ExampleCheckboxHeight = $aPos[1] + $aPos[3] $CheckboxTitleFix = 3 ; this can differ slightly depending on DPI $ExampleLabel = GUICtrlCreateLabel("Checkbox Example", $ExampleCheckboxPosH + 4, $ExampleCheckboxPosV + $CheckboxTitleFix, -1, -1) $hExampleLabel = GUICtrlGetHandle($ExampleLabel) $aPos = ControlGetPos($hGUI, "", $ExampleLabel) $ExampleLabelInfoPosV = $aPos[1] $ExampleLabelInfoPosH = $aPos[0] + $aPos[2] $ExampleLabelInfoHeight = $aPos[1] + $aPos[3] GUISetState() Func ExamplecheckBox() ; $GUI_CHECKED (1), $GUI_UNCHECKED (4) $ExampleCheckboxRead = GUICtrlRead($ExampleCheckbox) If $ExampleCheckboxRead = 4 Then GUICtrlSetState($ExampleCheckbox, $GUI_CHECKED) ElseIf $ExampleCheckboxRead = 1 Then GUICtrlSetState($ExampleCheckbox, $GUI_UNCHECKED) EndIf ; do another read to keep status $ExampleCheckboxRead = GUICtrlRead($ExampleCheckbox) EndFunc While 1 $MSG = GUIGetMsg() Select Case $MSG = $GUI_EVENT_CLOSE Exit Case $MSG = $ExampleLabel ExamplecheckBox() EndSelect WEnd
Solution ioa747 Posted Friday at 05:16 PM Solution Posted Friday at 05:16 PM for hovering the GUIGetCursorInfo() is suitable Here for example with buttons https://www.autoitscript.com/forum/topic/211721-round-buttons/#findComment-1532773 and here an example with dark Checkbox expandcollapse popup#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <WinAPIGdi.au3> #include <WinAPISysWin.au3> Global $hGUI = GUICreate("Example GUI", 975, 110, 843, 109) Global $Input = GUICtrlCreateInput("", 10, 10, 840, 90, BitOR($WS_VSCROLL, $ES_MULTILINE), 0) GUICtrlSetFont(-1, 12, 400, 0, "Consolas") Global $Button_OK = GUICtrlCreateButton("Request", 871, 30, 81, 31) Global $Button_copy = GUICtrlCreateButton("Copy", 871, 65, 81, 31) Global $ChbxDrkMode = GUICtrlCreateCheckbox("Dark mode", 871, 5, 125, 25) GUICtrlSetState(-1, 1) GUISetState(@SW_SHOW, $hGUI) DarkMode($hGUI, (GUICtrlRead($ChbxDrkMode) = 1 ? True : False)) Global $ID While 1 $ID = GUIGetMsg() Switch $ID Case $GUI_EVENT_CLOSE Exit Case $ChbxDrkMode DarkMode($hGUI, (GUICtrlRead($ChbxDrkMode) = 1 ? True : False)) Case $Button_OK ConsoleWrite("$Button_OK=" & $Button_OK & @CRLF) Case $Button_copy ConsoleWrite("$Button_copy=" & $Button_copy & @CRLF) EndSwitch WEnd ;---------------------------------------------------------------------------------------- Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked ;-------------------------------------------------------------------------------------------------------------------------------- ; https://www.autoitscript.com/forum/topic/211475-darkmode-udf-for-autoits-win32guis/#comment-1530103 ;-------------------------------------------------------------------------------------------------------------------------------- Func DarkMode($hGUI, $bDarkMode = True) ; DarkMode Local Enum $DWMWA_USE_IMMERSIVE_DARK_MODE = (@OSBuild <= 18985) ? 19 : 20 ;ConsoleWrite("$DWMWA_USE_IMMERSIVE_DARK_MODE=" & $DWMWA_USE_IMMERSIVE_DARK_MODE & @CRLF) ; DWMWA_USE_IMMERSIVE_DARK_MODE ; https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute ; Use with DwmSetWindowAttribute. Allows the window frame for this window to be drawn in dark mode colors when the dark mode system setting is enabled. ; For compatibility reasons, all windows default to light mode regardless of the system setting. ; The pvAttribute parameter points to a value of type BOOL. TRUE to honor dark mode for the window, FALSE to always use light mode. ; This value is supported starting with Windows 11 Build 22000. Local $iRet = _WinAPI_DwmSetWindowAttribute_unr($hGUI, $DWMWA_USE_IMMERSIVE_DARK_MODE, $bDarkMode) If Not $iRet Then Return SetError(1, 0, -1) _SetCtrlColorMode($Button_OK, $bDarkMode) _SetCtrlColorMode($Button_copy, $bDarkMode) _SetCtrlColorMode($Input, $bDarkMode) _WinAPI_SetWindowTheme_unr(GUICtrlGetHandle($ChbxDrkMode), 0, 0) ; this control needs the theme If $bDarkMode Then ; $hGUI GUISetBkColor(0x1B1B1B, $hGUI) ;Black ; $Input GUICtrlSetBkColor($Input, 0x2B2B2B) ;Dark slate gray GUICtrlSetColor($Input, 0xFBFBFB) ;Snow ; $ChbxDrkMode GUICtrlSetColor($ChbxDrkMode, 0xFBFBFB) ; removed to change the text color. Else ; $hGUI GUISetBkColor(0xF0F0F0, $hGUI) ; 0xF0F0F0 Honeydew ; $Input GUICtrlSetBkColor($Input, 0xFBFBFB) ; 0xFBFBFB Snow GUICtrlSetColor($Input, 0x2B2B2B) ; 0x2B2B2B Dark slate gray ; $ChbxDrkMode GUICtrlSetColor($ChbxDrkMode, 0x2B2B2B) ; 0x2B2B2B Dark slate gray EndIf _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW) WinActivate("[CLASS:Progman;]") ; To refresh the frame. WinActivate($hGUI) ; Only needed for the constant back and forth in this demo. EndFunc ;==>DarkMode ;-------------------------------------------------------------------------------------------------------------------------------- Func _SetCtrlColorMode($hWnd, $bDarkMode = True, $sName = Default) ; 'Explorer', 'CFD', 'DarkMode_ItemsView', etc. If $sName = Default Then $sName = $bDarkMode ? 'DarkMode_Explorer' : 'Explorer' $bDarkMode = Not Not $bDarkMode ; https://www.vbforums.com/showthread.php?900444-Windows-10-Dark-Mode-amp-VB6-apps If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) Local Enum $eDefault, $eAllowDark, $eForceDark, $eForceLight, $eMax ; enum PreferredAppMode DllCall('uxtheme.dll', 'bool', 133, 'hwnd', $hWnd, 'bool', $bDarkMode) ; fnAllowDarkModeForWindow = 133 DllCall('uxtheme.dll', 'int', 135, 'int', ($bDarkMode ? $eForceDark : $eForceLight)) ; fnAllowDarkModeForApp = 135 _WinAPI_SetWindowTheme_unr($hWnd, $sName) ; https://www.autoitscript.com/forum/index.php?showtopic=211475&view=findpost&p=1530103 DllCall('uxtheme.dll', 'none', 104) ; fnRefreshImmersiveColorPolicyState = 104 ; not needed ? _SendMessage($hWnd, $WM_THEMECHANGED, 0, 0) ; not needed ? EndFunc ;==>_SetCtrlColorMode ;-------------------------------------------------------------------------------------------------------------------------------- Func _WinAPI_SetWindowTheme_unr($hWnd, $sName = Null, $sList = Null) ; #include <WinAPITheme.au3> ; unthoughtful unrestricting mod. ;Causes a window to use a different set of visual style information than its class normally uses Local $sResult = DllCall('UxTheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd, 'wstr', $sName, 'wstr', $sList) If @error Then Return SetError(@error, @extended, 0) If $sResult[0] Then Return SetError(10, $sResult[0], 0) Return 1 EndFunc ;==>_WinAPI_SetWindowTheme_unr ;-------------------------------------------------------------------------------------------------------------------------------- Func _WinAPI_DwmSetWindowAttribute_unr($hWnd, $iAttribute, $iData) ; #include <WinAPIGdi.au3> ; unthoughtful unrestricting mod. ;Sets the value of the specified attributes for non-client rendering to apply to the window Local $aCall = DllCall('dwmapi.dll', 'long', 'DwmSetWindowAttribute', 'hwnd', $hWnd, 'dword', $iAttribute, _ 'dword*', $iData, 'dword', 4) If @error Then Return SetError(@error, @extended, 0) If $aCall[0] Then Return SetError(10, $aCall[0], 0) Return 1 EndFunc ;==>_WinAPI_DwmSetWindowAttribute_unr ;-------------------------------------------------------------------------------------------------------------------------------- I know that I know nothing
WildByDesign Posted Friday at 05:54 PM Author Posted Friday at 05:54 PM 36 minutes ago, ioa747 said: for hovering the GUIGetCursorInfo() is suitable That sounds good. I will do some reading on this function tonight and play around with it. 36 minutes ago, ioa747 said: and here an example with dark Checkbox Wow, thank you for sharing this. There are many really nice things all within that small script. Some really valuable stuff there that I probably have even more use for. This gives me more ideas now. ioa747 1
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