Jump to content

Recommended Posts

Posted

There is some discussion here. I am not sure how much moder menu raw is used there. What was left as I xan remeber was the white bottom line. I think them menu needs to be ownerdrawn. I do not if that is the case for all other common controls and dark mode.

Posted (edited)

@UEZ Excellent work!

 

EDIT: I just spent around an hour studying the code. The more that I read, the more my jaw dropped to the floor. Very impressive.

I may have to find an excuse to create an app that uses tabs now. I had always dreamed of dark mode tabs in AutoIt for quite a while now. 😃

I noticed one problem. I see that you've added code to paint over the white line. However, I still see the white line under the menubar.

 

EDIT2: I changed the color of the painted line so that I could see where it was ending up and get a screenshot for you.

 

image.png.b83e022422e0bc392b23c8634f87ac2b.png

 

EDIT3: I've been using the following to get the height of the menubar recently which works when DPI is used or not:

; get menubar height
    $aMenubar = _GUICtrlMenu_GetMenuBarInfo($g_hGUI)
    $iMenubarHeight = $aMenubar[3] - $aMenubar[1]
    ConsoleWrite("menubar height: " & $iMenubarHeight & @CRLF)

 

I wonder if it would be possible to measure the height of the titlebar combined with the height of the menubar to determine the coordinates to paint over the white line. The menubar height measurement is accurate. However, I have never been able to find an accurate measurement yet for the titlebar though.

Edited by WildByDesign
Posted (edited)

Can you please try this?

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
        Local $tWndPos = _WinAPI_GetWindowRect($g_hGUI)
        Local $iWndTop = $tWndPos.top

        ; 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 (1–2 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

I marked the line in red to see where it is painted. Is it now calculated properly?

Edited by UEZ
small update

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)
1 hour ago, UEZ said:

I marked the line in red to see where it is painted. Is it now calculated properly?

This works properly, yes. Thank you. It also worked once I applied DPI scaling of 125%. But once I tried 150% and higher the line did not line up anymore. But I understand that it is not supporting DPI yet.

EDIT: By the way, I wanted to mention that not only is your coding incredible, but I really wanted to point out the fact that your code comments are also very easy to understand and therefore helpful for anyone reading your code. I appreciate the extra effort that you put into code comments. :)

Edited by WildByDesign
Posted
On 10/14/2025 at 2:51 PM, UEZ said:

Does anyone know how to switch the date picker to dark mode?

Nobody in AutoIt has had success with this.

I was looking around at some open source projects that have great dark mode support (Notepad++, Explorer++, System Informer, etc.) to see if there was any source code examples but unfortunately none of these projects utilize SysDateTimePick32 from what I can tell.

Posted
6 hours ago, argumentum said:

Yes, thanks 👍

 

Updated the code for the window when date pick icon was clicked. Still searching for a way to change the date control itself.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

By the way, Windows 11 stable channel build 25H2 (and probably 24H2), build 26200.6899, just added brand new visual styles in aero.msstyles version 10.0.26100.6725 that contains all of the new dark mode classes.

DarkMode_CopyEngine::Progress
DarkMode_CopyEngine_Indeterminate::Progress
DarkMode_DarkTheme::Button
DarkMode_DarkTheme::Combobox
DarkMode_DarkTheme::Edit
DarkMode_DarkTheme::Header
DarkMode_DarkTheme::Link
DarkMode_DarkTheme::Listbox
DarkMode_DarkTheme::ListView
DarkMode_DarkTheme::Progress
DarkMode_DarkTheme::Rebar
DarkMode_DarkTheme::ScrollBar
DarkMode_DarkTheme::Spin
DarkMode_DarkTheme::Static
DarkMode_DarkTheme::Status
DarkMode_DarkTheme::Tab
DarkMode_DarkTheme::TaskDialog
DarkMode_DarkTheme::Toolbar
DarkMode_DarkTheme::Tooltip
DarkMode_DarkTheme::TreeView
DarkMode_DarkTheme_Indeterminate::Progress

Keep in mind, the DarkMode_DarkTheme classes are completely new and different from the DarkMode_Explorer classes that we are used to using.

Posted (edited)
On 10/14/2025 at 2:51 PM, UEZ said:
                Case "msctls_progress32"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_Explorer", 0)

This no longer works on the latest stable channel builds of Windows 11. In particular, builds 24H2 (26100.6899) and 25H2 (26200.6899), it fails to theme the progress control at all. (I just get an empty white box)

On these most recent stable channel builds of Windows 11, it now has to be:

Case "msctls_progress32"
                    _WinAPI_SetWindowTheme($hCtrl, "DarkMode_CopyEngine", 0)

With your example for SampleControls and also the DarkMode UDF, we are going to have to start comparing the builds with macro @OSBuild to determine which theme class to use.

These newer DarkMode_CopyEngine* and DarkMode_DarkTheme* theme classes seem to be improved significantly over the former DarkMode_Explorer* classes. A lot of visual issues are fixed now as well. So for any users who are on Windows 11 with the latest windows updates, using DarkMode_DarkTheme* is by far the better option over DarkMode_Explorer* classes.

MS even added nice dark theme for statusbar as well in DarkMode_DarkTheme* class. ListViews are improved too.

I'm not sure if we should update the older DarkMode UDF or start a new one. In my opinion, of the older DarkMode UDF versions, the GUIDarkMode_v0.02mod.au3 from the fabulous @argumentum is the most functional and best option to use as a base.

Edited by WildByDesign
  • 2 weeks later...
Posted

This is slightly off-topic from your example here, @UEZ, however I am wondering if such a thing can be done to apply dark mode to the windows/controls of other win32 apps. For example, classic Notepad or classic Calculator.

I am trying to put together an example which requires GUIDarkMode_v0.02mod.au3 from @argumentum which simplifies applying to all controls. It launches Notepad (hopefully classic because modern UWP Notepad would not be ideal) and applies dark mode to the window and controls.

I used the ideas from your SampleControls example by following up with refreshing the state, menu themes and redrawing the window.

Unfortunately it only changes the caption to dark mode while the window and controls stay in light mode. This is something that I've wanted to do as a project for a while now but never had any success. Eg. attempt to apply dark mode to the windows/controls of any running processes

Do you have any ideas for how to enforce this?

#include "GUIDarkMode_v0.02mod.au3"

Global $hNotepadWnd

Example()

Func Example()
    ; Run Notepad
    Run("notepad.exe")

    ; Wait 10 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 10)

    ; Retrieve the handle of the Notepad window using the classname of Notepad.
    $hNotepadWnd = WinGetHandle("[CLASS:Notepad]")
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Notepad.")
        Exit
    EndIf

    ; Display the handle of the Notepad window.
    ConsoleWrite("Notepad handle: " & $hNotepadWnd & @CRLF)

    Sleep(1000)

    GuiDarkmodeApply($hNotepadWnd)

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


    ; Redraw GUI
    _WinAPI_RedrawWindow($hNotepadWnd, 0, 0, $RDW_UPDATENOW)
    _WinAPI_RedrawWindow($hNotepadWnd, 0, 0, BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))

    ; Close the Notepad window using the handle returned by WinGetHandle.
    ;WinClose($hNotepadWnd)
EndFunc   ;==>Example

 

  • 1 month later...
Posted

One subtle (yet important) thing that I just noticed now that is missing is the menubar (top-level) items don't have a hover color. Once you click on one of the items, you can then hover the cursor back and forth and it will show a hover color. But it really should have a subtle hover cover initially as well.

Would you please be able to add that?

Posted
3 hours ago, WildByDesign said:

One subtle (yet important) thing that I just noticed now that is missing is the menubar (top-level) items don't have a hover color. Once you click on one of the items, you can then hover the cursor back and forth and it will show a hover color. But it really should have a subtle hover cover initially as well.

Would you please be able to add that?

Code updated -> see 1st post.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

  • 4 weeks later...
Posted

@UEZ I have tried using your fantastic ownerdrawn dark mode menubar/menu as a base for another project because your example is much more compact (and newer) in comparison to the older ModernMenuRaw UDF that goes back a decade or more. But I was unable to figure out how to run any functions from those menus.

To rule out an issue in my own script, I decided to just add a simple "About" menu item to your example under Menu One. It also failed to run any functions. I tried with the default GUIGetMsg but when that failed I also switched to OnEvent mode and that also failed.

The only thing that I could determine for sure was that any menu items added would report 0 as a handle. They did report their Control IDs but those still failed to run any functions.

Do you have any idea what could be the cause of this?

I feel like your ownerdrawn example for dark mode menubar/menu could be the best example that we have in current times for AutoIt. I just can't seem to get functions to work from the menu items like I do in a few of my other projects. Ideally, I would like to retire ModernMenuRaw UDF from my projects and use yours if possible.

Posted (edited)

Added "About" menu entry in Sysmenu (left upper corner in the GUI) and in "Menu One". Check out _WM_MENUCOMMAND function.

See first post.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
22 minutes ago, UEZ said:

Added "About" menu entry in Sysmenu (left upper corner in the GUI) and in "Menu One". Check out _WM_MENUCOMMAND function.

You, Sir, are a genius. Thank you kindly. :)

  • 1 month later...
Posted
On 10/14/2025 at 2:51 PM, UEZ said:

Does anyone know how to switch the date picker to dark mode?

I have been thinking about this recently. 

First of all, I would recommend following this issue: Any hope for a datetimepicker subclass that works?

The guy that does the majority of dark mode subclassing work on Notepad++ also does darkmodelib which he uses in 7zip-Dark7zip which is fantastic, by the way. But anyway, it is worth following that issue because at some point in time he will likely complete that datatimepicker subclass and it may give some ideas on how to properly do it.

As far as non-proper methods go, at least temporarily, do you think something like _WinAPI_UpdateLayeredWindowEx or _WinAPI_UpdateLayeredWindowIndirect could work?

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