Jump to content

Recommended Posts

Posted (edited)
4 hours ago, xuankhanh1982 said:

@water

The output file "test_stripped.au3" is attached in the post above.

@water was asking about output from SciTE console from the compilation process especially log for Au3Stripper not the result au3 file.

I was confused too, as Water is.
As you was asking about helps with your script form here which fires a ton of Au3Check errors and variables names was so short so at first glance I asked about version before stripping.

But then I realize what is the problem as I spent many hours on such issues together with my friend @Jos
Because of this I already sent the SciTE output to Water, and you should find it on your screen and confirm to Water that this is the same case as you was requested or other one.... but then please send us yours SciTE console output.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)

@WildByDesign

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3> #include
<WindowsConstants.au3
> #include <GUIDarkTheme.au3>
#Sử dụng đất
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_AU3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/rm /sv /sf
#Kết thúc
Sử dụng $g_DpiRatio = _ApplyDpiScaling()
Một()
Hàm a()
Bộ biến cục bộ $flag_light = Sai, $flag_dark = Sai
$Form1 = GUICreate("Form1", 615*$g_DpiRatio, 437*$g_DpiRatio, -1, -1, $ws_sysmenu)
GUISetIcon("shell32.dll", -278)
$input = GUICtrlCreateInput(@SystemDir, 65, 5, 340, 20)
GUICtrlSetState(-1, 128)
$disable_input = GUICtrlCreateButton("Disable Input", 60, 40, 100, 35)
$emable_input = GUICtrlCreateButton("Emable Input", 180, 40, 100, 35)
$Combo1 = GUICtrlCreateCombo("None", 168, 168, 129, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Combo1|Combo2|Combo3", "Combo1")
$about = GUICtrlCreateButton("About", 20, 264, 75, 40)
$msbox = GUICtrlCreateButton("MsgBox", 110, 264, 75, 40)
$Button1 = GUICtrlCreateButton("Button1", 200, 264, 75, 40)
$mode_light = GUICtrlCreateRadio("Mode Light", 360, 110, Default, 15)
$mode_dark = GUICtrlCreateRadio("Mode Dark", 360, 135, Default, 15)
GUICtrlSetState(-1, 1)
$lb = GUICtrlCreateLabel("Label1", 50, 150, Default, 15)
$Group1 = GUICtrlCreateGroup("Group1", 350, 40, 113, 49)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Tab1 = GUICtrlCreateTab(352*$g_DpiRatio, 240*$g_DpiRatio, 153*$g_DpiRatio, 80*$g_DpiRatio)
$TabSheet1 = GUICtrlCreateTabItem("config")
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 360, 270, 100, 15)
;~ GUICtrlSetBkColor(-1, 0xFF0000)
$TabSheet2 = GUICtrlCreateTabItem("TabSheet1")
GUICtrlCreateTabItem("")
_GUIDarkTheme_ApplyDark($Form1)
;~ _GUIDarkTheme_ApplyLight($Form1)
;~ GUICtrlSetBkColor($Combo1, $__DM_g_iCtrlBkColor)
GUISetState(@SW_SHOW)
Trong khi 1
    $nMsg = GUIGetMsg()
    Tắc Công $nMsg
        Trường hợp $GUI_EVENT_CLOSE
            Ra
        Trường hợp $disable_input
            GUICtrlSetState($input, 128)
        Trường $emable_input
            GUICtrlSetState($input,64)
        Trường $mode_light
            Nếu ($flag_light = False) thì
                _GUIDarkTheme_SwitchTheme($Form1)
                $flag_light = True
                $flag_dark = False
            EndIf
        Trường $mode_dark
            Nếu ($flag_dark = False) thì
                _GUIDarkTheme_SwitchTheme($Form1)
                $flag_dark = True
                $flag_light = False
            EndIf
        Trường hợp $Button1
;~ b()
        Trường $msbox
            _GUIDarkTheme_MsgBox(64+262144, " Điểm ", " Chào bạn đến với diễn đàn AutoIT!", 0, $Form1)
        Trường bảo $
            about($Form1, GUICtrlRead($mode_light), GUICtrlRead($mode_dark))
    Công tắc cuối
Thứ tư
EndFunc
Func about($i_hwnd, $light, $dark)
    Local $gui_about[4], $ms_about, $iwidth_about = 252
    $gui_about[0] = GUICreate("About", $iwidth_about*$g_DpiRatio, 150*$g_DpiRatio, -1, -1, $ws_sysmenu, $ws_ex_topmost, $i_hwnd)
    GUISetIcon("shell32.dll", -222)
    $gui_about[1] = GUICtrlCreateIcon("shell32.dll", -222, 21*$g_DpiRatio, 23*$g_DpiRatio, 32*$g_DpiRatio, 32*$g_DpiRatio)
    $gui_about[2] = GUICtrlCreateLabel(" Chào mừng bạn đến với diễn đàn AutoIT!", 62*$g_DpiRatio, 32*$g_DpiRatio, ($iwidth_about - 85)*$g_DpiRatio, 15*$g_DpiRatio)
    GUICtrlSetFont(-1, 9, 400, 0, "Segoe UI")
    $gui_about[3] = GUICtrlCreateButton("OK", ($iwidth_about - 96)*$g_DpiRatio, 88*$g_DpiRatio, 75*$g_DpiRatio, 23*$g_DpiRatio, BitOR($bs_center, $bs_vcenter))
    Nếu ($light = 1) thì
        _GUIDarkTheme_ApplyLight($gui_about[0])
    ElseIf ($dark = 1) Then
        _GUIDarkTheme_ApplyDark($gui_about[0])
    EndIf
    GUISetState()
    Trong khi 1
        $ms_about = GUIGetMsg()
        Nếu ($ms_about = $gui_about[3]) Hoặc ($ms_about = $gui_event_close) Thì
            GUISetState(64, $i_hwnd)
            không vòng xoay
        EndIf
    Thứ tư
    GUIDelete($gui_about[0])
EndFunc
Func b()
$Form2 = GUICreate("Form2", 389*$g_DpiRatio, 188*$g_DpiRatio, 192, 124)
GUISetIcon("shell32.dll", -155)
$Button2 = GUICtrlCreateButton("Button2", 152, 120, 73, 33)
$Label2 = GUICtrlCreateLabel("Label2", 104, 48, Default, 15)
$Checkbox2 = GUICtrlCreateCheckbox("Checkbox2", 248, 48, 65, 25)
$Radio2 = GUICtrlCreateRadio("Radio2", 288, 128, 57, 25)
$List2 = GUICtrlCreateList("6556565", 24, 88, 97,45)
_GUIDarkTheme_ApplyDark($Form2)
;~ _GUIDarkTheme_ApplyLight($Form2)
GUISetState(@SW_SHOW)
Trong khi 1
    $nMsg = GUIGetMsg()
    Công tắc $nMsg
        Trường hợp $GUI_EVENT_CLOSE
            không vòng xoay
        Hợp nhất trường $Button2
            Biến cục bộ $sMsg = "GUIDarkTheme UDF" & @CRLF
            $sMsg &= "Phiên bản: " & @TAB & _GUIDarkTheme_Version()
            _GUIDarkTheme_MsgBox(64+262144, " Giới thiệu", $sMsg, 0, $Form2)
    Công Tin
cuối cùng Thứ Tư
GUIDelete($Form2)
EndFunc
Func _ApplyDpiScaling()
    Hằng số địa phương $DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = - 2
    __DM_WinAPI_SetProcessDpiAwarenessContext($DPI_AWARENESS_CONTEXT_SYSTEM_AWARE)
    $iDPI cục bộ = Round(__DM_WinAPI_GetDpiFromDpiAwarenessContext($DPI_AWARENESS_CONTEXT_SYSTEM_AWARE)/96, 2)
    @error thì $iDPI = 1
    Trả lời về $iDPI
EndFunc ;==>_ApplyDpiScaling

Làm cách nào để tạo thông báo "GUICreate" trùng lặp màu nền với màu nền của hàm "_GUIDarkTheme_MsgBox"?
Vì hàm "_GUIDarkTheme_MsgBox" có nhiều hạn chế nên tôi không thể sử dụng nó và buộc phải tạo một "GUICreate" với nhiều tùy chọn hơn, như hình ảnh bên dưới.

https://ibb.co/GQQSWfJy

Edited by xuankhanh1982
Posted (edited)
2 hours ago, xuankhanh1982 said:

@water

The output file "test_stripped.au3" is attached in the post above.

Okay, I will grant that you're new at this. You have the editor and then you have the console. The console will show the errors. It will tell you where it errs. Basing just the error from the console save us from having to read a whole lot of code that doesn't show the error.  But again, given that you're new at this, now you know. 

Edit: so, There was a second page to all this.  😅

Edit2:

1 hour ago, xuankhanh1982 said:

Làm cách nào để tạo thông báo "GUICreate" trùng lặp màu nền với màu nền của hàm "_GUIDarkTheme_MsgBox"?
Vì hàm "_GUIDarkTheme_MsgBox" có nhiều hạn chế nên tôi không thể sử dụng nó và buộc phải tạo một "GUICreate" với nhiều tùy chọn hơn, như hình ảnh bên dưới.

"How can I create a "GUICreate" notification that matches the background color of the "_GUIDarkTheme_MsgBox" function?
Since the "_GUIDarkTheme_MsgBox" function has several limitations, I am unable to use it and am compelled to create a "GUICreate" window with more options, as shown in the image below.
"

Edited by argumentum

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

Posted (edited)
1 hour ago, xuankhanh1982 said:
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include "GUIDarkTheme.au3"

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 300, 200, -1, -1)
GUICtrlCreateLabel("", 0, 120, 300, 200 - 120); , $SS_GRAYRECT)
GUICtrlSetBkColor(-1, 0x202020)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateLabel("Hello there !", 40, 40)
$id_Bttn_Ok = GUICtrlCreateButton("&OK", 150, 150, 75, 21)
_GUIDarkTheme_ApplyDark($Form1)
GUISetBkColor(0x363636)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $id_Bttn_Ok
            GUIDelete()
            Exit

    EndSwitch
WEnd

..hope it helps

Edited by argumentum

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

Posted
2 hours ago, jpm said:

 

H I was wondering why the border is so big in Light mode it looks thinner

image.png.ef52c44fc796c23f79e19fa328034ac0.png

 

Good question. This is something that we should fix.

This happens because there is no dark theme for this control. So we have to remove the built-in light theme before we can apply dark colors. That leaves the thick light frame behind.

If that white frame is an extended style frame, we should be able to remove it.

If not, we may have to find a better way to color it or some trick to remove the frame.

Posted
8 hours ago, mLipok said:

Fixed version in attached zip

Thank you so much for your with fixing the issues related to Au3Stripper. This is a very important fix. :)

I'm just running a diff between your fixed UDF script and the 2.4.0 release to capture the changes that I need to make.

So using quotation marks around functions is what triggers Au3Stripper?

I was a little bit surprised to see that because many examples have the functions in quotes like that.

Posted (edited)
9 hours ago, jpm said:

image.png.ef52c44fc796c23f79e19fa328034ac0.png

@UEZ If you have a moment, could you please help us with this white border issue on the SysMonthCal32 control?

I have checked and there is no extended style applied.

I checked your SampleControls.au3 in Dark Mode examples, Page 1 (older, non-DPI aware) and Page 2 (newer, DPI-aware) and both examples also show the white border area.

However, the interesting thing is that I remember some of your very early versions of that script did not have the white border. Lucky for us, I keep everything. So it did not take long for me to find an older version of your script that did not have the border.

Older script in spoiler:

Spoiler
; Coded by UEZ build 2025-10-17 beta
;not DPI aware!

#include <APIConstants.au3>
#include <AVIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
#include <GuiMenu.au3>
#include <GuiMonthCal.au3>
#include <GuiScrollBars.au3>
#include <GuiTab.au3>
#include <TreeViewConstants.au3>
#include <ListViewConstants.au3>
#include <WinAPIConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIRes.au3>
#include <WinAPIShellEx.au3>
#include <WinAPISys.au3>
#include <WinAPISysWin.au3>
#include <WinAPITheme.au3>
#include <WindowsConstants.au3>

; initiate System DPI awareness
DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2)

Enum $IHCM_USE_CACHED_VALUE, $IHCM_REFRESH
Enum $APPMODE_DEFAULT = 0, $APPMODE_ALLOWDARK, $APPMODE_FORCEDARK, $APPMODE_FORCELIGHT, $APPMODE_MAX
Const $PRF_CLIENT = 0x04

; Dark Mode Colors (RGB)
Global Const $COLOR_BG_DARK = 0x202020
Global Const $COLOR_TEXT_LIGHT = 0xFFFFFF
Global Const $COLOR_CONTROL_BG = 0x2B2B2B
Global Const $COLOR_EDIT_BG = 0x1E1E1E
Global Const $COLOR_BUTTON_BG = 0x333333
Global Const $COLOR_BORDER = 0x3F3F3F

; Global variables for subclassing (MUST be declared before _Example()!)
Global $g_hGUI = 0, $g_hTab, $g_ListView
Global $g_aControls[50][3] = [[0, 0, 0]] ; [ControlID, hWnd, OldWndProc]
Global $g_iControlCount = 0
Global $g_pSubclassProc = 0

; Global brushes for _WM_CTLCOLOR (avoids memory leaks)
Global $g_hBrushEdit = 0
Global $g_hBrushButton = 0
Global $g_hBrushBg = 0
Global $g_hBrushGreen
Global $g_hLabelGreen = 0, $g_idLabelGreen
Global $g_idLabelPic, $g_hLabelPic
Global $g_hMenu = 0
Global $g_idDate = 0, $g_hDate = 0

; Global variable for tab subclassing
Global $g_hTab_CB, $g_pTab_CB, $g_hProc

; Structure for NM_CUSTOMDRAW notification
Global Const $tagNMCUSTOMDRAW = _
            $tagNMHDR & ";" & _                                                 ; Contains NM_CUSTOMDRAW / NMHDR header among other things
            "dword dwDrawStage;" & _                                            ; Current drawing stage (CDDS_*)
            "handle hdc;" & _                                                   ; Device Context Handle
            "long left;long top;long right;long bottom;" & _                    ; Drawing rectangle
            "dword_ptr dwItemSpec;" & _                                         ; Item index or other info (depending on the control)
            "uint uItemState;" & _                                              ; State Flags (CDIS_SELECTED, CDIS_FOCUS etc.)
            "lparam lItemlParam"                                                ; lParam set by the item (e.g., via LVITEM.lParam)


Global $g_hMenu = 0, $hMenuFont
Global $g_aMenuText = [] ; dynamic array for top-level menu texts
Global $arMenuItems[1][8]
$arMenuItems[0][0] = 0
Global $arSideItems[1][10]
$arSideItems[0][0] = 0

Const $ODT_MENU = 1
Const $ODS_SELECTED = 0x0001
Const $ODS_DISABLED = 0x0004

_Example()

Func _Example()
    ; Create global brushes
    $g_hBrushEdit = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_EDIT_BG))
    $g_hBrushButton = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BUTTON_BG))
    $g_hBrushBg = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BG_DARK))

    #Region GUI
    $g_hGUI = GUICreate("Sample GUI with Dark Mode", 400, 400)
    GUISetIcon(@SystemDir & "\mspaint.exe", 0)
    GUISetBkColor($COLOR_BG_DARK, $g_hGUI)

    ; Register GUI-level WM_CTLCOLOR messages
    GUIRegisterMsg($WM_CTLCOLOREDIT,     "_WM_CTLCOLOR")
    GUIRegisterMsg($WM_CTLCOLORLISTBOX,  "_WM_CTLCOLOR")
    GUIRegisterMsg($WM_CTLCOLORBTN,      "_WM_CTLCOLOR")
    GUIRegisterMsg($WM_CTLCOLORSTATIC,   "_WM_CTLCOLOR")
    GUIRegisterMsg($WM_INITMENUPOPUP,    "_OnInitMenuPopup")
    GUIRegisterMsg($WM_MEASUREITEM,      "WM_MEASUREITEM_Handler")
    GUIRegisterMsg($WM_DRAWITEM,         "WM_DRAWITEM_Handler")
    GUIRegisterMsg($WM_NOTIFY,           "WM_NOTIFY")
    GUIRegisterMsg($WM_ACTIVATE,         "_WM_ACTIVATE_OverpaintLine")
    GUIRegisterMsg($WM_WINDOWPOSCHANGED, "_WM_WINDOWPOSCHANGED_OverpaintLine")
    #EndRegion GUI

    #Region MENU
    Global $g_aMenuText[4]
    $g_aMenuText[0] = "Menu &One"
    $g_aMenuText[1] = "Menu &Two"
    $g_aMenuText[2] = "Menu Th&ree"
    $g_aMenuText[3] = "Menu &Four"

    Local $idMenu1 = GUICtrlCreateMenu($g_aMenuText[0])
    Local $idMenu2 = GUICtrlCreateMenu($g_aMenuText[1])
    GUICtrlCreateMenu($g_aMenuText[2])
    GUICtrlCreateMenu($g_aMenuText[3])
    GUICtrlCreateMenuItem('SubMenu One &A', $idMenu1)
    GUICtrlCreateMenuItem('SubMenu One &B', $idMenu1)

    ; Owner-draw Top-Level Menu einrichten
    _MakeMenuOwnerDraw($g_hGUI)

    #EndRegion MENU

    #Region CONTEXT MENU
    Local $idContextMenu = GUICtrlCreateContextMenu()
    GUICtrlCreateMenuItem("Context Menu", $idContextMenu)
    GUICtrlCreateMenuItem("", $idContextMenu)
    GUICtrlCreateMenuItem("&Properties", $idContextMenu)
    #EndRegion CONTEXT MENU

    #Region PIC
    Local $idPic = GUICtrlCreatePic("", 0, 0, 169, 68)
    GUICtrlSetImage($idPic, "C:\Program Files (x86)\AutoIt3\Examples\GUI\logo4.gif")
    GUICtrlSetTip(-1, '#Region PIC')
    $g_idLabelPic = GUICtrlCreateLabel("Sample Pic", 75, 1, 53, 15)
    $g_hLabelPic = GUICtrlGetHandle($g_idLabelPic)
    #EndRegion PIC

    #Region AVI
    Local $idAvi = GUICtrlCreateAvi("C:\Program Files (x86)\AutoIt3\Examples\GUI\SampleAVI.avi", 0, 180, 10, 32, 32, $ACS_AUTOPLAY)
    GUICtrlSetTip(-1, '#Region AVI')
    GUICtrlCreateLabel("Sample avi", 175, 50)
    #EndRegion AVI

    #Region TAB
    Local $idTab = GUICtrlCreateTab(240, 0, 150, 70), $g_hTab = GUICtrlGetHandle($idTab)
    _AddControlForSubclass($idTab)
    GUICtrlCreateTabItem("One")
    GUICtrlSetTip(-1, '#Region TAB1')
    GUICtrlCreateLabel("Sample Tab", 250, 40)
    GUICtrlCreateTabItem("Two")
    GUICtrlSetTip(-1, '#Region TAB2')
    GUICtrlCreateTabItem("Three")
    GUICtrlSetTip(-1, '#Region TAB3')
    GUICtrlCreateTabItem("")
    $g_hTab = GUICtrlGetHandle($idTab)
    #EndRegion TAB

    #Region COMBO
    Local $idCombo = GUICtrlCreateCombo("Sample Combo", 250, 80, 120, 100)
    GUICtrlSetData($idCombo, "Item 2|Item 3", "Sample Combo")
    _AddControlForSubclass($idCombo)
    GUICtrlSetTip(-1, '#Region COMBO')
    #EndRegion COMBO

    #Region PROGRESS
    Local $idProgress = GUICtrlCreateProgress(60, 80, 150, 20)
    _AddControlForSubclass($idProgress)
    GUICtrlSetTip(-1, '#Region PROGRESS')
    GUICtrlSetData(-1, 60)
    GUICtrlCreateLabel("Progress:", 5, 82)
    #EndRegion PROGRESS

    #Region EDIT
    Local $idEdit = GUICtrlCreateEdit(@CRLF & "  Sample Edit Control", 10, 110, 150, 70)
    _AddControlForSubclass($idEdit)
    GUICtrlSetTip(-1, '#Region EDIT')
    #EndRegion EDIT

    #Region LIST
    Local $idList = GUICtrlCreateList("", 5, 190, 100, 90)
    _AddControlForSubclass($idList)
    GUICtrlSetTip(-1, '#Region LIST')
    GUICtrlSetData(-1, "A.Sample|B.List|C.Control|D.Here", "B.List")
    #EndRegion LIST

    #Region ICON
    GUICtrlCreateIcon("explorer.exe", 0, 175, 120)
    GUICtrlSetTip(-1, '#Region ICON')
    GUICtrlCreateLabel("Icon", 180, 160, 50, 20)
    #EndRegion ICON

    #Region LIST VIEW
    Local $idListView = GUICtrlCreateListView("Sample|ListView|", 110, 190, 110, 80, $LVS_REPORT)
    _AddControlForSubclass($idListView)
    GUICtrlSetBkColor($idListView, $COLOR_EDIT_BG)
    GUICtrlSetColor($idListView, $COLOR_TEXT_LIGHT)
    GUICtrlSetTip(-1, '#Region LIST VIEW')
    GUICtrlCreateListViewItem("A|One", $idListView)
    GUICtrlCreateListViewItem("B|Two", $idListView)
    GUICtrlCreateListViewItem("C|Three", $idListView)
    $g_ListView = GUICtrlGetHandle($idListView)
    #EndRegion LIST VIEW

    #Region GROUP WITH RADIO BUTTONS
    Local $idGroup = GUICtrlCreateGroup("Sample Group", 230, 120)
    GUICtrlSetColor($idGroup, $COLOR_TEXT_LIGHT)
    Local $idRadio1 = GUICtrlCreateRadio("Radio One", 250, 140, 80)
    GUICtrlSetTip($idRadio1, '#Region RADIO1')
    GUICtrlSetState($idRadio1, $GUI_CHECKED)
    Local $idRadio2 = GUICtrlCreateRadio("Radio Two", 250, 165, 80)
    GUICtrlSetTip($idRadio2, '#Region RADIO2')
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($idGroup), "wstr", 0, "wstr", 0)
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($idRadio1), "wstr", 0, "wstr", 0)
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($idRadio2), "wstr", 0, "wstr", 0)
    #EndRegion GROUP WITH RADIO BUTTONS

    #Region UPDOWN
    GUICtrlCreateLabel("UpDown", 350, 115)
    GUICtrlSetColor(-1, $COLOR_TEXT_LIGHT)
    Local $idInput = GUICtrlCreateInput("42", 350, 130, 40, 20)
    _AddControlForSubclass($idInput)
    Local $idUpDown = GUICtrlCreateUpdown(-1)
    _AddControlForSubclass($idUpDown)
    #EndRegion UPDOWN

    #Region LABEL
    $g_idLabelGreen = GUICtrlCreateLabel("Green" & @CRLF & "Label", 350, 165, 40, 40)
    $g_hLabelGreen = GUICtrlGetHandle($g_idLabelGreen)
    GUICtrlSetTip($g_idLabelGreen, '#Region LABEL')
    $g_hBrushGreen = _WinAPI_CreateSolidBrush(_ColorToCOLORREF(0x00FF00)) ; green background

    #Region SLIDER
    GUICtrlCreateLabel("Slider:", 235, 215)
    Local $idSlider = GUICtrlCreateSlider(270, 210, 120, 30)
    _AddControlForSubclass($idSlider)
    GUICtrlSetTip(-1, '#Region SLIDER')
    GUICtrlSetData(-1, 30)
    #EndRegion SLIDER

    #Region INPUT
    Local $idInput2 = GUICtrlCreateInput("Sample Input Box", 235, 255, 130, 20)
    _AddControlForSubclass($idInput2)
    GUICtrlSetTip(-1, '#Region INPUT')
    #EndRegion INPUT

    #Region DATE
    $g_idDate = GUICtrlCreateDate("", 5, 280, 200, 20)
    $g_hDate = GUICtrlGetHandle($g_idDate)
    _AddControlForSubclass($g_idDate)
    GUICtrlSetTip(-1, '#Region DATE')
    GUICtrlCreateLabel("(Date control expands into a calendar)", 10, 305, 200, 20)
    #EndRegion DATE

    #Region BUTTON
    Local $idButton = GUICtrlCreateButton("Sample Button", 10, 330, 100, 30)
    _AddControlForSubclass($idButton)
    GUICtrlSetTip(-1, '#Region BUTTON')
    #EndRegion BUTTON

    #Region CHECKBOX
    Local $idCheckBox = GUICtrlCreateCheckbox("Checkbox", 130, 335, 80, 20)
    GUICtrlSetTip(-1, '#Region CHECKBOX')
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($idCheckBox), "wstr", 0, "wstr", 0)
    #EndRegion CHECKBOX

    #Region TREEVIEW ONE
    Local $idTreeView1 = GUICtrlCreateTreeView(210, 290, 80, 80)
    _AddControlForSubclass($idTreeView1)
    GUICtrlSetBkColor($idTreeView1, $COLOR_EDIT_BG)
    GUICtrlSetColor($idTreeView1, $COLOR_TEXT_LIGHT)
    GUICtrlSetTip(-1, '#Region TREEVIEW ONE')
    Local $idTreeViewItem = GUICtrlCreateTreeViewItem("TreeView", $idTreeView1)
    GUICtrlCreateTreeViewItem("Item1", $idTreeViewItem)
    GUICtrlCreateTreeViewItem("Item2", $idTreeViewItem)
    GUICtrlCreateTreeViewItem("Foo", -1)
    GUICtrlSetState($idTreeViewItem, $GUI_EXPAND)
    #EndRegion TREEVIEW ONE

    #Region TREEVIEW TWO
    Local $idTreeView2 = GUICtrlCreateTreeView(295, 290, 103, 80, $TVS_CHECKBOXES)
    _AddControlForSubclass($idTreeView2)
    GUICtrlSetBkColor($idTreeView2, $COLOR_EDIT_BG)
    GUICtrlSetColor($idTreeView2, $COLOR_TEXT_LIGHT)
    GUICtrlSetTip(-1, '#Region TREEVIEW TWO')
    GUICtrlCreateTreeViewItem("TreeView", $idTreeView2)
    GUICtrlCreateTreeViewItem("With", $idTreeView2)
    GUICtrlCreateTreeViewItem("$TVS_CHECKBOXES", $idTreeView2)
    GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlCreateTreeViewItem("Style", $idTreeView2)
    #EndRegion TREEVIEW TWO

    ; Apply Dark Mode
    _ApplyDarkModeToAllControls()

    ; Handle scrollbars for windows that have them
    _EnableDarkScrollBars()

    ; Register a custom window procedure for the tab control for owner-drawing
    $g_hTab_CB = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
    $g_pTab_CB = DllCallbackGetPtr($g_hTab_CB)
    $g_hProc = _WinAPI_SetWindowLong($g_hTab, $GWL_WNDPROC, $g_pTab_CB)

    GUISetState(@SW_SHOW)

    _OverpaintWhiteLine()
    _WinAPI_RedrawWindow($g_hGUI, 0, 0, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                _CleanupSubclassing()
                _CleanupBrushes()
                ExitLoop
        EndSwitch
    WEnd
    ; Restore the original window procedure for the tab control
    _WinAPI_SetWindowLong($g_hTab, $GWL_WNDPROC, $g_hProc)
    DllCallbackFree($g_hTab_CB)

    GUIDelete()
EndFunc   ;==>_Example

Func _OverpaintWhiteLine()
    Local $hDC = _WinAPI_GetWindowDC($g_hGUI)
    If Not $hDC Then Return

    Local $tWndRect = _WinAPI_GetWindowRect($g_hGUI)
    Local $iWndWidth = $tWndRect.right - $tWndRect.left

    ; 1. Caption height
    Local $iCaptionHeight = _WinAPI_GetSystemMetrics($SM_CYCAPTION)

    ; 2. Border height (top)
    Local $iBorderHeight = _WinAPI_GetSystemMetrics($SM_CYSIZEFRAME)
    If $iBorderHeight = 0 Then $iBorderHeight = _WinAPI_GetSystemMetrics($SM_CYFIXEDFRAME)

    ; 3. Determine menu height dynamically
    Local $iMenuHeight = _WinAPI_GetSystemMetrics($SM_CYMENU) ; standard menu height

    ; Alternative: get menu height via GetMenuBarInfo
    Local $tMenuBarInfo = DllStructCreate("dword cbSize;long left;long top;long right;long bottom;handle hwndMenu;handle hwndItem;bool fBarFocused;bool fFocused")
    DllStructSetData($tMenuBarInfo, "cbSize", DllStructGetSize($tMenuBarInfo))
    Local $aResult = DllCall("user32.dll", "bool", "GetMenuBarInfo", "hwnd", $g_hGUI, "long", 0xFFFFFFFD, "long", 0, "ptr", DllStructGetPtr($tMenuBarInfo))

    If IsArray($aResult) And $aResult[0] Then
        ; Calculate the actual menu height from the coordinates
        Local $iMenuTop = $tMenuBarInfo.top
        Local $iMenuBottom = $tMenuBarInfo.bottom
        ; Convert to window coordinates
        $iMenuHeight = ($iMenuBottom - $iMenuTop)
    EndIf

    ; The white line is directly below the menu
    Local $iWhiteLineY = $iCaptionHeight + $iBorderHeight + $iMenuHeight - _WinAPI_GetSystemMetrics($SM_CYFIXEDFRAME) * 2

;~     ConsoleWrite("Caption: " & $iCaptionHeight & ", Border: " & $iBorderHeight & ", Menu: " & $iMenuHeight & " -> White Line at Y=" & $iWhiteLineY & @CRLF)

    ; Overpaint the white line (1x2 pixels)
    Local $tRect = DllStructCreate($tagRECT)
    With $tRect
        .left = 0
        .top = $iWhiteLineY
        .right = $iWndWidth
        .bottom = $iWhiteLineY + 2 ; 2 pixels high
    EndWith

    Local $hBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BG_DARK))
;~     Local $hBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF(0xFF0000))
    _WinAPI_FillRect($hDC, $tRect, $hBrush)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($g_hGUI, $hDC)
EndFunc   ;==>_OverpaintWhiteLine

Func _WM_ACTIVATE_OverpaintLine($hWnd, $iMsg, $wParam, $lParam)
    If $hWnd <> $g_hGUI Then Return $GUI_RUNDEFMSG
    _OverpaintWhiteLine()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_ACTIVATE_OverpaintLine

Func _WM_WINDOWPOSCHANGED_OverpaintLine($hWnd, $iMsg, $wParam, $lParam)
    If $hWnd <> $g_hGUI Then Return $GUI_RUNDEFMSG
    _OverpaintWhiteLine()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_WINDOWPOSCHANGED_OverpaintLine

Func _OnInitMenuPopup($hWnd, $iMsg, $wParam, $lParam)
    ; wParam = HMENU of the popup, lParam = position/index - not needed here
    ; A small delay sometimes helps to ensure the popup window exists
    Sleep(100)

    ; The foreground window is most likely the new menu popup
    Local $hPopup = _WinAPI_GetForegroundWindow()
    If Not $hPopup Then Return $GUI_RUNDEFMSG

    Local $sCls = StringLower(_WinAPI_GetClassName($hPopup))
    If $sCls <> "#32768" And $sCls <> "popupmenu" Then
        ; if no menu popup is detected -> do nothing
        Return $GUI_RUNDEFMSG
    EndIf

    ; Set Theme + AllowDarkMode on the popup itself
    _WinAPI_SetWindowTheme($hPopup, "DarkMode_Explorer", "")
    _WinAPI_AllowDarkModeForWindow($hPopup, True)

    ; Also apply the theme to all child windows of the popup (e.g., scrollbars)
    Local $hChild = _WinAPI_GetWindow($hPopup, $GW_CHILD)
    While $hChild
        Local $sChildCls = StringLower(_WinAPI_GetClassName($hChild))
        ; apply theme specifically for scrollbars, UpDown, etc.
        If $sChildCls = "scrollbar" Or $sChildCls = "msctls_updown32" Or $sChildCls = "traynotifywnd" Then
            _WinAPI_SetWindowTheme($hChild, "DarkMode_Explorer", "")
            _WinAPI_AllowDarkModeForWindow($hChild, True)
        Else
            ; try generically
            _WinAPI_SetWindowTheme($hChild, "DarkMode_Explorer", "")
            _WinAPI_AllowDarkModeForWindow($hChild, True)
        EndIf
        $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
    WEnd

    ; Force refresh so the change is visible immediately
    _WinAPI_FlushMenuThemes()
    _WinAPI_RefreshImmersiveColorPolicyState()
    _WinAPI_RedrawWindow($hPopup, 0, 0, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))

    Return $GUI_RUNDEFMSG
EndFunc   ;==>_OnInitMenuPopup

Func _ColorToCOLORREF($iColor) ;RGB to BGR
    Local $iR = BitAND(BitShift($iColor, 16), 0xFF)
    Local $iG = BitAND(BitShift($iColor, 8), 0xFF)
    Local $iB = BitAND($iColor, 0xFF)
    Return BitOR(BitShift($iB, -16), BitShift($iG, -8), $iR)
EndFunc   ;==>_ColorToCOLORREF

Func _AddControlForSubclass($iCtrlID)
    Local $hCtrl = GUICtrlGetHandle($iCtrlID)
    If $hCtrl Then
        $g_aControls[$g_iControlCount][0] = $iCtrlID
        $g_aControls[$g_iControlCount][1] = $hCtrl
        $g_aControls[$g_iControlCount][2] = 0 ; Placeholder for OldWndProc
        $g_iControlCount += 1
    EndIf
EndFunc   ;==>_AddControlForSubclass

Func _ApplyDarkModeToAllControls()
    ; DWM Dark Mode for the main window
    _WinAPI_SetPreferredAppMode($APPMODE_FORCEDARK)

    ; Create subclass callback
    If Not $g_pSubclassProc Then
        $g_pSubclassProc = DllCallbackRegister("_SubclassProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr")
    EndIf

    ; Subclass all controls
    For $i = 0 To $g_iControlCount - 1
        Local $hCtrl = $g_aControls[$i][1]
        If $hCtrl Then
            Local $sClass = _WinAPI_GetClassName($hCtrl)
            ; Use SetWindowSubclass
            _WinAPI_SetWindowSubclass($hCtrl, DllCallbackGetPtr($g_pSubclassProc), $i, 0)

            ; Special themes for different control types
            Switch StringLower($sClass)
                Case "edit", "richedit", "richedit20a", "richedit20w"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_CFD", 0)
                Case "button"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case "combobox"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_CFD", 0)
                    ; Handle ComboBox child-edit
                    Local $hEdit = _WinAPI_FindWindowEx($hCtrl, 0, "Edit", "")
                    If $hEdit Then
                        _WinAPI_SetWindowTheme($hEdit, "DarkMode_CFD", 0)
                        _WinAPI_AllowDarkModeForWindow($hEdit, True)
                    EndIf
                    ; ComboBox dropdown list
                    Local $hComboLBox = _WinAPI_FindWindowEx($hCtrl, 0, "ComboLBox", "")
                    If $hComboLBox Then
                        _WinAPI_SetWindowTheme($hComboLBox, "DarkMode_Explorer", 0)
                        _WinAPI_AllowDarkModeForWindow($hComboLBox, True)
                    EndIf
                Case "syslistview32"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                    ; ListView extended styles for better dark mode
                    _SendMessage($hCtrl, $LVS_EX_DOUBLEBUFFER, 0x00010000, 0x00010000)
                    ; Also make the ListView header dark
                    Local $hHeader = _SendMessage($hCtrl, $LVM_GETHEADER, 0, 0)
                    If $hHeader Then
                        _WinAPI_SetWindowTheme($hHeader, "DarkMode_ItemsView", 0)
                    EndIf
                Case "systreeview32"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case "msctls_trackbar32" ; Slider
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case "systabcontrol32"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", "") ;must be ""
                    ; tab-Control background
                    _SendMessage($hCtrl, 0x132D, 0, $COLOR_BG_DARK) ; TCM_SETBKCOLOR
                    ; Try to make the UpDown (spinner for too many tabs) dark as well
                    Local $hUpDown = _WinAPI_FindWindowEx($hCtrl, 0, "msctls_updown32", "")
                    If $hUpDown Then _WinAPI_SetWindowTheme($hUpDown, "DarkMode_Explorer", 0)
                Case "listbox"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case "msctls_progress32"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case "scrollbar"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case Else
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
            EndSwitch

            _WinAPI_AllowDarkModeForWindow($hCtrl, True)
        EndIf
    Next

    ; Update theme system
    _WinAPI_RefreshImmersiveColorPolicyState()
    _WinAPI_FlushMenuThemes()
    _WinAPI_DwmSetWindowAttribute($g_hGUI, $DWMWA_USE_IMMERSIVE_DARK_MODE, True)


    ; Redraw GUI
    _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
EndFunc   ;==>_ApplyDarkModeToAllControls

Func _CleanupSubclassing()
    ; Remove all subclasses
    If $g_pSubclassProc Then
        For $i = 0 To $g_iControlCount - 1
            Local $hCtrl = $g_aControls[$i][1]
            If $hCtrl Then
                _WinAPI_RemoveWindowSubclass($hCtrl, DllCallbackGetPtr($g_pSubclassProc), $i)
            EndIf
        Next
        DllCallbackFree($g_pSubclassProc)
        $g_pSubclassProc = 0
    EndIf
EndFunc   ;==>_CleanupSubclassing

Func _SubclassProc($hWnd, $iMsg, $wParam, $lParam, $iID, $pData)
    Switch $iMsg
        Case $WM_NOTIFY
            Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
            Local $hFrom = $tNMHDR.hWndFrom
            Local $iCode = $tNMHDR.Code

            ; --- Adjust ListView Header text color ---
            If $iCode = $NM_CUSTOMDRAW Then
                Local $tNMCUSTOMDRAW = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
                Local $dwDrawStage = $tNMCUSTOMDRAW.dwDrawStage
                Local $hDC = $tNMCUSTOMDRAW.hdc

                Switch $dwDrawStage
                    Case $CDDS_PREPAINT
                        Return $CDRF_NOTIFYITEMDRAW
                    Case $CDDS_ITEMPREPAINT
                        _WinAPI_SetTextColor($hDC, _ColorToCOLORREF($COLOR_TEXT_LIGHT)) ; White text
                        _WinAPI_SetBkColor($hDC, _ColorToCOLORREF($COLOR_BG_DARK))     ; Dark background
                        Return BitOR($CDRF_NEWFONT, $CDRF_NOTIFYPOSTPAINT)
                EndSwitch
            EndIf

        Case $WM_PAINT
            ; Custom Paint for better Dark Mode rendering
            Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
    EndSwitch

    ; Forward standard message to DefSubclassProc
    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_SubclassProc

Func _MakeMenuOwnerDraw($hWnd)
    ; Get menu handle
    $g_hMenu = _GUICtrlMenu_GetMenu($hWnd)
    If Not $g_hMenu Then Return False

    Local $iCount = _GUICtrlMenu_GetItemCount($g_hMenu)
    If $iCount <= 0 Then Return False

    ReDim $g_aMenuText[$iCount]

    For $i = 0 To $iCount - 1
        ; retrieve text via GetMenuStringW (works better than _GUICtrlMenu_GetItemText)
        Local $tText = DllStructCreate("wchar s[256]")
        Local $iLen = DllCall("user32.dll", "int", "GetMenuStringW", _
                                                    "handle", $g_hMenu, _
                                                    "uint", $i, _
                                                    "struct*", $tText, _
                                                    "int", 255, _
                                                    "uint", 0x0400) ; MF_BYPOSITION

        If IsArray($iLen) And $iLen[0] > 0 Then
            $g_aMenuText[$i] = $tText.s
        Else
            $g_aMenuText[$i] = ""
        EndIf

        ; set top-level item to owner-draw
        _GUICtrlMenu_SetItemType($g_hMenu, $i, $MFT_OWNERDRAW, True)
    Next

    ; redraw menu bar immediately
    _GUICtrlMenu_DrawMenuBar($hWnd)
    _WinAPI_RedrawWindow($hWnd, 0, 0, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))

    Return True
EndFunc   ;==>_MakeMenuOwnerDraw

Func WM_MEASUREITEM_Handler($hWnd, $iMsg, $wParam, $lParam)
    Local $tagMEASUREITEM = "uint CtlType;uint CtlID;uint itemID;uint itemWidth;uint itemHeight;ulong_ptr itemData"
    Local $t = DllStructCreate($tagMEASUREITEM, $lParam)
    If Not IsDllStruct($t) Then Return $GUI_RUNDEFMSG

    If $t.CtlType <> $ODT_MENU Then Return $GUI_RUNDEFMSG

    Local $itemID = $t.itemID

    ; itemID is the control ID, not the position!
    ; We must derive the position from the itemID
    Local $iPos = -1
    For $i = 0 To UBound($g_aMenuText) - 1
        If $itemID = ($i + 3) Then ; Offset of 3 due to internal IDs
            $iPos = $i
            ExitLoop
        EndIf
    Next

    ; Fallback: try the itemID directly
    If $iPos < 0 Then $iPos = $itemID
    If $iPos < 0 Or $iPos >= UBound($g_aMenuText) Then $iPos = 0

    Local $sText = $g_aMenuText[$iPos]

    ; Calculate text dimensions
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $hFont = _SendMessage($hWnd, $WM_GETFONT, 0, 0)
    If Not $hFont Then $hFont = _WinAPI_GetStockObject($DEFAULT_GUI_FONT)
    Local $hOldFont = _WinAPI_SelectObject($hDC, $hFont)

    Local $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sText)
    Local $iTextWidth = $tSize.X
    Local $iTextHeight = $tSize.Y

    _WinAPI_SelectObject($hDC, $hOldFont)
    _WinAPI_ReleaseDC($hWnd, $hDC)

    ; Set dimensions with padding
    $t.itemWidth = $iTextWidth + 1
    $t.itemHeight = $iTextHeight + 1

    Return 1
EndFunc   ;==>WM_MEASUREITEM_Handler

Func WM_DRAWITEM_Handler($hWnd, $iMsg, $wParam, $lParam)
    Local $tagDRAWITEM = "uint CtlType;uint CtlID;uint itemID;uint itemAction;uint itemState;ptr hwndItem;handle hDC;" & _
                         "long left;long top;long right;long bottom;ulong_ptr itemData"
    Local $t = DllStructCreate($tagDRAWITEM, $lParam)
    If Not IsDllStruct($t) Then Return $GUI_RUNDEFMSG

    If $t.CtlType <> $ODT_MENU Then Return $GUI_RUNDEFMSG

    Local $hDC     = $t.hDC
    Local $left    = $t.left
    Local $top     = $t.top
    Local $right   = $t.right
    Local $bottom  = $t.bottom
    Local $state   = $t.itemState
    Local $itemID  = $t.itemID

    ; convert itemID to position
    Local $iPos = -1
    For $i = 0 To UBound($g_aMenuText) - 1
        If $itemID = ($i + 3) Then
            $iPos = $i
            ExitLoop
        EndIf
    Next

    If $iPos < 0 Then $iPos = $itemID
    If $iPos < 0 Or $iPos >= UBound($g_aMenuText) Then $iPos = 0

    Local $sText = $g_aMenuText[$iPos]
    $sText = StringReplace($sText, "&", "")

    ; Colors
    Local $clrBG   = _ColorToCOLORREF($COLOR_BG_DARK)
    Local $clrSel  = _ColorToCOLORREF(0x505050)
    Local $clrText = _ColorToCOLORREF($COLOR_TEXT_LIGHT)

    Static $iDrawCount = 0
    Static $bFullBarDrawn = False

    ; Count how many items were drawn in this "draw cycle"
    $iDrawCount += 1

    ; If we are at the first item AND the bar has not yet been drawn
    If $iPos = 0 And Not $bFullBarDrawn Then
        ; Get the full window width
        Local $tClient = _WinAPI_GetClientRect($hWnd)
        Local $iFullWidth = DllStructGetData($tClient, "right")

        ; Fill the entire menu bar
        Local $tFullMenuBar = DllStructCreate($tagRECT)
        With $tFullMenuBar
            .left = 0
            .top = $top
            .right =  $iFullWidth + 3
            .bottom = $bottom
        EndWith

        Local $hFullBrush = _WinAPI_CreateSolidBrush($clrBG)
        _WinAPI_FillRect($hDC, $tFullMenuBar, $hFullBrush)
        _WinAPI_DeleteObject($hFullBrush)
    EndIf

    ; After drawing all items, mark as "drawn"
    If $iDrawCount >= UBound($g_aMenuText) Then
        $bFullBarDrawn = True
        $iDrawCount = 0
    EndIf

    ; Draw background for the area AFTER the last menu item
    If $iPos = (UBound($g_aMenuText) - 1) Then ; Last menu
        Local $tClient = _WinAPI_GetClientRect($hWnd)
        Local $iFullWidth = DllStructGetData($tClient, "right")

        ; Fill only the area to the RIGHT of the last menu item
        If $right < $iFullWidth Then
            Local $tEmptyArea = DllStructCreate($tagRECT)
            With $tEmptyArea
                .left = $right
                .top = $top
                .right = $iFullWidth + _WinAPI_GetSystemMetrics(7)
                .bottom = $bottom
            EndWith

            Local $hEmptyBrush = _WinAPI_CreateSolidBrush($clrBG)
            _WinAPI_FillRect($hDC, $tEmptyArea, $hEmptyBrush)
            _WinAPI_DeleteObject($hEmptyBrush)
        EndIf
    EndIf

    ; Draw item background (selected = lighter)
    Local $bSelected = BitAND($state, $ODS_SELECTED)
    Local $hBrush = _WinAPI_CreateSolidBrush($bSelected ? $clrSel : $clrBG)

    Local $tItemRect = DllStructCreate($tagRECT)
    With $tItemRect
        .left = $left
        .top = $top
        .right = $right
        .bottom = $bottom
    EndWith

    _WinAPI_FillRect($hDC, $tItemRect, $hBrush)
    _WinAPI_DeleteObject($hBrush)

    ; Setup font
    Local $hFont = _SendMessage($hWnd, $WM_GETFONT, 0, 0)
    If Not $hFont Then $hFont = _WinAPI_GetStockObject($DEFAULT_GUI_FONT)
    Local $hOldFont = _WinAPI_SelectObject($hDC, $hFont)

    _WinAPI_SetBkMode($hDC, $TRANSPARENT)
    _WinAPI_SetTextColor($hDC, $clrText)

    ; Draw text
    Local $tTextRect = DllStructCreate($tagRECT)
    With $tTextRect
        .left = $left + 10
        .top = $top + 4
        .right = $right - 10
        .bottom = $bottom - 4
    EndWith

    DllCall("user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $sText, "int", -1, "ptr", DllStructGetPtr($tTextRect), "uint", BitOR($DT_SINGLELINE, $DT_VCENTER, $DT_LEFT))

    If $hOldFont Then _WinAPI_SelectObject($hDC, $hOldFont)

    Return 1
EndFunc   ;==>WM_DRAWITEM_Handler

Func _WM_CTLCOLOR($hWnd, $iMsg, $wParam, $lParam)
    Local $hDC = $wParam
    Local $hCtrl = $lParam

    ; If the control is the special green label -> return green background
    If $hCtrl = $g_hLabelGreen Then
        ; black text on a green background
        _WinAPI_SetTextColor($hDC, _ColorToCOLORREF(0x000000))
        _WinAPI_SetBkColor($hDC, _ColorToCOLORREF(0x00FF00))
        _WinAPI_SetBkMode($hDC, $OPAQUE) ; important, otherwise it remains transparent and you cannot see the background
        If $g_hBrushGreen Then Return $g_hBrushGreen
    EndIf

    ; --- Special case: Make "Sample Pic" label transparent ---
    If $hCtrl = $g_hLabelPic Then
        ; set transparent background
        _WinAPI_SetBkMode($hDC, $TRANSPARENT)
        ; set text color (if necessary) - e.g., white
        _WinAPI_SetTextColor($hDC, _ColorToCOLORREF($COLOR_TEXT_LIGHT))
        ; return NULL_BRUSH (stock object), so Windows does NOT fill with your dark brush
        Local $hNull = _WinAPI_GetStockObject(5) ; 5 = NULL_BRUSH
        If $hNull Then Return $hNull
        ; Fallback if not available:
        Return $GUI_RUNDEFMSG
    EndIf

    ; --- Default behavior for all other statics / controls ---
    _WinAPI_SetTextColor($hDC, _ColorToCOLORREF($COLOR_TEXT_LIGHT))

    Local $hBrush = $g_hBrushEdit
    Local $iColor = $COLOR_EDIT_BG

    Switch $iMsg
        Case $WM_CTLCOLORBTN
            $hBrush = $g_hBrushButton
            $iColor = $COLOR_BUTTON_BG
        Case $WM_CTLCOLORSTATIC
            $hBrush = $g_hBrushBg
            $iColor = $COLOR_BG_DARK
    EndSwitch
    _WinAPI_SetBkColor($hDC, _ColorToCOLORREF($iColor))
    _WinAPI_SetBkMode($hDC, $TRANSPARENT)

    Return $hBrush
EndFunc   ;==>_WM_CTLCOLOR

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $tBuffer, $tBuffer2, $iCtrl
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd($tNMHDR.hWndFrom)
    $iIDFrom = $tNMHDR.IDFrom
    $iCode = $tNMHDR.Code

    Switch $hWndFrom
        Case $g_hDate ;thanks to argumentum for the code :-)
            Switch $iCode
                Case $NM_SETFOCUS
                    ; Disable the visual theme when the DateTime control receives focus
                    _WinAPI_SetThemeAppProperties(0) ; we don't necessarily need this, SetWindowTheme below works - WildByDesign

                Case $DTN_DROPDOWN
                    ; Apply dark colors when the calendar dropdown appears
                    Local $iCtrl = _GUICtrlDTP_GetMonthCal($hWndFrom)
                    ;_WinAPI_SetWindowTheme($iCtrl, "", "") ; this will work here without _WinAPI_SetThemeAppProperties - WildByDesign
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TEXT, $COLOR_TEXT_LIGHT)
                    ;_GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TITLEBK, $COLOR_BG_DARK)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_BACKGROUND, $COLOR_BG_DARK)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TITLETEXT, $COLOR_TEXT_LIGHT)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_MONTHBK, $COLOR_BG_DARK)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TRAILINGTEXT, $COLOR_TEXT_LIGHT)

                Case $DTN_CLOSEUP
                    ;  Calendar will closed

            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_NOTIFY

Func _CleanupBrushes()
    ; Delete all brushes
    If $g_hBrushEdit Then _WinAPI_DeleteObject($g_hBrushEdit)
    If $g_hBrushButton Then _WinAPI_DeleteObject($g_hBrushButton)
    If $g_hBrushBg Then _WinAPI_DeleteObject($g_hBrushBg)
    If $g_hBrushGreen Then _WinAPI_DeleteObject($g_hBrushGreen)
EndFunc   ;==>_CleanupBrushes

Func _EnableDarkScrollBars()
    ; Try to enable Dark Mode for all scrollbars (also for TreeView with checkboxes)
    For $i = 0 To $g_iControlCount - 1
        Local $hCtrl = $g_aControls[$i][1]
        If Not $hCtrl Then ContinueLoop

        ; 1️ Normal attempt (works for most controls)
        Local $tScrollInfo = _GUIScrollBars_GetScrollInfoEx($hCtrl, 1)
        If IsDllStruct($tScrollInfo) Then
            _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
        EndIf

        ; 2️ Extension: If the control has its own scrollbar child windows (e.g., TreeView with $TVS_CHECKBOXES)
        Local $hChild = _WinAPI_GetWindow($hCtrl, $GW_CHILD)
        While $hChild
            Local $sClass = _WinAPI_GetClassName($hChild)
            If StringCompare($sClass, "ScrollBar") = 0 Then
                ; Set DarkMode on the ScrollBar itself
                _WinAPI_SetWindowTheme($hChild, "DarkMode_Explorer", 0)
                _WinAPI_AllowDarkModeForWindow($hChild, True)
            EndIf
            $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
        WEnd
    Next
EndFunc   ;==>_EnableDarkScrollBars

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
    ; Custom window procedure for tab control with Dark Mode
    Switch $iMsg
        Case $WM_ERASEBKGND
            Return 1 ; Prevent background erase to avoid flicker

        Case $WM_PAINT
            Local $tPaint = DllStructCreate($tagPAINTSTRUCT)
            Local $hDC = DllCall("user32.dll", "handle", "BeginPaint", "hwnd", $hWnd, "struct*", $tPaint)
            If @error Or Not $hDC[0] Then Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam)
            $hDC = $hDC[0]

            ; Get client rectangle
            Local $tClient = _WinAPI_GetClientRect($hWnd)
            If Not IsDllStruct($tClient) Then
                _WinAPI_EndPaint($hWnd, $tPaint)
                Return 0
            EndIf

            Local $iWidth = $tClient.Right
            Local $iHeight = $tClient.Bottom

            ; Create memory DC for double buffering
            Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
            Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
            Local $hOldBmp = _WinAPI_SelectObject($hMemDC, $hBitmap)

            ; Fill background
            Local $hBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BG_DARK))
            _WinAPI_FillRect($hMemDC, $tClient, $hBrush)
            _WinAPI_DeleteObject($hBrush)

            ; Get tab info
            Local $iTabCount = _SendMessage($hWnd, 0x1304, 0, 0) ; TCM_GETITEMCOUNT
            Local $iCurSel = _SendMessage($hWnd, 0x130B, 0, 0)   ; TCM_GETCURSEL

            ; Setup font
            Local $hFont = _SendMessage($hWnd, $WM_GETFONT, 0, 0)
            If Not $hFont Then $hFont = _WinAPI_GetStockObject($DEFAULT_GUI_FONT)
            Local $hOldFont = _WinAPI_SelectObject($hMemDC, $hFont)

            _WinAPI_SetBkMode($hMemDC, $TRANSPARENT)
            _WinAPI_SetTextColor($hMemDC, _ColorToCOLORREF($COLOR_TEXT_LIGHT))

            ; Draw each tab
            Local $tRect, $tRect, $iLeft, $iTop, $iRight, $iBottom
            For $i = 0 To $iTabCount - 1
                ; Get tab rectangle using TCM_GETITEMRECT
                $tRect = DllStructCreate($tagRECT)
                $aResult = DllCall("user32.dll", "lresult", "SendMessageW", _
                                                            "hwnd", $hWnd, _
                                                            "uint", 0x130A, _  ; TCM_GETITEMRECT
                                                            "wparam", $i, _
                                                            "struct*", $tRect)
                If @error Or Not $aResult[0] Then ContinueLoop

                $iLeft = $tRect.Left
                $iTop = $tRect.Top
                $iRight = $tRect.Right
                $iBottom = $tRect.Bottom

                ; Skip if rectangle is invalid
                If $iLeft >= $iRight Or $iTop >= $iBottom Then ContinueLoop

                ; Get tab text
                Local $tItem = DllStructCreate("uint Mask;dword dwState;dword dwStateMask;ptr pszText;int cchTextMax;int iImage;lparam lParam")
                Local $tText = DllStructCreate("wchar Text[256]")
                With $tItem
                    .Mask = 0x0001 ; TCIF_TEXT
                    .pszText = DllStructGetPtr($tText)
                    .cchTextMax = 256
                EndWith

                DllCall("user32.dll", "lresult", "SendMessageW", _
                                                "hwnd", $hWnd, _
                                                "uint", 0x133C, _  ; TCM_GETITEMW
                                                "wparam", $i, _
                                                "struct*", $tItem)

                Local $sText = DllStructGetData($tText, "Text")

                ; Draw tab background
                Local $bSelected = ($i = $iCurSel)
                Local $iTabColor = $bSelected ? $COLOR_BUTTON_BG : $COLOR_BG_DARK
                Local $hTabBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($iTabColor))

                Local $tTabRect = DllStructCreate($tagRECT)
                With $tTabRect
                    .Left = $iLeft
                    .Top = $iTop
                    .Right = $iRight
                    .Bottom = $iBottom
                EndWith

                _WinAPI_FillRect($hMemDC, $tTabRect, $hTabBrush)
                _WinAPI_DeleteObject($hTabBrush)

;~              Local $hTabPen = _WinAPI_CreatePen(0, 1, _ColorToCOLORREF($COLOR_BORDER))
;~              Local $hOldTabPen = _WinAPI_SelectObject($hMemDC, $hTabPen)
;~              _WinAPI_MoveTo($hMemDC, $iLeft, $iBottom)
;~              _WinAPI_LineTo($hMemDC, $iRight, $iBottom)
;~              _WinAPI_SelectObject($hMemDC, $hOldTabPen)
;~              _WinAPI_DeleteObject($hTabPen)

                ; Draw selection indicator (top border for selected tab)
                If $bSelected Then
                    Local $hPen = _WinAPI_CreatePen(0, 2, _ColorToCOLORREF(0x0078D4)) ; Blue accent
                    Local $hOldPen = _WinAPI_SelectObject($hMemDC, $hPen)
                    _WinAPI_MoveTo($hMemDC, $iLeft, $iTop)
                    _WinAPI_LineTo($hMemDC, $iRight - 2, $iTop)
                    _WinAPI_SelectObject($hMemDC, $hOldPen)
                    _WinAPI_DeleteObject($hPen)
                EndIf

                ; Draw separator between tabs
                If $i < $iTabCount - 1 Then
                    Local $hPenSep = _WinAPI_CreatePen(0, 1, _ColorToCOLORREF($COLOR_BORDER))
                    Local $hOldPenSep = _WinAPI_SelectObject($hMemDC, $hPenSep)
                    _WinAPI_MoveTo($hMemDC, $iRight - 1, $iTop + 4)
                    _WinAPI_LineTo($hMemDC, $iRight - 1, $iBottom - 4)
                    _WinAPI_SelectObject($hMemDC, $hOldPenSep)
                    _WinAPI_DeleteObject($hPenSep)
                EndIf

                ; Draw text centered in tab
                Local $tTextRect = DllStructCreate($tagRECT)
                With $tTextRect
                    .Left = $iLeft + 6
                    .Top = $iTop + 3
                    .Right = $iRight - 6
                    .Bottom = $iBottom - 3
                EndWith

                DllCall("user32.dll", "int", "DrawTextW", _
                                            "handle", $hMemDC, _
                                            "wstr", $sText, _
                                            "int", -1, _
                                            "struct*", $tTextRect, _
                                            "uint", BitOR($DT_CENTER, $DT_VCENTER, $DT_SINGLELINE))
            Next

            ; Draw border around entire control
            Local $hBorderPen = _WinAPI_CreatePen(0, 1, _ColorToCOLORREF($COLOR_BORDER))
            Local $hOldBorderPen = _WinAPI_SelectObject($hMemDC, $hBorderPen)
            Local $hNullBrush = _WinAPI_GetStockObject(5) ; NULL_BRUSH
            Local $hOldBorderBrush = _WinAPI_SelectObject($hMemDC, $hNullBrush)

            DllCall("gdi32.dll", "bool", "Rectangle", _
                                        "handle", $hMemDC, _
                                        "int", 0, _
                                        "int", 0, _
                                        "int", $iWidth, _
                                        "int", $iHeight)

            _WinAPI_SelectObject($hMemDC, $hOldBorderPen)
            _WinAPI_SelectObject($hMemDC, $hOldBorderBrush)
            _WinAPI_DeleteObject($hBorderPen)

            ; Copy to screen
            _WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $hMemDC, 0, 0, $SRCCOPY)

            ; Cleanup
            _WinAPI_SelectObject($hMemDC, $hOldFont)
            _WinAPI_SelectObject($hMemDC, $hOldBmp)
            _WinAPI_DeleteObject($hBitmap)
            _WinAPI_DeleteDC($hMemDC)

            _WinAPI_EndPaint($hWnd, $tPaint)
            Return 0



    EndSwitch

    Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc

Func _WinAPI_FindWindowEx($hParent, $hAfter, $sClass, $sTitle = "")
    Local $ret = DllCall("user32.dll", "hwnd", "FindWindowExW", "hwnd", $hParent, "hwnd", $hAfter, "wstr", $sClass, "wstr", $sTitle)
    If @error Or Not IsArray($ret) Then Return 0
    Return $ret[0]
EndFunc   ;==>_WinAPI_FindWindowEx


#Region DarkMode API
Func _WinAPI_ShouldAppsUseDarkMode()
    Local $aResult = DllCall("UxTheme.dll", "bool", 132)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_ShouldAppsUseDarkMode

Func _WinAPI_AllowDarkModeForWindow($hWND, $bAllow = True)
    Local $aResult = DllCall("UxTheme.dll", "bool", 133, "hwnd", $hWND, "bool", $bAllow)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_AllowDarkModeForWindow

Func _WinAPI_FlushMenuThemes()
    Local $aResult = DllCall("UxTheme.dll", "none", 136)
    If @error Then Return SetError(1, 0, False)
    Return True
EndFunc   ;==>_WinAPI_FlushMenuThemes

Func _WinAPI_RefreshImmersiveColorPolicyState()
    Local $aResult = DllCall("UxTheme.dll", "none", 104)
    If @error Then Return SetError(1, 0, False)
    Return True
EndFunc   ;==>_WinAPI_RefreshImmersiveColorPolicyState

Func _WinAPI_IsDarkModeAllowedForWindow($hWND)
    Local $aResult = DllCall("UxTheme.dll", "bool", 137, "hwnd", $hWND)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_IsDarkModeAllowedForWindow

Func _WinAPI_GetIsImmersiveColorUsingHighContrast($iIMMERSIVE_HC_CACHE_MODE)
    Local $aResult = DllCall("UxTheme.dll", "bool", 106, "long", $iIMMERSIVE_HC_CACHE_MODE)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_GetIsImmersiveColorUsingHighContrast

Func _WinAPI_OpenNcThemeData($hWND, $tClassList)
    Local $aResult = DllCall("UxTheme.dll", "hwnd", 49, "hwnd", $hWND, "struct*", $tClassList)
    If @error Then Return SetError(1, 0, False)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_OpenNcThemeData

Func _WinAPI_ShouldSystemUseDarkMode()
    Local $aResult = DllCall("UxTheme.dll", "bool", 138)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_ShouldSystemUseDarkMode

Func _WinAPI_IsDarkModeAllowedForApp()
    Local $aResult = DllCall("UxTheme.dll", "bool", 139)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_IsDarkModeAllowedForApp

Func _WinAPI_AllowDarkModeForApp($bAllow = True) ;Windows 10 Build 17763
    Return _WinAPI_SetPreferredAppMode($bAllow ? 1 : 0) ; 1 = AllowDark, 0 = Default
EndFunc   ;==>_WinAPI_AllowDarkModeForApp

Func _WinAPI_SetPreferredAppMode($iPreferredAppMode) ;Windows 10 Build 18362+
    Local $aResult = DllCall("UxTheme.dll", "long", 135, "long", $iPreferredAppMode)
    If @error Then Return SetError(1, 0, False)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_SetPreferredAppMode
#EndRegion DarkMode API

 

 

I spent a lot of time comparing back and forth between all of versions with the white border compared to this older version with no border and I cannot figure out the difference. The technique used is the same.

They all use WM_NOTIFY to catch the DTN_DROPDOWN notification, remove the theme with either _WinAPI_SetThemeAppProperties(0) or _WinAPI_SetWindowTheme($iCtrl, "", "") and then color the MonthCal parts using the _GUICtrlMonthCal_SetColor function. By the way, I left some comments in the WM_NOTIFY function because I think that we should use _WinAPI_SetWindowTheme($iCtrl, "", "") and not _WinAPI_SetThemeAppProperties(0) because it (_WinAPI_SetThemeAppProperties) causes problems while SetWindowTheme does not.

Anyway, if you are able to pinpoint whatever the difference is for that white border appearing, I would be very thankful. :)

Edited by WildByDesign
Posted

@argumentum

Thanks

Your method is only a temporary solution. Suppose I have 10 or more notifications; would I have to create 10 or more empty labels?

In my opinion, your approach is not suitable for software developers.

Posted
2 hours ago, WildByDesign said:

Thank you so much for your with fixing the issues related to Au3Stripper. This is a very important fix. :)

I'm just running a diff between your fixed UDF script and the 2.4.0 release to capture the changes that I need to make.

Good

  

2 hours ago, WildByDesign said:

So using quotation marks around functions is what triggers Au3Stripper?

I was a little bit surprised to see that because many examples have the functions in quotes like that.

Au3Stripper with those parameters

#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/rm /sv /sf

was stripping name of the function not strings which looks like function names

for this reason only function declaration (name of the function) was stripped, and not the string

OnAutoItExitRegister("__GUIDarkTheme_OnExit")

Func __GUIDarkTheme_OnExit()
.....
EndFunc   ;==>__GUIDarkTheme_OnExit

in scenario in the following snippet function declaration and function usage (name of the function) is stripped:

OnAutoItExitRegister(__GUIDarkTheme_OnExit)

Func __GUIDarkTheme_OnExit()
.....
EndFunc   ;==>__GUIDarkTheme_OnExit

 

Au3Stripper never strips Strings enclosed within double or single quotes.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

  

2 hours ago, WildByDesign said:

I was a little bit surprised to see that because many examples have the functions in quotes like that.

it was introduced:

Quote
3.3.9.6 (July 10, 2013) (Beta)
AutoIt:
- Added: Functions are now first class objects which means variables can "point" to them and the function can be called through the variable.

 

From this time only occasionally, some examples in HelpFile were changed.
Even more, many Standard UDF's are still not ready for Au3Stripper.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

GUIDarkTheme 2.4.1

  • Added ability to change accent color
    • Accent color is used on focused Edit controls and selected tab control items
    • New function _GUIDarkTheme_AccentColorSet(0xRRGGBB)
  • Updated modern tab control (24H2/25H2) with accent colored tab strip on selected tab
  • Fixed issue with Au3Stripper - (Thanks to @mLipok for fix)
  • Fixed issue with SysMonthCal32 control not showing days of the week
    • Title background shares color with days of the week text color (Windows limitation)

 

@bladem2003 You have colored accent strip on modern tab control now. I am glad that you suggested it because it turned out really nice. You also have a function to change accent color now as well.

By the way, accent color is used for Edit controls when focused and the selected tab in a tab control. Those will change with the function. The Slider thumb is also colored with that same color but I did not make it change with accent color change because I'm not sure if anyone wants that to change too. If yes, next update I can have the Slider thumb accent brush change as well.

Posted
6 hours ago, WildByDesign said:

@UEZ If you have a moment, could you please help us with this white border issue on the SysMonthCal32 control?

I have checked and there is no extended style applied.

I checked your SampleControls.au3 in Dark Mode examples, Page 1 (older, non-DPI aware) and Page 2 (newer, DPI-aware) and both examples also show the white border area.

However, the interesting thing is that I remember some of your very early versions of that script did not have the white border. Lucky for us, I keep everything. So it did not take long for me to find an older version of your script that did not have the border.

Older script in spoiler:

  Hide contents
; Coded by UEZ build 2025-10-17 beta
;not DPI aware!

#include <APIConstants.au3>
#include <AVIConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
#include <GuiMenu.au3>
#include <GuiMonthCal.au3>
#include <GuiScrollBars.au3>
#include <GuiTab.au3>
#include <TreeViewConstants.au3>
#include <ListViewConstants.au3>
#include <WinAPIConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIRes.au3>
#include <WinAPIShellEx.au3>
#include <WinAPISys.au3>
#include <WinAPISysWin.au3>
#include <WinAPITheme.au3>
#include <WindowsConstants.au3>

; initiate System DPI awareness
DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2)

Enum $IHCM_USE_CACHED_VALUE, $IHCM_REFRESH
Enum $APPMODE_DEFAULT = 0, $APPMODE_ALLOWDARK, $APPMODE_FORCEDARK, $APPMODE_FORCELIGHT, $APPMODE_MAX
Const $PRF_CLIENT = 0x04

; Dark Mode Colors (RGB)
Global Const $COLOR_BG_DARK = 0x202020
Global Const $COLOR_TEXT_LIGHT = 0xFFFFFF
Global Const $COLOR_CONTROL_BG = 0x2B2B2B
Global Const $COLOR_EDIT_BG = 0x1E1E1E
Global Const $COLOR_BUTTON_BG = 0x333333
Global Const $COLOR_BORDER = 0x3F3F3F

; Global variables for subclassing (MUST be declared before _Example()!)
Global $g_hGUI = 0, $g_hTab, $g_ListView
Global $g_aControls[50][3] = [[0, 0, 0]] ; [ControlID, hWnd, OldWndProc]
Global $g_iControlCount = 0
Global $g_pSubclassProc = 0

; Global brushes for _WM_CTLCOLOR (avoids memory leaks)
Global $g_hBrushEdit = 0
Global $g_hBrushButton = 0
Global $g_hBrushBg = 0
Global $g_hBrushGreen
Global $g_hLabelGreen = 0, $g_idLabelGreen
Global $g_idLabelPic, $g_hLabelPic
Global $g_hMenu = 0
Global $g_idDate = 0, $g_hDate = 0

; Global variable for tab subclassing
Global $g_hTab_CB, $g_pTab_CB, $g_hProc

; Structure for NM_CUSTOMDRAW notification
Global Const $tagNMCUSTOMDRAW = _
            $tagNMHDR & ";" & _                                                 ; Contains NM_CUSTOMDRAW / NMHDR header among other things
            "dword dwDrawStage;" & _                                            ; Current drawing stage (CDDS_*)
            "handle hdc;" & _                                                   ; Device Context Handle
            "long left;long top;long right;long bottom;" & _                    ; Drawing rectangle
            "dword_ptr dwItemSpec;" & _                                         ; Item index or other info (depending on the control)
            "uint uItemState;" & _                                              ; State Flags (CDIS_SELECTED, CDIS_FOCUS etc.)
            "lparam lItemlParam"                                                ; lParam set by the item (e.g., via LVITEM.lParam)


Global $g_hMenu = 0, $hMenuFont
Global $g_aMenuText = [] ; dynamic array for top-level menu texts
Global $arMenuItems[1][8]
$arMenuItems[0][0] = 0
Global $arSideItems[1][10]
$arSideItems[0][0] = 0

Const $ODT_MENU = 1
Const $ODS_SELECTED = 0x0001
Const $ODS_DISABLED = 0x0004

_Example()

Func _Example()
    ; Create global brushes
    $g_hBrushEdit = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_EDIT_BG))
    $g_hBrushButton = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BUTTON_BG))
    $g_hBrushBg = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BG_DARK))

    #Region GUI
    $g_hGUI = GUICreate("Sample GUI with Dark Mode", 400, 400)
    GUISetIcon(@SystemDir & "\mspaint.exe", 0)
    GUISetBkColor($COLOR_BG_DARK, $g_hGUI)

    ; Register GUI-level WM_CTLCOLOR messages
    GUIRegisterMsg($WM_CTLCOLOREDIT,     "_WM_CTLCOLOR")
    GUIRegisterMsg($WM_CTLCOLORLISTBOX,  "_WM_CTLCOLOR")
    GUIRegisterMsg($WM_CTLCOLORBTN,      "_WM_CTLCOLOR")
    GUIRegisterMsg($WM_CTLCOLORSTATIC,   "_WM_CTLCOLOR")
    GUIRegisterMsg($WM_INITMENUPOPUP,    "_OnInitMenuPopup")
    GUIRegisterMsg($WM_MEASUREITEM,      "WM_MEASUREITEM_Handler")
    GUIRegisterMsg($WM_DRAWITEM,         "WM_DRAWITEM_Handler")
    GUIRegisterMsg($WM_NOTIFY,           "WM_NOTIFY")
    GUIRegisterMsg($WM_ACTIVATE,         "_WM_ACTIVATE_OverpaintLine")
    GUIRegisterMsg($WM_WINDOWPOSCHANGED, "_WM_WINDOWPOSCHANGED_OverpaintLine")
    #EndRegion GUI

    #Region MENU
    Global $g_aMenuText[4]
    $g_aMenuText[0] = "Menu &One"
    $g_aMenuText[1] = "Menu &Two"
    $g_aMenuText[2] = "Menu Th&ree"
    $g_aMenuText[3] = "Menu &Four"

    Local $idMenu1 = GUICtrlCreateMenu($g_aMenuText[0])
    Local $idMenu2 = GUICtrlCreateMenu($g_aMenuText[1])
    GUICtrlCreateMenu($g_aMenuText[2])
    GUICtrlCreateMenu($g_aMenuText[3])
    GUICtrlCreateMenuItem('SubMenu One &A', $idMenu1)
    GUICtrlCreateMenuItem('SubMenu One &B', $idMenu1)

    ; Owner-draw Top-Level Menu einrichten
    _MakeMenuOwnerDraw($g_hGUI)

    #EndRegion MENU

    #Region CONTEXT MENU
    Local $idContextMenu = GUICtrlCreateContextMenu()
    GUICtrlCreateMenuItem("Context Menu", $idContextMenu)
    GUICtrlCreateMenuItem("", $idContextMenu)
    GUICtrlCreateMenuItem("&Properties", $idContextMenu)
    #EndRegion CONTEXT MENU

    #Region PIC
    Local $idPic = GUICtrlCreatePic("", 0, 0, 169, 68)
    GUICtrlSetImage($idPic, "C:\Program Files (x86)\AutoIt3\Examples\GUI\logo4.gif")
    GUICtrlSetTip(-1, '#Region PIC')
    $g_idLabelPic = GUICtrlCreateLabel("Sample Pic", 75, 1, 53, 15)
    $g_hLabelPic = GUICtrlGetHandle($g_idLabelPic)
    #EndRegion PIC

    #Region AVI
    Local $idAvi = GUICtrlCreateAvi("C:\Program Files (x86)\AutoIt3\Examples\GUI\SampleAVI.avi", 0, 180, 10, 32, 32, $ACS_AUTOPLAY)
    GUICtrlSetTip(-1, '#Region AVI')
    GUICtrlCreateLabel("Sample avi", 175, 50)
    #EndRegion AVI

    #Region TAB
    Local $idTab = GUICtrlCreateTab(240, 0, 150, 70), $g_hTab = GUICtrlGetHandle($idTab)
    _AddControlForSubclass($idTab)
    GUICtrlCreateTabItem("One")
    GUICtrlSetTip(-1, '#Region TAB1')
    GUICtrlCreateLabel("Sample Tab", 250, 40)
    GUICtrlCreateTabItem("Two")
    GUICtrlSetTip(-1, '#Region TAB2')
    GUICtrlCreateTabItem("Three")
    GUICtrlSetTip(-1, '#Region TAB3')
    GUICtrlCreateTabItem("")
    $g_hTab = GUICtrlGetHandle($idTab)
    #EndRegion TAB

    #Region COMBO
    Local $idCombo = GUICtrlCreateCombo("Sample Combo", 250, 80, 120, 100)
    GUICtrlSetData($idCombo, "Item 2|Item 3", "Sample Combo")
    _AddControlForSubclass($idCombo)
    GUICtrlSetTip(-1, '#Region COMBO')
    #EndRegion COMBO

    #Region PROGRESS
    Local $idProgress = GUICtrlCreateProgress(60, 80, 150, 20)
    _AddControlForSubclass($idProgress)
    GUICtrlSetTip(-1, '#Region PROGRESS')
    GUICtrlSetData(-1, 60)
    GUICtrlCreateLabel("Progress:", 5, 82)
    #EndRegion PROGRESS

    #Region EDIT
    Local $idEdit = GUICtrlCreateEdit(@CRLF & "  Sample Edit Control", 10, 110, 150, 70)
    _AddControlForSubclass($idEdit)
    GUICtrlSetTip(-1, '#Region EDIT')
    #EndRegion EDIT

    #Region LIST
    Local $idList = GUICtrlCreateList("", 5, 190, 100, 90)
    _AddControlForSubclass($idList)
    GUICtrlSetTip(-1, '#Region LIST')
    GUICtrlSetData(-1, "A.Sample|B.List|C.Control|D.Here", "B.List")
    #EndRegion LIST

    #Region ICON
    GUICtrlCreateIcon("explorer.exe", 0, 175, 120)
    GUICtrlSetTip(-1, '#Region ICON')
    GUICtrlCreateLabel("Icon", 180, 160, 50, 20)
    #EndRegion ICON

    #Region LIST VIEW
    Local $idListView = GUICtrlCreateListView("Sample|ListView|", 110, 190, 110, 80, $LVS_REPORT)
    _AddControlForSubclass($idListView)
    GUICtrlSetBkColor($idListView, $COLOR_EDIT_BG)
    GUICtrlSetColor($idListView, $COLOR_TEXT_LIGHT)
    GUICtrlSetTip(-1, '#Region LIST VIEW')
    GUICtrlCreateListViewItem("A|One", $idListView)
    GUICtrlCreateListViewItem("B|Two", $idListView)
    GUICtrlCreateListViewItem("C|Three", $idListView)
    $g_ListView = GUICtrlGetHandle($idListView)
    #EndRegion LIST VIEW

    #Region GROUP WITH RADIO BUTTONS
    Local $idGroup = GUICtrlCreateGroup("Sample Group", 230, 120)
    GUICtrlSetColor($idGroup, $COLOR_TEXT_LIGHT)
    Local $idRadio1 = GUICtrlCreateRadio("Radio One", 250, 140, 80)
    GUICtrlSetTip($idRadio1, '#Region RADIO1')
    GUICtrlSetState($idRadio1, $GUI_CHECKED)
    Local $idRadio2 = GUICtrlCreateRadio("Radio Two", 250, 165, 80)
    GUICtrlSetTip($idRadio2, '#Region RADIO2')
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($idGroup), "wstr", 0, "wstr", 0)
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($idRadio1), "wstr", 0, "wstr", 0)
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($idRadio2), "wstr", 0, "wstr", 0)
    #EndRegion GROUP WITH RADIO BUTTONS

    #Region UPDOWN
    GUICtrlCreateLabel("UpDown", 350, 115)
    GUICtrlSetColor(-1, $COLOR_TEXT_LIGHT)
    Local $idInput = GUICtrlCreateInput("42", 350, 130, 40, 20)
    _AddControlForSubclass($idInput)
    Local $idUpDown = GUICtrlCreateUpdown(-1)
    _AddControlForSubclass($idUpDown)
    #EndRegion UPDOWN

    #Region LABEL
    $g_idLabelGreen = GUICtrlCreateLabel("Green" & @CRLF & "Label", 350, 165, 40, 40)
    $g_hLabelGreen = GUICtrlGetHandle($g_idLabelGreen)
    GUICtrlSetTip($g_idLabelGreen, '#Region LABEL')
    $g_hBrushGreen = _WinAPI_CreateSolidBrush(_ColorToCOLORREF(0x00FF00)) ; green background

    #Region SLIDER
    GUICtrlCreateLabel("Slider:", 235, 215)
    Local $idSlider = GUICtrlCreateSlider(270, 210, 120, 30)
    _AddControlForSubclass($idSlider)
    GUICtrlSetTip(-1, '#Region SLIDER')
    GUICtrlSetData(-1, 30)
    #EndRegion SLIDER

    #Region INPUT
    Local $idInput2 = GUICtrlCreateInput("Sample Input Box", 235, 255, 130, 20)
    _AddControlForSubclass($idInput2)
    GUICtrlSetTip(-1, '#Region INPUT')
    #EndRegion INPUT

    #Region DATE
    $g_idDate = GUICtrlCreateDate("", 5, 280, 200, 20)
    $g_hDate = GUICtrlGetHandle($g_idDate)
    _AddControlForSubclass($g_idDate)
    GUICtrlSetTip(-1, '#Region DATE')
    GUICtrlCreateLabel("(Date control expands into a calendar)", 10, 305, 200, 20)
    #EndRegion DATE

    #Region BUTTON
    Local $idButton = GUICtrlCreateButton("Sample Button", 10, 330, 100, 30)
    _AddControlForSubclass($idButton)
    GUICtrlSetTip(-1, '#Region BUTTON')
    #EndRegion BUTTON

    #Region CHECKBOX
    Local $idCheckBox = GUICtrlCreateCheckbox("Checkbox", 130, 335, 80, 20)
    GUICtrlSetTip(-1, '#Region CHECKBOX')
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($idCheckBox), "wstr", 0, "wstr", 0)
    #EndRegion CHECKBOX

    #Region TREEVIEW ONE
    Local $idTreeView1 = GUICtrlCreateTreeView(210, 290, 80, 80)
    _AddControlForSubclass($idTreeView1)
    GUICtrlSetBkColor($idTreeView1, $COLOR_EDIT_BG)
    GUICtrlSetColor($idTreeView1, $COLOR_TEXT_LIGHT)
    GUICtrlSetTip(-1, '#Region TREEVIEW ONE')
    Local $idTreeViewItem = GUICtrlCreateTreeViewItem("TreeView", $idTreeView1)
    GUICtrlCreateTreeViewItem("Item1", $idTreeViewItem)
    GUICtrlCreateTreeViewItem("Item2", $idTreeViewItem)
    GUICtrlCreateTreeViewItem("Foo", -1)
    GUICtrlSetState($idTreeViewItem, $GUI_EXPAND)
    #EndRegion TREEVIEW ONE

    #Region TREEVIEW TWO
    Local $idTreeView2 = GUICtrlCreateTreeView(295, 290, 103, 80, $TVS_CHECKBOXES)
    _AddControlForSubclass($idTreeView2)
    GUICtrlSetBkColor($idTreeView2, $COLOR_EDIT_BG)
    GUICtrlSetColor($idTreeView2, $COLOR_TEXT_LIGHT)
    GUICtrlSetTip(-1, '#Region TREEVIEW TWO')
    GUICtrlCreateTreeViewItem("TreeView", $idTreeView2)
    GUICtrlCreateTreeViewItem("With", $idTreeView2)
    GUICtrlCreateTreeViewItem("$TVS_CHECKBOXES", $idTreeView2)
    GUICtrlSetState(-1, $GUI_CHECKED)
    GUICtrlCreateTreeViewItem("Style", $idTreeView2)
    #EndRegion TREEVIEW TWO

    ; Apply Dark Mode
    _ApplyDarkModeToAllControls()

    ; Handle scrollbars for windows that have them
    _EnableDarkScrollBars()

    ; Register a custom window procedure for the tab control for owner-drawing
    $g_hTab_CB = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
    $g_pTab_CB = DllCallbackGetPtr($g_hTab_CB)
    $g_hProc = _WinAPI_SetWindowLong($g_hTab, $GWL_WNDPROC, $g_pTab_CB)

    GUISetState(@SW_SHOW)

    _OverpaintWhiteLine()
    _WinAPI_RedrawWindow($g_hGUI, 0, 0, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                _CleanupSubclassing()
                _CleanupBrushes()
                ExitLoop
        EndSwitch
    WEnd
    ; Restore the original window procedure for the tab control
    _WinAPI_SetWindowLong($g_hTab, $GWL_WNDPROC, $g_hProc)
    DllCallbackFree($g_hTab_CB)

    GUIDelete()
EndFunc   ;==>_Example

Func _OverpaintWhiteLine()
    Local $hDC = _WinAPI_GetWindowDC($g_hGUI)
    If Not $hDC Then Return

    Local $tWndRect = _WinAPI_GetWindowRect($g_hGUI)
    Local $iWndWidth = $tWndRect.right - $tWndRect.left

    ; 1. Caption height
    Local $iCaptionHeight = _WinAPI_GetSystemMetrics($SM_CYCAPTION)

    ; 2. Border height (top)
    Local $iBorderHeight = _WinAPI_GetSystemMetrics($SM_CYSIZEFRAME)
    If $iBorderHeight = 0 Then $iBorderHeight = _WinAPI_GetSystemMetrics($SM_CYFIXEDFRAME)

    ; 3. Determine menu height dynamically
    Local $iMenuHeight = _WinAPI_GetSystemMetrics($SM_CYMENU) ; standard menu height

    ; Alternative: get menu height via GetMenuBarInfo
    Local $tMenuBarInfo = DllStructCreate("dword cbSize;long left;long top;long right;long bottom;handle hwndMenu;handle hwndItem;bool fBarFocused;bool fFocused")
    DllStructSetData($tMenuBarInfo, "cbSize", DllStructGetSize($tMenuBarInfo))
    Local $aResult = DllCall("user32.dll", "bool", "GetMenuBarInfo", "hwnd", $g_hGUI, "long", 0xFFFFFFFD, "long", 0, "ptr", DllStructGetPtr($tMenuBarInfo))

    If IsArray($aResult) And $aResult[0] Then
        ; Calculate the actual menu height from the coordinates
        Local $iMenuTop = $tMenuBarInfo.top
        Local $iMenuBottom = $tMenuBarInfo.bottom
        ; Convert to window coordinates
        $iMenuHeight = ($iMenuBottom - $iMenuTop)
    EndIf

    ; The white line is directly below the menu
    Local $iWhiteLineY = $iCaptionHeight + $iBorderHeight + $iMenuHeight - _WinAPI_GetSystemMetrics($SM_CYFIXEDFRAME) * 2

;~     ConsoleWrite("Caption: " & $iCaptionHeight & ", Border: " & $iBorderHeight & ", Menu: " & $iMenuHeight & " -> White Line at Y=" & $iWhiteLineY & @CRLF)

    ; Overpaint the white line (1x2 pixels)
    Local $tRect = DllStructCreate($tagRECT)
    With $tRect
        .left = 0
        .top = $iWhiteLineY
        .right = $iWndWidth
        .bottom = $iWhiteLineY + 2 ; 2 pixels high
    EndWith

    Local $hBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BG_DARK))
;~     Local $hBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF(0xFF0000))
    _WinAPI_FillRect($hDC, $tRect, $hBrush)
    _WinAPI_DeleteObject($hBrush)
    _WinAPI_ReleaseDC($g_hGUI, $hDC)
EndFunc   ;==>_OverpaintWhiteLine

Func _WM_ACTIVATE_OverpaintLine($hWnd, $iMsg, $wParam, $lParam)
    If $hWnd <> $g_hGUI Then Return $GUI_RUNDEFMSG
    _OverpaintWhiteLine()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_ACTIVATE_OverpaintLine

Func _WM_WINDOWPOSCHANGED_OverpaintLine($hWnd, $iMsg, $wParam, $lParam)
    If $hWnd <> $g_hGUI Then Return $GUI_RUNDEFMSG
    _OverpaintWhiteLine()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_WINDOWPOSCHANGED_OverpaintLine

Func _OnInitMenuPopup($hWnd, $iMsg, $wParam, $lParam)
    ; wParam = HMENU of the popup, lParam = position/index - not needed here
    ; A small delay sometimes helps to ensure the popup window exists
    Sleep(100)

    ; The foreground window is most likely the new menu popup
    Local $hPopup = _WinAPI_GetForegroundWindow()
    If Not $hPopup Then Return $GUI_RUNDEFMSG

    Local $sCls = StringLower(_WinAPI_GetClassName($hPopup))
    If $sCls <> "#32768" And $sCls <> "popupmenu" Then
        ; if no menu popup is detected -> do nothing
        Return $GUI_RUNDEFMSG
    EndIf

    ; Set Theme + AllowDarkMode on the popup itself
    _WinAPI_SetWindowTheme($hPopup, "DarkMode_Explorer", "")
    _WinAPI_AllowDarkModeForWindow($hPopup, True)

    ; Also apply the theme to all child windows of the popup (e.g., scrollbars)
    Local $hChild = _WinAPI_GetWindow($hPopup, $GW_CHILD)
    While $hChild
        Local $sChildCls = StringLower(_WinAPI_GetClassName($hChild))
        ; apply theme specifically for scrollbars, UpDown, etc.
        If $sChildCls = "scrollbar" Or $sChildCls = "msctls_updown32" Or $sChildCls = "traynotifywnd" Then
            _WinAPI_SetWindowTheme($hChild, "DarkMode_Explorer", "")
            _WinAPI_AllowDarkModeForWindow($hChild, True)
        Else
            ; try generically
            _WinAPI_SetWindowTheme($hChild, "DarkMode_Explorer", "")
            _WinAPI_AllowDarkModeForWindow($hChild, True)
        EndIf
        $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
    WEnd

    ; Force refresh so the change is visible immediately
    _WinAPI_FlushMenuThemes()
    _WinAPI_RefreshImmersiveColorPolicyState()
    _WinAPI_RedrawWindow($hPopup, 0, 0, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))

    Return $GUI_RUNDEFMSG
EndFunc   ;==>_OnInitMenuPopup

Func _ColorToCOLORREF($iColor) ;RGB to BGR
    Local $iR = BitAND(BitShift($iColor, 16), 0xFF)
    Local $iG = BitAND(BitShift($iColor, 8), 0xFF)
    Local $iB = BitAND($iColor, 0xFF)
    Return BitOR(BitShift($iB, -16), BitShift($iG, -8), $iR)
EndFunc   ;==>_ColorToCOLORREF

Func _AddControlForSubclass($iCtrlID)
    Local $hCtrl = GUICtrlGetHandle($iCtrlID)
    If $hCtrl Then
        $g_aControls[$g_iControlCount][0] = $iCtrlID
        $g_aControls[$g_iControlCount][1] = $hCtrl
        $g_aControls[$g_iControlCount][2] = 0 ; Placeholder for OldWndProc
        $g_iControlCount += 1
    EndIf
EndFunc   ;==>_AddControlForSubclass

Func _ApplyDarkModeToAllControls()
    ; DWM Dark Mode for the main window
    _WinAPI_SetPreferredAppMode($APPMODE_FORCEDARK)

    ; Create subclass callback
    If Not $g_pSubclassProc Then
        $g_pSubclassProc = DllCallbackRegister("_SubclassProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr")
    EndIf

    ; Subclass all controls
    For $i = 0 To $g_iControlCount - 1
        Local $hCtrl = $g_aControls[$i][1]
        If $hCtrl Then
            Local $sClass = _WinAPI_GetClassName($hCtrl)
            ; Use SetWindowSubclass
            _WinAPI_SetWindowSubclass($hCtrl, DllCallbackGetPtr($g_pSubclassProc), $i, 0)

            ; Special themes for different control types
            Switch StringLower($sClass)
                Case "edit", "richedit", "richedit20a", "richedit20w"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_CFD", 0)
                Case "button"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case "combobox"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_CFD", 0)
                    ; Handle ComboBox child-edit
                    Local $hEdit = _WinAPI_FindWindowEx($hCtrl, 0, "Edit", "")
                    If $hEdit Then
                        _WinAPI_SetWindowTheme($hEdit, "DarkMode_CFD", 0)
                        _WinAPI_AllowDarkModeForWindow($hEdit, True)
                    EndIf
                    ; ComboBox dropdown list
                    Local $hComboLBox = _WinAPI_FindWindowEx($hCtrl, 0, "ComboLBox", "")
                    If $hComboLBox Then
                        _WinAPI_SetWindowTheme($hComboLBox, "DarkMode_Explorer", 0)
                        _WinAPI_AllowDarkModeForWindow($hComboLBox, True)
                    EndIf
                Case "syslistview32"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                    ; ListView extended styles for better dark mode
                    _SendMessage($hCtrl, $LVS_EX_DOUBLEBUFFER, 0x00010000, 0x00010000)
                    ; Also make the ListView header dark
                    Local $hHeader = _SendMessage($hCtrl, $LVM_GETHEADER, 0, 0)
                    If $hHeader Then
                        _WinAPI_SetWindowTheme($hHeader, "DarkMode_ItemsView", 0)
                    EndIf
                Case "systreeview32"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case "msctls_trackbar32" ; Slider
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case "systabcontrol32"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", "") ;must be ""
                    ; tab-Control background
                    _SendMessage($hCtrl, 0x132D, 0, $COLOR_BG_DARK) ; TCM_SETBKCOLOR
                    ; Try to make the UpDown (spinner for too many tabs) dark as well
                    Local $hUpDown = _WinAPI_FindWindowEx($hCtrl, 0, "msctls_updown32", "")
                    If $hUpDown Then _WinAPI_SetWindowTheme($hUpDown, "DarkMode_Explorer", 0)
                Case "listbox"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case "msctls_progress32"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case "scrollbar"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
                Case Else
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
            EndSwitch

            _WinAPI_AllowDarkModeForWindow($hCtrl, True)
        EndIf
    Next

    ; Update theme system
    _WinAPI_RefreshImmersiveColorPolicyState()
    _WinAPI_FlushMenuThemes()
    _WinAPI_DwmSetWindowAttribute($g_hGUI, $DWMWA_USE_IMMERSIVE_DARK_MODE, True)


    ; Redraw GUI
    _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
EndFunc   ;==>_ApplyDarkModeToAllControls

Func _CleanupSubclassing()
    ; Remove all subclasses
    If $g_pSubclassProc Then
        For $i = 0 To $g_iControlCount - 1
            Local $hCtrl = $g_aControls[$i][1]
            If $hCtrl Then
                _WinAPI_RemoveWindowSubclass($hCtrl, DllCallbackGetPtr($g_pSubclassProc), $i)
            EndIf
        Next
        DllCallbackFree($g_pSubclassProc)
        $g_pSubclassProc = 0
    EndIf
EndFunc   ;==>_CleanupSubclassing

Func _SubclassProc($hWnd, $iMsg, $wParam, $lParam, $iID, $pData)
    Switch $iMsg
        Case $WM_NOTIFY
            Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
            Local $hFrom = $tNMHDR.hWndFrom
            Local $iCode = $tNMHDR.Code

            ; --- Adjust ListView Header text color ---
            If $iCode = $NM_CUSTOMDRAW Then
                Local $tNMCUSTOMDRAW = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
                Local $dwDrawStage = $tNMCUSTOMDRAW.dwDrawStage
                Local $hDC = $tNMCUSTOMDRAW.hdc

                Switch $dwDrawStage
                    Case $CDDS_PREPAINT
                        Return $CDRF_NOTIFYITEMDRAW
                    Case $CDDS_ITEMPREPAINT
                        _WinAPI_SetTextColor($hDC, _ColorToCOLORREF($COLOR_TEXT_LIGHT)) ; White text
                        _WinAPI_SetBkColor($hDC, _ColorToCOLORREF($COLOR_BG_DARK))     ; Dark background
                        Return BitOR($CDRF_NEWFONT, $CDRF_NOTIFYPOSTPAINT)
                EndSwitch
            EndIf

        Case $WM_PAINT
            ; Custom Paint for better Dark Mode rendering
            Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
    EndSwitch

    ; Forward standard message to DefSubclassProc
    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_SubclassProc

Func _MakeMenuOwnerDraw($hWnd)
    ; Get menu handle
    $g_hMenu = _GUICtrlMenu_GetMenu($hWnd)
    If Not $g_hMenu Then Return False

    Local $iCount = _GUICtrlMenu_GetItemCount($g_hMenu)
    If $iCount <= 0 Then Return False

    ReDim $g_aMenuText[$iCount]

    For $i = 0 To $iCount - 1
        ; retrieve text via GetMenuStringW (works better than _GUICtrlMenu_GetItemText)
        Local $tText = DllStructCreate("wchar s[256]")
        Local $iLen = DllCall("user32.dll", "int", "GetMenuStringW", _
                                                    "handle", $g_hMenu, _
                                                    "uint", $i, _
                                                    "struct*", $tText, _
                                                    "int", 255, _
                                                    "uint", 0x0400) ; MF_BYPOSITION

        If IsArray($iLen) And $iLen[0] > 0 Then
            $g_aMenuText[$i] = $tText.s
        Else
            $g_aMenuText[$i] = ""
        EndIf

        ; set top-level item to owner-draw
        _GUICtrlMenu_SetItemType($g_hMenu, $i, $MFT_OWNERDRAW, True)
    Next

    ; redraw menu bar immediately
    _GUICtrlMenu_DrawMenuBar($hWnd)
    _WinAPI_RedrawWindow($hWnd, 0, 0, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))

    Return True
EndFunc   ;==>_MakeMenuOwnerDraw

Func WM_MEASUREITEM_Handler($hWnd, $iMsg, $wParam, $lParam)
    Local $tagMEASUREITEM = "uint CtlType;uint CtlID;uint itemID;uint itemWidth;uint itemHeight;ulong_ptr itemData"
    Local $t = DllStructCreate($tagMEASUREITEM, $lParam)
    If Not IsDllStruct($t) Then Return $GUI_RUNDEFMSG

    If $t.CtlType <> $ODT_MENU Then Return $GUI_RUNDEFMSG

    Local $itemID = $t.itemID

    ; itemID is the control ID, not the position!
    ; We must derive the position from the itemID
    Local $iPos = -1
    For $i = 0 To UBound($g_aMenuText) - 1
        If $itemID = ($i + 3) Then ; Offset of 3 due to internal IDs
            $iPos = $i
            ExitLoop
        EndIf
    Next

    ; Fallback: try the itemID directly
    If $iPos < 0 Then $iPos = $itemID
    If $iPos < 0 Or $iPos >= UBound($g_aMenuText) Then $iPos = 0

    Local $sText = $g_aMenuText[$iPos]

    ; Calculate text dimensions
    Local $hDC = _WinAPI_GetDC($hWnd)
    Local $hFont = _SendMessage($hWnd, $WM_GETFONT, 0, 0)
    If Not $hFont Then $hFont = _WinAPI_GetStockObject($DEFAULT_GUI_FONT)
    Local $hOldFont = _WinAPI_SelectObject($hDC, $hFont)

    Local $tSize = _WinAPI_GetTextExtentPoint32($hDC, $sText)
    Local $iTextWidth = $tSize.X
    Local $iTextHeight = $tSize.Y

    _WinAPI_SelectObject($hDC, $hOldFont)
    _WinAPI_ReleaseDC($hWnd, $hDC)

    ; Set dimensions with padding
    $t.itemWidth = $iTextWidth + 1
    $t.itemHeight = $iTextHeight + 1

    Return 1
EndFunc   ;==>WM_MEASUREITEM_Handler

Func WM_DRAWITEM_Handler($hWnd, $iMsg, $wParam, $lParam)
    Local $tagDRAWITEM = "uint CtlType;uint CtlID;uint itemID;uint itemAction;uint itemState;ptr hwndItem;handle hDC;" & _
                         "long left;long top;long right;long bottom;ulong_ptr itemData"
    Local $t = DllStructCreate($tagDRAWITEM, $lParam)
    If Not IsDllStruct($t) Then Return $GUI_RUNDEFMSG

    If $t.CtlType <> $ODT_MENU Then Return $GUI_RUNDEFMSG

    Local $hDC     = $t.hDC
    Local $left    = $t.left
    Local $top     = $t.top
    Local $right   = $t.right
    Local $bottom  = $t.bottom
    Local $state   = $t.itemState
    Local $itemID  = $t.itemID

    ; convert itemID to position
    Local $iPos = -1
    For $i = 0 To UBound($g_aMenuText) - 1
        If $itemID = ($i + 3) Then
            $iPos = $i
            ExitLoop
        EndIf
    Next

    If $iPos < 0 Then $iPos = $itemID
    If $iPos < 0 Or $iPos >= UBound($g_aMenuText) Then $iPos = 0

    Local $sText = $g_aMenuText[$iPos]
    $sText = StringReplace($sText, "&", "")

    ; Colors
    Local $clrBG   = _ColorToCOLORREF($COLOR_BG_DARK)
    Local $clrSel  = _ColorToCOLORREF(0x505050)
    Local $clrText = _ColorToCOLORREF($COLOR_TEXT_LIGHT)

    Static $iDrawCount = 0
    Static $bFullBarDrawn = False

    ; Count how many items were drawn in this "draw cycle"
    $iDrawCount += 1

    ; If we are at the first item AND the bar has not yet been drawn
    If $iPos = 0 And Not $bFullBarDrawn Then
        ; Get the full window width
        Local $tClient = _WinAPI_GetClientRect($hWnd)
        Local $iFullWidth = DllStructGetData($tClient, "right")

        ; Fill the entire menu bar
        Local $tFullMenuBar = DllStructCreate($tagRECT)
        With $tFullMenuBar
            .left = 0
            .top = $top
            .right =  $iFullWidth + 3
            .bottom = $bottom
        EndWith

        Local $hFullBrush = _WinAPI_CreateSolidBrush($clrBG)
        _WinAPI_FillRect($hDC, $tFullMenuBar, $hFullBrush)
        _WinAPI_DeleteObject($hFullBrush)
    EndIf

    ; After drawing all items, mark as "drawn"
    If $iDrawCount >= UBound($g_aMenuText) Then
        $bFullBarDrawn = True
        $iDrawCount = 0
    EndIf

    ; Draw background for the area AFTER the last menu item
    If $iPos = (UBound($g_aMenuText) - 1) Then ; Last menu
        Local $tClient = _WinAPI_GetClientRect($hWnd)
        Local $iFullWidth = DllStructGetData($tClient, "right")

        ; Fill only the area to the RIGHT of the last menu item
        If $right < $iFullWidth Then
            Local $tEmptyArea = DllStructCreate($tagRECT)
            With $tEmptyArea
                .left = $right
                .top = $top
                .right = $iFullWidth + _WinAPI_GetSystemMetrics(7)
                .bottom = $bottom
            EndWith

            Local $hEmptyBrush = _WinAPI_CreateSolidBrush($clrBG)
            _WinAPI_FillRect($hDC, $tEmptyArea, $hEmptyBrush)
            _WinAPI_DeleteObject($hEmptyBrush)
        EndIf
    EndIf

    ; Draw item background (selected = lighter)
    Local $bSelected = BitAND($state, $ODS_SELECTED)
    Local $hBrush = _WinAPI_CreateSolidBrush($bSelected ? $clrSel : $clrBG)

    Local $tItemRect = DllStructCreate($tagRECT)
    With $tItemRect
        .left = $left
        .top = $top
        .right = $right
        .bottom = $bottom
    EndWith

    _WinAPI_FillRect($hDC, $tItemRect, $hBrush)
    _WinAPI_DeleteObject($hBrush)

    ; Setup font
    Local $hFont = _SendMessage($hWnd, $WM_GETFONT, 0, 0)
    If Not $hFont Then $hFont = _WinAPI_GetStockObject($DEFAULT_GUI_FONT)
    Local $hOldFont = _WinAPI_SelectObject($hDC, $hFont)

    _WinAPI_SetBkMode($hDC, $TRANSPARENT)
    _WinAPI_SetTextColor($hDC, $clrText)

    ; Draw text
    Local $tTextRect = DllStructCreate($tagRECT)
    With $tTextRect
        .left = $left + 10
        .top = $top + 4
        .right = $right - 10
        .bottom = $bottom - 4
    EndWith

    DllCall("user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", $sText, "int", -1, "ptr", DllStructGetPtr($tTextRect), "uint", BitOR($DT_SINGLELINE, $DT_VCENTER, $DT_LEFT))

    If $hOldFont Then _WinAPI_SelectObject($hDC, $hOldFont)

    Return 1
EndFunc   ;==>WM_DRAWITEM_Handler

Func _WM_CTLCOLOR($hWnd, $iMsg, $wParam, $lParam)
    Local $hDC = $wParam
    Local $hCtrl = $lParam

    ; If the control is the special green label -> return green background
    If $hCtrl = $g_hLabelGreen Then
        ; black text on a green background
        _WinAPI_SetTextColor($hDC, _ColorToCOLORREF(0x000000))
        _WinAPI_SetBkColor($hDC, _ColorToCOLORREF(0x00FF00))
        _WinAPI_SetBkMode($hDC, $OPAQUE) ; important, otherwise it remains transparent and you cannot see the background
        If $g_hBrushGreen Then Return $g_hBrushGreen
    EndIf

    ; --- Special case: Make "Sample Pic" label transparent ---
    If $hCtrl = $g_hLabelPic Then
        ; set transparent background
        _WinAPI_SetBkMode($hDC, $TRANSPARENT)
        ; set text color (if necessary) - e.g., white
        _WinAPI_SetTextColor($hDC, _ColorToCOLORREF($COLOR_TEXT_LIGHT))
        ; return NULL_BRUSH (stock object), so Windows does NOT fill with your dark brush
        Local $hNull = _WinAPI_GetStockObject(5) ; 5 = NULL_BRUSH
        If $hNull Then Return $hNull
        ; Fallback if not available:
        Return $GUI_RUNDEFMSG
    EndIf

    ; --- Default behavior for all other statics / controls ---
    _WinAPI_SetTextColor($hDC, _ColorToCOLORREF($COLOR_TEXT_LIGHT))

    Local $hBrush = $g_hBrushEdit
    Local $iColor = $COLOR_EDIT_BG

    Switch $iMsg
        Case $WM_CTLCOLORBTN
            $hBrush = $g_hBrushButton
            $iColor = $COLOR_BUTTON_BG
        Case $WM_CTLCOLORSTATIC
            $hBrush = $g_hBrushBg
            $iColor = $COLOR_BG_DARK
    EndSwitch
    _WinAPI_SetBkColor($hDC, _ColorToCOLORREF($iColor))
    _WinAPI_SetBkMode($hDC, $TRANSPARENT)

    Return $hBrush
EndFunc   ;==>_WM_CTLCOLOR

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $tBuffer, $tBuffer2, $iCtrl
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd($tNMHDR.hWndFrom)
    $iIDFrom = $tNMHDR.IDFrom
    $iCode = $tNMHDR.Code

    Switch $hWndFrom
        Case $g_hDate ;thanks to argumentum for the code :-)
            Switch $iCode
                Case $NM_SETFOCUS
                    ; Disable the visual theme when the DateTime control receives focus
                    _WinAPI_SetThemeAppProperties(0) ; we don't necessarily need this, SetWindowTheme below works - WildByDesign

                Case $DTN_DROPDOWN
                    ; Apply dark colors when the calendar dropdown appears
                    Local $iCtrl = _GUICtrlDTP_GetMonthCal($hWndFrom)
                    ;_WinAPI_SetWindowTheme($iCtrl, "", "") ; this will work here without _WinAPI_SetThemeAppProperties - WildByDesign
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TEXT, $COLOR_TEXT_LIGHT)
                    ;_GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TITLEBK, $COLOR_BG_DARK)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_BACKGROUND, $COLOR_BG_DARK)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TITLETEXT, $COLOR_TEXT_LIGHT)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_MONTHBK, $COLOR_BG_DARK)
                    _GUICtrlMonthCal_SetColor($iCtrl, $MCSC_TRAILINGTEXT, $COLOR_TEXT_LIGHT)

                Case $DTN_CLOSEUP
                    ;  Calendar will closed

            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_NOTIFY

Func _CleanupBrushes()
    ; Delete all brushes
    If $g_hBrushEdit Then _WinAPI_DeleteObject($g_hBrushEdit)
    If $g_hBrushButton Then _WinAPI_DeleteObject($g_hBrushButton)
    If $g_hBrushBg Then _WinAPI_DeleteObject($g_hBrushBg)
    If $g_hBrushGreen Then _WinAPI_DeleteObject($g_hBrushGreen)
EndFunc   ;==>_CleanupBrushes

Func _EnableDarkScrollBars()
    ; Try to enable Dark Mode for all scrollbars (also for TreeView with checkboxes)
    For $i = 0 To $g_iControlCount - 1
        Local $hCtrl = $g_aControls[$i][1]
        If Not $hCtrl Then ContinueLoop

        ; 1️ Normal attempt (works for most controls)
        Local $tScrollInfo = _GUIScrollBars_GetScrollInfoEx($hCtrl, 1)
        If IsDllStruct($tScrollInfo) Then
            _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)
        EndIf

        ; 2️ Extension: If the control has its own scrollbar child windows (e.g., TreeView with $TVS_CHECKBOXES)
        Local $hChild = _WinAPI_GetWindow($hCtrl, $GW_CHILD)
        While $hChild
            Local $sClass = _WinAPI_GetClassName($hChild)
            If StringCompare($sClass, "ScrollBar") = 0 Then
                ; Set DarkMode on the ScrollBar itself
                _WinAPI_SetWindowTheme($hChild, "DarkMode_Explorer", 0)
                _WinAPI_AllowDarkModeForWindow($hChild, True)
            EndIf
            $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT)
        WEnd
    Next
EndFunc   ;==>_EnableDarkScrollBars

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
    ; Custom window procedure for tab control with Dark Mode
    Switch $iMsg
        Case $WM_ERASEBKGND
            Return 1 ; Prevent background erase to avoid flicker

        Case $WM_PAINT
            Local $tPaint = DllStructCreate($tagPAINTSTRUCT)
            Local $hDC = DllCall("user32.dll", "handle", "BeginPaint", "hwnd", $hWnd, "struct*", $tPaint)
            If @error Or Not $hDC[0] Then Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam)
            $hDC = $hDC[0]

            ; Get client rectangle
            Local $tClient = _WinAPI_GetClientRect($hWnd)
            If Not IsDllStruct($tClient) Then
                _WinAPI_EndPaint($hWnd, $tPaint)
                Return 0
            EndIf

            Local $iWidth = $tClient.Right
            Local $iHeight = $tClient.Bottom

            ; Create memory DC for double buffering
            Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
            Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
            Local $hOldBmp = _WinAPI_SelectObject($hMemDC, $hBitmap)

            ; Fill background
            Local $hBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BG_DARK))
            _WinAPI_FillRect($hMemDC, $tClient, $hBrush)
            _WinAPI_DeleteObject($hBrush)

            ; Get tab info
            Local $iTabCount = _SendMessage($hWnd, 0x1304, 0, 0) ; TCM_GETITEMCOUNT
            Local $iCurSel = _SendMessage($hWnd, 0x130B, 0, 0)   ; TCM_GETCURSEL

            ; Setup font
            Local $hFont = _SendMessage($hWnd, $WM_GETFONT, 0, 0)
            If Not $hFont Then $hFont = _WinAPI_GetStockObject($DEFAULT_GUI_FONT)
            Local $hOldFont = _WinAPI_SelectObject($hMemDC, $hFont)

            _WinAPI_SetBkMode($hMemDC, $TRANSPARENT)
            _WinAPI_SetTextColor($hMemDC, _ColorToCOLORREF($COLOR_TEXT_LIGHT))

            ; Draw each tab
            Local $tRect, $tRect, $iLeft, $iTop, $iRight, $iBottom
            For $i = 0 To $iTabCount - 1
                ; Get tab rectangle using TCM_GETITEMRECT
                $tRect = DllStructCreate($tagRECT)
                $aResult = DllCall("user32.dll", "lresult", "SendMessageW", _
                                                            "hwnd", $hWnd, _
                                                            "uint", 0x130A, _  ; TCM_GETITEMRECT
                                                            "wparam", $i, _
                                                            "struct*", $tRect)
                If @error Or Not $aResult[0] Then ContinueLoop

                $iLeft = $tRect.Left
                $iTop = $tRect.Top
                $iRight = $tRect.Right
                $iBottom = $tRect.Bottom

                ; Skip if rectangle is invalid
                If $iLeft >= $iRight Or $iTop >= $iBottom Then ContinueLoop

                ; Get tab text
                Local $tItem = DllStructCreate("uint Mask;dword dwState;dword dwStateMask;ptr pszText;int cchTextMax;int iImage;lparam lParam")
                Local $tText = DllStructCreate("wchar Text[256]")
                With $tItem
                    .Mask = 0x0001 ; TCIF_TEXT
                    .pszText = DllStructGetPtr($tText)
                    .cchTextMax = 256
                EndWith

                DllCall("user32.dll", "lresult", "SendMessageW", _
                                                "hwnd", $hWnd, _
                                                "uint", 0x133C, _  ; TCM_GETITEMW
                                                "wparam", $i, _
                                                "struct*", $tItem)

                Local $sText = DllStructGetData($tText, "Text")

                ; Draw tab background
                Local $bSelected = ($i = $iCurSel)
                Local $iTabColor = $bSelected ? $COLOR_BUTTON_BG : $COLOR_BG_DARK
                Local $hTabBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($iTabColor))

                Local $tTabRect = DllStructCreate($tagRECT)
                With $tTabRect
                    .Left = $iLeft
                    .Top = $iTop
                    .Right = $iRight
                    .Bottom = $iBottom
                EndWith

                _WinAPI_FillRect($hMemDC, $tTabRect, $hTabBrush)
                _WinAPI_DeleteObject($hTabBrush)

;~              Local $hTabPen = _WinAPI_CreatePen(0, 1, _ColorToCOLORREF($COLOR_BORDER))
;~              Local $hOldTabPen = _WinAPI_SelectObject($hMemDC, $hTabPen)
;~              _WinAPI_MoveTo($hMemDC, $iLeft, $iBottom)
;~              _WinAPI_LineTo($hMemDC, $iRight, $iBottom)
;~              _WinAPI_SelectObject($hMemDC, $hOldTabPen)
;~              _WinAPI_DeleteObject($hTabPen)

                ; Draw selection indicator (top border for selected tab)
                If $bSelected Then
                    Local $hPen = _WinAPI_CreatePen(0, 2, _ColorToCOLORREF(0x0078D4)) ; Blue accent
                    Local $hOldPen = _WinAPI_SelectObject($hMemDC, $hPen)
                    _WinAPI_MoveTo($hMemDC, $iLeft, $iTop)
                    _WinAPI_LineTo($hMemDC, $iRight - 2, $iTop)
                    _WinAPI_SelectObject($hMemDC, $hOldPen)
                    _WinAPI_DeleteObject($hPen)
                EndIf

                ; Draw separator between tabs
                If $i < $iTabCount - 1 Then
                    Local $hPenSep = _WinAPI_CreatePen(0, 1, _ColorToCOLORREF($COLOR_BORDER))
                    Local $hOldPenSep = _WinAPI_SelectObject($hMemDC, $hPenSep)
                    _WinAPI_MoveTo($hMemDC, $iRight - 1, $iTop + 4)
                    _WinAPI_LineTo($hMemDC, $iRight - 1, $iBottom - 4)
                    _WinAPI_SelectObject($hMemDC, $hOldPenSep)
                    _WinAPI_DeleteObject($hPenSep)
                EndIf

                ; Draw text centered in tab
                Local $tTextRect = DllStructCreate($tagRECT)
                With $tTextRect
                    .Left = $iLeft + 6
                    .Top = $iTop + 3
                    .Right = $iRight - 6
                    .Bottom = $iBottom - 3
                EndWith

                DllCall("user32.dll", "int", "DrawTextW", _
                                            "handle", $hMemDC, _
                                            "wstr", $sText, _
                                            "int", -1, _
                                            "struct*", $tTextRect, _
                                            "uint", BitOR($DT_CENTER, $DT_VCENTER, $DT_SINGLELINE))
            Next

            ; Draw border around entire control
            Local $hBorderPen = _WinAPI_CreatePen(0, 1, _ColorToCOLORREF($COLOR_BORDER))
            Local $hOldBorderPen = _WinAPI_SelectObject($hMemDC, $hBorderPen)
            Local $hNullBrush = _WinAPI_GetStockObject(5) ; NULL_BRUSH
            Local $hOldBorderBrush = _WinAPI_SelectObject($hMemDC, $hNullBrush)

            DllCall("gdi32.dll", "bool", "Rectangle", _
                                        "handle", $hMemDC, _
                                        "int", 0, _
                                        "int", 0, _
                                        "int", $iWidth, _
                                        "int", $iHeight)

            _WinAPI_SelectObject($hMemDC, $hOldBorderPen)
            _WinAPI_SelectObject($hMemDC, $hOldBorderBrush)
            _WinAPI_DeleteObject($hBorderPen)

            ; Copy to screen
            _WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $hMemDC, 0, 0, $SRCCOPY)

            ; Cleanup
            _WinAPI_SelectObject($hMemDC, $hOldFont)
            _WinAPI_SelectObject($hMemDC, $hOldBmp)
            _WinAPI_DeleteObject($hBitmap)
            _WinAPI_DeleteDC($hMemDC)

            _WinAPI_EndPaint($hWnd, $tPaint)
            Return 0



    EndSwitch

    Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WinProc

Func _WinAPI_FindWindowEx($hParent, $hAfter, $sClass, $sTitle = "")
    Local $ret = DllCall("user32.dll", "hwnd", "FindWindowExW", "hwnd", $hParent, "hwnd", $hAfter, "wstr", $sClass, "wstr", $sTitle)
    If @error Or Not IsArray($ret) Then Return 0
    Return $ret[0]
EndFunc   ;==>_WinAPI_FindWindowEx


#Region DarkMode API
Func _WinAPI_ShouldAppsUseDarkMode()
    Local $aResult = DllCall("UxTheme.dll", "bool", 132)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_ShouldAppsUseDarkMode

Func _WinAPI_AllowDarkModeForWindow($hWND, $bAllow = True)
    Local $aResult = DllCall("UxTheme.dll", "bool", 133, "hwnd", $hWND, "bool", $bAllow)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_AllowDarkModeForWindow

Func _WinAPI_FlushMenuThemes()
    Local $aResult = DllCall("UxTheme.dll", "none", 136)
    If @error Then Return SetError(1, 0, False)
    Return True
EndFunc   ;==>_WinAPI_FlushMenuThemes

Func _WinAPI_RefreshImmersiveColorPolicyState()
    Local $aResult = DllCall("UxTheme.dll", "none", 104)
    If @error Then Return SetError(1, 0, False)
    Return True
EndFunc   ;==>_WinAPI_RefreshImmersiveColorPolicyState

Func _WinAPI_IsDarkModeAllowedForWindow($hWND)
    Local $aResult = DllCall("UxTheme.dll", "bool", 137, "hwnd", $hWND)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_IsDarkModeAllowedForWindow

Func _WinAPI_GetIsImmersiveColorUsingHighContrast($iIMMERSIVE_HC_CACHE_MODE)
    Local $aResult = DllCall("UxTheme.dll", "bool", 106, "long", $iIMMERSIVE_HC_CACHE_MODE)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_GetIsImmersiveColorUsingHighContrast

Func _WinAPI_OpenNcThemeData($hWND, $tClassList)
    Local $aResult = DllCall("UxTheme.dll", "hwnd", 49, "hwnd", $hWND, "struct*", $tClassList)
    If @error Then Return SetError(1, 0, False)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_OpenNcThemeData

Func _WinAPI_ShouldSystemUseDarkMode()
    Local $aResult = DllCall("UxTheme.dll", "bool", 138)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_ShouldSystemUseDarkMode

Func _WinAPI_IsDarkModeAllowedForApp()
    Local $aResult = DllCall("UxTheme.dll", "bool", 139)
    If @error Then Return SetError(1, 0, False)
    Return ($aResult[0] <> 0)
EndFunc   ;==>_WinAPI_IsDarkModeAllowedForApp

Func _WinAPI_AllowDarkModeForApp($bAllow = True) ;Windows 10 Build 17763
    Return _WinAPI_SetPreferredAppMode($bAllow ? 1 : 0) ; 1 = AllowDark, 0 = Default
EndFunc   ;==>_WinAPI_AllowDarkModeForApp

Func _WinAPI_SetPreferredAppMode($iPreferredAppMode) ;Windows 10 Build 18362+
    Local $aResult = DllCall("UxTheme.dll", "long", 135, "long", $iPreferredAppMode)
    If @error Then Return SetError(1, 0, False)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_SetPreferredAppMode
#EndRegion DarkMode API

 

 

I spent a lot of time comparing back and forth between all of versions with the white border compared to this older version with no border and I cannot figure out the difference. The technique used is the same.

They all use WM_NOTIFY to catch the DTN_DROPDOWN notification, remove the theme with either _WinAPI_SetThemeAppProperties(0) or _WinAPI_SetWindowTheme($iCtrl, "", "") and then color the MonthCal parts using the _GUICtrlMonthCal_SetColor function. By the way, I left some comments in the WM_NOTIFY function because I think that we should use _WinAPI_SetWindowTheme($iCtrl, "", "") and not _WinAPI_SetThemeAppProperties(0) because it (_WinAPI_SetThemeAppProperties) causes problems while SetWindowTheme does not.

Anyway, if you are able to pinpoint whatever the difference is for that white border appearing, I would be very thankful. :)

here is the result of your post script

 

Screenshot - 2026-05-16 , 07_58_12.png

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
×
×
  • Create New...