Popular Post NoNameCode Posted February 9, 2024 Popular Post Posted February 9, 2024 (edited) Hello everyone, today I would like to show you how far I have come with the implementation of DarkMode for AutoIT GUIs. Source: https://github.com/ysc3839/win32-darkmode About Win32 Darkmode: Since about 2020 there is a "hidden" / "undocumented" API for Win32 DarkMode. There is also already a program that has implemented this quite well. (Notepad++) Difficulties Unfortunately, the Windows devs are either too lazy or have been stupid with the implementation. So we have to apply all kinds of fixes (as we are already used to) to get the GUIs to actually run completely. Also there are some difficulties as all existing code that could be used is written in c++. I understand that, but only rudimentarily. So if there is someone here who can / would like to help me translate / implement some existing solutions. There are for example: The 'FixDarkScrollBar()' function which I would like to implement, but where I just can't get any further. Also with ChatGPT the code is difficult to 'override' and it doesn't work at all. GPT tells me that the implementation in AutoIT is quite impossible. And the full IatHook.h (https://github.com/ysc3839/win32-darkmode/blob/master/win32-darkmode/IatHook.h) Edit: Sloved witth v0.0.3 Todos / Challenges: * Redrawing of the Menu to Black * Getting the other controls into the right Theme for DarkMode * Setting Text Theme Colder of e.g. Checkboxes, ListViewHeader or Group Text * Getting Darkmode for Date Let me know what you think and where you might have suggestions for improvement or ideas. (Especially if you can help translate c++ into autoit :3) Kind Regards NoNameCode GUIDarkMode_V0.03 - OpenNcThemeData Hook.zip Changelog V.03 * Added HookOpenNcThemeData.dll => Coded by NoNameCode in C++ if someone want the Source pls DM * Added HookOpenNcThemeData_Debug.dll => Same as HookOpenNcThemeData.dll but Creates a OpenNcThemeData.txt with the opened Classes and if the Class got Replaced by Hook * Changed Darkmode_GUISample.au3 > More Data for GUICtrlCreateList and GUICtrlCreateEdit + #include <String.au3> > Added Routine to get AutoIt Install Path by Reg; or if not by @AutoItExe for PIC (logo4.gif) or AVI (SampleAVI.avi) * Changed GUIDarkMode.au3 > Added DllOpen for HookOpenNcThemeData.dll and Added OnAutoItExitRegister for DllClose function > Changed _GUICtrlSetDarkTheme -> Cleand Up Switch by CTRL Class bec. moste of them are not needed anymore through ScrollbarFix via HookOpenNcThemeData.dll Old Stuff: Spoiler Update: V0.02 GUIDarkMode_V0.02.zip Changelog V0.02 GUIDarkMode.au3 * Added Global Color Vars $GUIDARKMODE_COLOR_GUIBK / $GUIDARKMODE_COLOR_GUICTRL / $GUIDARKMODE_COLOR_GUICTRLBK * Added _GUICtrlAllSetDarkTheme * Changed _GUICtrlSetDarkTheme >> Added ClassName interpretation >> Added Auto Colering on Classname using GUIDARKMODE_COLOR_GUICTRL & GUIDARKMODE_COLOR_GUICTRLBK >> Changed use of _WinAPI_SetWindowTheme to _WinAPI_SetWindowTheme_unr (Many thanks 2 argumentum) * Changed _GUICtrlSetDarkThemeEx >> Changed use of _WinAPI_SetWindowTheme to _WinAPI_SetWindowTheme_unr (Many thanks 2 argumentum) * Changed _GUISetDarkTheme >> Changed use of DllCall to _WinAPI_DwmSetWindowAttribute_unr (Many thanks 2 argumentum) >> Added GUISetBkColor using $GUIDARKMODE_COLOR_GUIBK Darkmode_GUISample.au3 (New) * Added new GUI for Testing (Last version from mLipok 09/06/2014) #!DarkMode_TestGUI.au3 * Removed GUIDarkMode_V0.01.zip Edited February 14, 2024 by NoNameCode New Version + New Picture // Changed Titel UEZ, argumentum, ioa747 and 4 others 6 1
Werty Posted February 9, 2024 Posted February 9, 2024 (edited) Please zip all the files in a folder, the way it is now everybody first have to make a folder, then download 4 files into that folder, some may not be bothered with that and you lose out on comments. Just make a folder and put them in there, then zip the folder and upload it, much easier for everyone. Edited February 9, 2024 by Werty argumentum 1 Some guy's script + some other guy's script = my script!
argumentum Posted February 10, 2024 Posted February 10, 2024 (edited) DllCall('uxtheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd_ListviewHeadder, 'wstr', "DarkMode_ItemsView", 'wstr', Null) ; dark DllCall('uxtheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd_ListviewHeadder, 'wstr', "ItemsView", 'wstr', Null) ; light is not much and not perfect but, is good to know that we can finally paint the edge where there is no items. The rest to coloring of the header is available in the forum. Thanks for sharing. And do zip those files. Add a version or date to the filename to clearly see updates Edit: a dirty patch to show it's potential in your demo: ... ; ListView hinzufügen $idListView = GUICtrlCreateListView("Spalte 1|Spalte 2|Spalte 3", 180, 280, 200, 100) $hHeadder = _GUICtrlListView_GetHeader($idListview) _GUICtrlSetDarkTheme($hHeadder) DllCall('uxtheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hHeadder, 'wstr', "DarkMode_ItemsView", 'wstr', Null) ; dark ... Edited February 10, 2024 by argumentum more NoNameCode 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Popular Post argumentum Posted February 10, 2024 Popular Post Posted February 10, 2024 (edited) Since I'm working on updating the UDFs, I made a demo: Spoiler expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPIGdi.au3> #include <EditConstants.au3> #include <WinAPISysWin.au3> #include <WindowsConstants.au3> #include <WinAPITheme.au3> Global $hGUI, $idNote, $sNote, $iRet, $idChbxDrkMode, $idCustomColors, $idButton_Close Example() ; Win 10 onwards Func Example() ; Create a GUI with various controls. $hGUI = GUICreate("Example", 300, 200) Local Enum $DWMWA_USE_IMMERSIVE_DARK_MODE = (@OSBuild <= 18985) ? 19 : 20 ; 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. ; Create checkbox controls. $idChbxDrkMode = GUICtrlCreateCheckbox("Use Dark Mode frame", 10, 10, 125, 25) $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25) $idCustomColors = GUICtrlCreateCheckbox("custom colors on change", 145, 10, 185, 25) $sNote = @CRLF & "Clicking the checkbox allows the window frame " & _ @CRLF & " for this window to be drawn in dark mode colors" & _ @CRLF & " when the dark mode system setting is enabled." $idNote = GUICtrlCreateEdit($sNote, 10, 44, 280, 120, BitOR($ES_CENTER, $WS_HSCROLL, $WS_VSCROLL, $ES_READONLY)) If Not RegRead("HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "AppsUseLightTheme") And Not @error Then GUICtrlSetState($idChbxDrkMode, $GUI_CHECKED) ; from "Choose your default app mode". Is what Explorer uses as a reference. $iRet = _WinAPI_DwmSetWindowAttribute_unr($hGUI, $DWMWA_USE_IMMERSIVE_DARK_MODE, True) EndIf ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton_Close ExitLoop Case $idChbxDrkMode If _IsChecked($idChbxDrkMode) Then ; enable window frame dark mode $iRet = _WinAPI_DwmSetWindowAttribute_unr($hGUI, $DWMWA_USE_IMMERSIVE_DARK_MODE, True) LetsSeeTheDifference() Else ; disable window frame dark mode $iRet = _WinAPI_DwmSetWindowAttribute_unr($hGUI, $DWMWA_USE_IMMERSIVE_DARK_MODE, False) LetsSeeTheDifference() EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked Func LetsSeeTheDifference() GUICtrlSetData($idNote, $sNote & @CRLF & @CRLF & "DwmSetWindowAttribute: " & ($iRet ? 'OK' : 'Failed, see MSDN notes') & @CRLF & '(OSBuild: ' & @OSBuild & ')') If Not $iRet Then Return If _IsChecked($idCustomColors) Then SetCtrlColorMode($idButton_Close, _IsChecked($idChbxDrkMode)) SetCtrlColorMode($idNote, _IsChecked($idChbxDrkMode)) If _IsChecked($idChbxDrkMode) Then GUISetBkColor(0x222222, $hGUI) ; Default title is 0x202020 GUICtrlSetBkColor($idNote, 0x222222) ; 0x222222 is enough to look apart from the title GUICtrlSetColor($idNote, 0xE0E0E0) ; ...personal preference. _WinAPI_SetWindowTheme(GUICtrlGetHandle($idChbxDrkMode), "", "") ; this control needs the theme removed GUICtrlSetColor($idChbxDrkMode, 0xC0C0C0); to change the text color. _WinAPI_SetWindowTheme(GUICtrlGetHandle($idCustomColors), "", "") GUICtrlSetColor($idCustomColors, 0xC0C0C0) _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW) Else _WinAPI_SetWindowTheme(GUICtrlGetHandle($idChbxDrkMode), "Explorer") ; restore it's default theme _WinAPI_SetWindowTheme(GUICtrlGetHandle($idCustomColors), "Explorer") GUISetBkColor(_WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE)), $hGUI) GUICtrlSetBkColor($idNote, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_BTNFACE))) GUICtrlSetColor($idNote, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_WINDOWTEXT))) GUICtrlSetColor($idChbxDrkMode, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_WINDOWTEXT))) GUICtrlSetColor($idCustomColors, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_WINDOWTEXT))) _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW) EndIf EndIf WinActivate("[CLASS:Progman;]") ; To refresh the frame. WinActivate($hGUI) ; Only needed for the constant back and forth in this demo. EndFunc ;==>LetsSeeTheDifference 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($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_DwmSetWindowAttribute_unr($hWnd, $iAttribute, $iData) ; #include <WinAPIGdi.au3> ; unthoughtful unrestricting mod. 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 that is quite ugly code wise. Hence my participation on this thread. I like your UDF and would love to see it merged to the extent that is currently functional to the standard distribution for a next release. Would you like to make the changes to make it so ? am recruiting you 🤪 ( am not affiliated with MVPs or developers but am nonetheless bringing up ideas , and try my best to have more capable product for us all ) By the way: this demo is to showcase _WinAPI_DwmSetWindowAttribute() and since it has no examples in the help file, I made two of which this is one. Also the enumeration is based in WinXP or 7. It all needs to be updated to Win 11. Having examples help the users use the function and also, out of the attention it gets, it get's debugged and expanded Edited February 12, 2024 by argumentum better code taurus905, NoNameCode, Werty and 2 others 2 3 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
NoNameCode Posted February 10, 2024 Author Posted February 10, 2024 Hi argumentum, thank allot for your input If you set costum Colors here then it looks alredy pretty cool 😎 About your code: a) I also think that removing the theme from the checkboxes is an interesting approach. b) I looked at your demo and tested it with List(Box) and TreeView. However, I think that this does not yet work comprehensively for all GUI Ctrls that we can create in this way. c) I'll add your "Ugly" :') method to the "UDF" if that's okay with you? Furthermore: I will have a look at the source code of Notepadd++ and see how they did it and if we can adopt it. Maybe I'll also open another thread to see if we can translate the "FindDelayLoadThunkInModule" from IatHook.h, needed in "FixDarkScrollBar()". To your request: Sure, I would be happy if something of mine is included in the Autoit standard distribution. However, I would like to know which part of the code you mean and which changes you would like me to make. argumentum 1
argumentum Posted February 10, 2024 Posted February 10, 2024 @Werty's footnote, "Some guy's script + some other guy's script = my script!". Well, that's me too I only wish I could remember where I left the car keys. Or code I wrote. Or read C and go through Notepad++, but, I'm a hobbyist scripter with some memories of Borland pascal been better than MS C++. Why am I saying this., Yes, I can not do what you just did with the UDF. Is not in me, am old and naturally disorganized. The idea is to open the different standard ( build in the AutoIt distro ) UDFs and complete them / expand them, with the new enumerators in each file destined to hold them. Add/modify the existing ones so that users can have a proper wrapper for each function call. _WinAPI_DwmSetWindowAttribute_unr() is a good example of what I did but would not be proper for release as part of the product ( I call the AutoIt3 distribution "the product" ). So is not changing your UDF but find a proper way to incorporate these new ... stuff, into the pre-existing ones and naming everything in accordance to MSDN documentation, as everything should have a reference of where the coder pull this out of. And, keep everything backward compatible ( as much as possible ) . Very important. Werty, SmOke_N and NoNameCode 3 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted February 10, 2024 Posted February 10, 2024 32 minutes ago, NoNameCode said: b) I looked at your demo and tested it with List(Box) and TreeView. However, I think that this does not yet work comprehensively for all GUI Ctrls that we can create in this way. this SetCtrlColorMode(), is a simple, do most of what it needed to get it out of the way ( the button and edit controls ). I bet it'd work for the Listview headder too. But is not an effort to have what you envision/aim to get done with the example you presented. I edited it later but: 1 hour ago, argumentum said: By the way: this demo is to showcase _WinAPI_DwmSetWindowAttribute() and since it has no examples in the help file, I made two of which this is one. Also the enumeration is based in WinXP or 7. It all needs to be updated to Win 11. Having examples help the users use the function and also, out of the attention it gets, it get's debugged and expanded ...so, no, it's not an all encompassing solution but, as you shared, I saw and shared, ...who know how complete/functional can this end up been after more users get involved. No clue. After all, M$ would love to kill win32 controls and push their .NET solutions. Therefore, a proper dark mode implementation for win32controls may never have an easy fix If you look at the vbforum link in the code, maybe the Listbox control can be replaced with a Listview If the code for the listview header is there, the rest of the coloring is quite possible ( just look around in the forum ) to have a presentable Listview in dark mode. 47 minutes ago, NoNameCode said: c) I'll add your "Ugly" :') method to the "UDF" if that's okay with you? Thank you, your very kind. But as functional that blob of DllCalls is, is not production material. Each call would need a tested wrapper. It takes time to try to brake code to make it better. I just kept it short for the demo and maybe after all the wrapper are coded, I'll replace them accordingly. I wish I had more time to investigate more but IRL I have code to attend to, or no food next month Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted February 10, 2024 Posted February 10, 2024 7 minutes ago, argumentum said: I made two of which this is one This is the other demo example ( unrelated to dark mode ) for the current version of _WinAPI_DwmSetWindowAttribute() and is in a trac# to be updated too. Spoiler expandcollapse popup#include <GUIConstantsEx.au3> #include <WinAPIGdi.au3> #include <EditConstants.au3> Global $hGUI Example() Func Example() ; Create a GUI with various controls. $hGUI = GUICreate("Example", 300, 200) ; Create a checkbox control. Local $idCheckbox = GUICtrlCreateCheckbox("Disable GUI animation", 10, 10, 185, 25) Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25) GUICtrlCreateEdit(@CRLF & "Clicking the checkbox will change the transition" & _ @CRLF & " effect shown while Minimize/Restore/Maximize.", 10, 60, 280, 70, _ BitOR($ES_CENTER, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY)) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idButton_Close ExitLoop Case $idCheckbox If _IsChecked($idCheckbox) Then ; disable window animation _WinAPI_DwmSetWindowAttribute($hGUI, $DWMWA_TRANSITIONS_FORCEDISABLED, True) LetsSeeTheDifference() Else ; enable window animation _WinAPI_DwmSetWindowAttribute($hGUI, $DWMWA_TRANSITIONS_FORCEDISABLED, False) LetsSeeTheDifference() EndIf EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example Func LetsSeeTheDifference() Sleep(200) WinSetState($hGUI, "", @SW_MINIMIZE) Sleep(500) WinSetState($hGUI, "", @SW_RESTORE) EndFunc ;==>LetsSeeTheDifference Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked ..and is actually the 2nd example ( the first I've shown in this thread, that lead into the need to expand the enumerators and adjust of the function itself to accommodate the new features. 😅 And that is my story and how everything escalated. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted February 11, 2024 Posted February 11, 2024 On 2/9/2024 at 1:12 AM, NoNameCode said: The 'FixDarkScrollBar()' function which I would like to implement is this what you mean ? expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiScrollBars.au3> #include <StructureConstants.au3> #include <WindowsConstants.au3> #include <SendMessage.au3> Global $g_idMemo, $g_iUSE_IMMERSIVE_DARK_MODE Example() Func Example() Local $hGUI = GUICreate("ScrollBars Get/Set ScrollInfo (v" & @AutoItVersion & ")", 400, 400, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX)) $g_idMemo = GUICtrlCreateEdit("", 2, 2, 380, 360, BitOR($WS_HSCROLL, $WS_VSCROLL)) GUICtrlSetResizing($g_idMemo, $GUI_DOCKALL) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") GUISetBkColor(0x88AABB) Local Enum $DWMWA_USE_IMMERSIVE_DARK_MODE = (@OSBuild <= 18985) ? 19 : 20 $g_iUSE_IMMERSIVE_DARK_MODE = _WinAPI_DwmSetWindowAttribute_unr($hGUI, $DWMWA_USE_IMMERSIVE_DARK_MODE, True) If $g_iUSE_IMMERSIVE_DARK_MODE Then GUISetBkColor(0x222222) SetCtrlColorMode($g_idMemo) GUICtrlSetBkColor($g_idMemo, 0x222222) GUICtrlSetColor($g_idMemo, 0xDDDDDD) SetCtrlColorMode($hGUI) ; the scrollbar EndIf GUISetState(@SW_SHOW) _GUIScrollBars_Init($hGUI) Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO) DllStructSetData($tSCROLLINFO, "cbSize", DllStructGetSize($tSCROLLINFO)) DllStructSetData($tSCROLLINFO, "fMask", $SIF_ALL) _GUIScrollBars_GetScrollInfo($hGUI, $SB_HORZ, $tSCROLLINFO) MemoWrite("Horizontal" & @CRLF & "--------------------------------------") MemoWrite("nPage....: " & DllStructGetData($tSCROLLINFO, "nPage")) MemoWrite("nPos.....: " & DllStructGetData($tSCROLLINFO, "nPos")) MemoWrite("nMin.....: " & DllStructGetData($tSCROLLINFO, "nMin")) MemoWrite("nMax.....: " & DllStructGetData($tSCROLLINFO, "nMax")) MemoWrite("nTrackPos: " & DllStructGetData($tSCROLLINFO, "nTrackPos")) DllStructSetData($tSCROLLINFO, "cbSize", DllStructGetSize($tSCROLLINFO)) DllStructSetData($tSCROLLINFO, "fMask", $SIF_ALL) _GUIScrollBars_GetScrollInfo($hGUI, $SB_VERT, $tSCROLLINFO) MemoWrite(@CRLF & "Vertical" & @CRLF & "--------------------------------------") MemoWrite("nPage....: " & DllStructGetData($tSCROLLINFO, "nPage")) MemoWrite("nPos.....: " & DllStructGetData($tSCROLLINFO, "nPos")) MemoWrite("nMin.....: " & DllStructGetData($tSCROLLINFO, "nMin")) MemoWrite("nMax.....: " & DllStructGetData($tSCROLLINFO, "nMax")) MemoWrite("nTrackPos: " & DllStructGetData($tSCROLLINFO, "nTrackPos")) ; Set the vertical scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", $SIF_RANGE) DllStructSetData($tSCROLLINFO, "nMin", 5) DllStructSetData($tSCROLLINFO, "nMax", 80) _GUIScrollBars_SetScrollInfo($hGUI, $SB_VERT, $tSCROLLINFO) ; Set the horizontal scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", $SIF_RANGE) DllStructSetData($tSCROLLINFO, "nMin", 10) DllStructSetData($tSCROLLINFO, "nMax", 120) _GUIScrollBars_SetScrollInfo($hGUI, $SB_HORZ, $tSCROLLINFO) DllStructSetData($tSCROLLINFO, "cbSize", DllStructGetSize($tSCROLLINFO)) DllStructSetData($tSCROLLINFO, "fMask", $SIF_ALL) _GUIScrollBars_GetScrollInfo($hGUI, $SB_HORZ, $tSCROLLINFO) MemoWrite(@CRLF & "Horizontal Updated" & @CRLF & "--------------------------------------") MemoWrite("nMin.....: " & DllStructGetData($tSCROLLINFO, "nMin")) MemoWrite("nMax.....: " & DllStructGetData($tSCROLLINFO, "nMax")) DllStructSetData($tSCROLLINFO, "cbSize", DllStructGetSize($tSCROLLINFO)) DllStructSetData($tSCROLLINFO, "fMask", $SIF_ALL) _GUIScrollBars_GetScrollInfo($hGUI, $SB_VERT, $tSCROLLINFO) MemoWrite(@CRLF & "Vertical Updated" & @CRLF & "--------------------------------------") MemoWrite("nMin.....: " & DllStructGetData($tSCROLLINFO, "nMin")) MemoWrite("nMax.....: " & DllStructGetData($tSCROLLINFO, "nMax")) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Exit EndFunc ;==>Example ; Write a line to the memo control Func MemoWrite($sMessage) GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite 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) ; #include <SendMessage.au3> ; not needed ? EndFunc ;==>SetCtrlColorMode Func _WinAPI_SetWindowTheme_unr($hWnd, $sName = Null, $sList = Null) ; #include <WinAPITheme.au3> ; unthoughtful unrestricting mod. 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. 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 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
NoNameCode Posted February 11, 2024 Author Posted February 11, 2024 2 hours ago, argumentum said: is this what you mean ? @argumentum No thats not what i mean with the ScrollbarFix. Let me expand for a moment: This FixScrollBar() does the following: It sets its own function before each call of "OpenNcThemeData" within "comctl32.dll". With OpenNcThemeData each control queries its theme data. Why? Because every control asks for the class "ScrollBar" and not for "Explorer::ScrollBar". The problem is that switching on DarkMode for "ScrollBar" has no effect. To set this custom callback function, the "DelayLoadThunk" adress must be found in "comctl32.dll". However, this turns out to be extremely complex. In theory, we simply edit the ClassList that is called by OpenNcThemeData with our own function and pass the edited version to OpenNcThemeData, which then returns the result. To the GUI Scrollbars: They are "Fixed" no worries. I call GUICtrlSetDarkThem for $hGUI in GUISetDarkTheme again. argumentum 1
argumentum Posted February 11, 2024 Posted February 11, 2024 v02, cool. https://www.autoitscript.com/forum/topic/191035-combobox-set-dropdownlist-colorssize-udf/ https://www.autoitscript.com/forum/topic/191058-datetime-pick-coloring/ maybe this can help ? NoNameCode 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
NoNameCode Posted February 11, 2024 Author Posted February 11, 2024 4 minutes ago, argumentum said: v02, cool. https://www.autoitscript.com/forum/topic/191035-combobox-set-dropdownlist-colorssize-udf/ https://www.autoitscript.com/forum/topic/191058-datetime-pick-coloring/ maybe this can help ? @argumentum Looks promising, ill look at it tomorow. I have to get some Sleep x) See u soon argumentum 1
argumentum Posted February 11, 2024 Posted February 11, 2024 (edited) ..remove the hard coded path you added and put this line close to the top of the script: FileChangeDir(StringLeft(@AutoItExe, StringInStr(@AutoItExe, '\', 0, -1)) & "Examples\GUI") This way it'll work everywhere, no matter where AutoIt is installed at. and #Region COMBO GUICtrlCreateCombo("Sample Combo", 250, 80, 120, 100) GUICtrlSetTip(-1, '#Region COMBO') GUICtrlSetData(-1, "Item 2|Item 3|Item 4", "Sample Combo") ; to better see the resultant #EndRegion COMBO Edited February 11, 2024 by argumentum more Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted February 11, 2024 Posted February 11, 2024 (edited) ..this is why I need supervision, still. ( sowy mom, dad ) _WinAPI_SetWindowTheme(GUICtrlGetHandle($idCtrl), "", "") works just fine to remove a theme. Now if I pass a non-string, is not a 'wstr', maybe am passing a 'ptr' ?, good luck DLL guessing what I mean. Hence, no need to use anything other that the default UDF function. ( I figure that after the revisions it went though the years, ...my ignorance is no bliss ) Anyway, a proper unrestricted function would ( unnecessarily ) be: < removed, bad idea > Edited February 11, 2024 by argumentum oops Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Moderators SmOke_N Posted February 11, 2024 Moderators Posted February 11, 2024 1 hour ago, argumentum said: ..this is why I need supervision, still. ( sowy mom, dad ) _WinAPI_SetWindowTheme(GUICtrlGetHandle($idCtrl), "", "") works just fine to remove a theme. Now if I pass a non-string, is not a 'wstr', maybe am passing a 'ptr' ?, good luck DLL guessing what I mean. SetWindowTheme : https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-setwindowtheme those params are actually requesting pointers. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
argumentum Posted February 11, 2024 Posted February 11, 2024 5 minutes ago, SmOke_N said: those params are actually requesting pointers I wish I knew more. Ok, they request a pointer to a wstr, but we're Spartans and say, "here's the string, take it ! " ? Since what I needed is to remove the class, passing Null will not do it, either I say 'wstr' = "" or my 'ptr' = 0 How would you go about it ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Moderators SmOke_N Posted February 11, 2024 Moderators Posted February 11, 2024 I'm not sure I'm following, just read your last comment on the pointers and haven't followed the thread. However, looking at your code, then looking at the original code: Func _WinAPI_SetWindowTheme($hWnd, $sName = Default, $sList = Default) Local $sTypeOfName = 'wstr', $sTypeOfList = 'wstr' If Not IsString($sName) Then $sTypeOfName = 'ptr' $sName = 0 EndIf If Not IsString($sList) Then $sTypeOfList = 'ptr' $sList = 0 EndIf Local $aRet = DllCall('uxtheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd, $sTypeOfName, $sName, $sTypeOfList, $sList) If @error Then Return SetError(@error, @extended, 0) If $aRet[0] Then Return SetError(10, $aRet[0], 0) Return 1 EndFunc ;==>_WinAPI_SetWindowTheme Are you saying that passing NULL to name/list params that it doesn't accomplish what you're looking for? Also, you have $sTypeOfName $sTypeOfList in the list of params, then you localize the same variables, that's a bit confusing. So I'm unsure what is trying to be accomplished to even suggest or provide a solution. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
argumentum Posted February 11, 2024 Posted February 11, 2024 untested but: ( as I don't know but as a concept ) Func _WinAPI_SetWindowTheme_ByPointer($hWnd, $sName = 'Explorer', $sList = Null) Local $tName=DllStructCreate($sName) Local $pName=DllStructGetPtr($tName) Local $tList=DllStructCreate($sList) Local $pList=DllStructGetPtr($tName) Local $aRet = DllCall('uxtheme.dll', 'long', 'SetWindowTheme', 'hwnd', $hWnd, 'ptr', $pName, 'ptr', $pList) If @error Then Return SetError(@error, @extended, 0) If $aRet[0] Then Return SetError(10, $aRet[0], 0) Return 1 EndFunc would match that MSDN say it should be ? ( the current version foregoes the pointers and sends the string, but don't ask me why or how it works ) 4 minutes ago, SmOke_N said: So I'm unsure what is trying to be accomplished to even suggest or provide a solution What I wanted is to remove the theme for Checkbox to take a new text color. Google it, saw ",0, 0)" and pasted. The current version of the wrapper did not work. I thought that it was an oversight but then reading/thinking/testing, saw that I could accomplish that by passing a "" instead of a 0 . But since I already placed my foot in my mouth, I'm like, this Ex version let's the user do as he'd please and have proper error handling. 9 minutes ago, SmOke_N said: However, looking at your code, then looking at the original code: That is not the current code. Therefore was not my starting point. But I learned that later. The _WinAPI_SetWindowThemeEx() I posted above is free and open, to pass a user made string, or a user made pointer, without any checks. I don't see it as misleading rather an extended wrapper for if the user actually know what is doing. Otherwise use the standard wrapper. In any case, for what this call does, as is in the current version shows to be functional. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted February 11, 2024 Posted February 11, 2024 36 minutes ago, SmOke_N said: in the list of params, then you localize the same variables, Yes, my bad. Left overs. Thanks for telling me. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Moderators SmOke_N Posted February 11, 2024 Moderators Posted February 11, 2024 (edited) This is absolutely not tested (not even once), but if I were to code it, I'd probably approach it this way. Func _WinAPI_SetWindowThemeEx($hWnd, $vName = "Explorer", $vList = Null) Local $tSubAppName = (IsDllStruct($vName) ? $vName : Null) Local $pSubAppName = (IsPtr($vName) ? $vName : Null) Local $tSubIdList = (IsDllStruct($vList) ? $vList : Null) Local $pSubIdList = (IsPtr($vList) ? $vList : Null) ; create struct if it doesn't exist If $tSubAppName = Null Then $tSubAppName = DllStructCreate("wchar[" & BinaryLen($vName) + 1 & "]") DllStructSetData($tSubAppName, 1, $vName) EndIf ; create struct if it doesn't exist If $tSubIdList = Null Then $tSubIdList = DllStructCreate("wchar[" & BinaryLen($vList) + 1 & "]") DllStructSetData($tSubIdList, 1, $vList) EndIf ; set pointer if not passed in params If Not IsPtr($pSubAppName) Then $pSubAppName = DllStructGetPtr($tSubAppName, 1) If Not IsPtr($pSubIdList) Then $pSubIdList = DllStructGetPtr($tSubIdList, 1) Local $aRet = DllCall("uxtheme.dll", "long", "SetWindowTheme", _ "hwnd", $hWnd, _ "ptr", $pSubAppName, _ "ptr", $pSubIdList) If @error Then Return SetError(@error, @extended, 0) ; no idea why we're setting an error of 10 to a success but meh ; it should return zero on success and a positive number with $aRet[0]/hResult as the error IMO If $aRet[0] Then Return SetError(10, $aRet[0], 0) Return 1 EndFunc This is the first func I've written in AutoIt in quite some time, so please forgive if it's confusing lol... Edited February 11, 2024 by SmOke_N Had wrong var names for ptr(s) when setting DllStructGetPtr() val argumentum 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
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