Jump to content

DarkMode UDF for AutoIt's Win32GUIs


Recommended Posts

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 by Werty

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

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:   image.png.295f03e151502d452d61632264f1b1b4.png

...
; 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 by argumentum
more

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

@Werty's footnote, "Some guy's script + some other guy's script = my script!". Well, that's me too :lol:

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.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

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
attachment.php?attachmentid=187940&d=168

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 :P

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

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
#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.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

On 2/9/2024 at 1:12 AM, NoNameCode said:

The 'FixDarkScrollBar()' function which I would like to implement

is this what you mean ?
image.png.3c4d0c54d890130c85590a32c783c22a.png

#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.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

2 hours ago, argumentum said:

is this what you mean ?
image.png.3c4d0c54d890130c85590a32c783c22a.png

 

@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.

Link to comment
Share on other sites

..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 by argumentum
more

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

..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 by argumentum
oops

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • Moderators
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.

image.thumb.png.3753bd3a450c871d483a22dbfee9d6c7.png

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.

Link to comment
Share on other sites

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.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • Moderators

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.

Link to comment
Share on other sites

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.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • Moderators

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 by SmOke_N
Had wrong var names for ptr(s) when setting DllStructGetPtr() val

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.

Link to comment
Share on other sites

  • NoNameCode changed the title to DarkMode UDF for AutoIt's Win32GUIs

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...