Page 2 of 3 FirstFirst 123 LastLast
Results 41 to 80 of 111

Thread: Windows 10 Dark Mode & VB6 apps

  1. #41

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by wqweto View Post
    Call Win32SetWindowTheme(m_hWnd, vbNullString, "DarkMode::FileExplorerBannerContainer")
    Please can you show me the content of your function "Win32SetWindowTheme" and the declaration of the windows api "SetWindowTheme"?

  2. #42

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    VBCCR18 DTPicker control:

    Name:  VBCCCR18_DTPicker.png
Views: 246
Size:  34.8 KB

    Using the code:
    Code:
    SetWindowTheme dtpSelectDate.hwnd, 0&, StrPtr("DarkMode::FileExplorerBannerContainer")
    Name:  VBCCCR18_DTPicker_DarkMode.png
Views: 244
Size:  33.8 KB

    The editbox got the darkmode-look but the icons in the right dropdown-section are gone and the calendar still looks normal...

    I also tried .hWndCalendar but no effect.

  3. #43
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: Windows 10 Dark Mode & VB6 apps

    > The editbox got the darkmode-look but the icons in the right dropdown-section are gone and the calendar still looks normal...

    This is the best I could achieve back when I was researching the darkmode for our apps.

    cheers,
    </wqw>

  4. #44
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: Windows 10 Dark Mode & VB6 apps

    It expects Unicode strings so the declare itself has to be in vb6

    Public Declare Function SetWindowTheme Lib "uxtheme" (ByVal hwnd As LongPtr, ByVal pszSubAppName As LongPtr, ByVal pszSubIdList As LongPtr) As Long

    You use 0 for NULL and StrPtr("text") for anything besides null. Presumably wqweto's wrapper is handling that.

    (As always if you don't have oleexp.tlb, VB6LongPtr.tlb, or another existing def, you can add LongPtr support with Public Enum LongPtr: [_]: End Enum)

    In tB my API lib accepts the LongPtr version and has an overload to also accept String directly,
    Public DeclareWide PtrSafe Function SetWindowTheme Lib "uxtheme" (ByVal hwnd As LongPtr, ByVal pszSubAppName As String, ByVal pszSubIdList As String) As Long
    Last edited by fafalone; Apr 28th, 2026 at 08:13 AM.

  5. #45
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: Windows 10 Dark Mode & VB6 apps

    Yes, it's a thin convenience wrapper over the LongPtr (optional) parameters:

    Code:
    Private Declare Function SetWindowTheme Lib "uxtheme" (ByVal hwnd As Long, ByVal pszSubAppName As Long, ByVal pszSubIdList As Long) As Long
    
    Public Function Win32SetWindowTheme(ByVal hwnd As Long, pszSubAppName As String, Optional pszSubIdList As String) As Long
        Win32SetWindowTheme = SetWindowTheme(hwnd, StrPtr(pszSubAppName), StrPtr(pszSubIdList))
    End Function
    cheers,
    </wqw>

  6. #46
    Member
    Join Date
    Feb 2023
    Posts
    55

    Re: Windows 10 Dark Mode & VB6 apps

    Anyone got that working for ImageCombos?

  7. #47

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Chris_G33 View Post
    Anyone got that working for ImageCombos?
    I use this code for VBCCR ImageCombos DarkMode:

    Code:
    If sTypeName = "ImageCombo" Then
       If g_IsWindows10orHigher = True Then
          Call SetDarkModeCFD(CTL.hWndCombo) ' "DarkMode_CFD"
          Call SetDarkModeExplorer(CTL.hWndList) ' "DarkMode_Explorer"
       End If
    End If
    This will change the combobox to DarkMode and the scrollbar of the dropdown-list but you cant change the background color of the dropdown-list.
    I guess the dropdown-list is owner-drawed and ignore the darkmode settings.

  8. #48

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    VBCCR 1.8.86

    The best DarkMode for the DateTimePicker-Control we can get so far.

    Maybe we will find a solution to change the color of the right DropDown-Button in the future too:

    Code:
    DTPicker1.VisualStyles = FALSE
    SetWindowTheme DTPicker1.hwnd, 0&, StrPtr("DarkMode::FileExplorerBannerContainer")
    DTPicker1.CalendarBackColor = gDarkMode_BackColor
    DTPicker1.CalendarForeColor = gDarkMode_FontColor
    DTPicker1.CalendarTitleBackColor = gDarkMode_BackColor2
    DTPicker1.CalendarTitleForeColor = gDarkMode_FontColor
    Name:  DTPicker_Darkmode.png
Views: 206
Size:  75.3 KB

  9. #49
    Lively Member
    Join Date
    Mar 2020
    Posts
    82

    Re: Windows 10 Dark Mode & VB6 apps

    I get this with DTPicker and MonthView :

    Name:  dtpicker.jpg
Views: 210
Size:  29.8 KB
    Calendar does not fill up its window.

    Name:  monthview.jpg
Views: 209
Size:  30.6 KB
    Monthview is cropped

  10. #50

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    @Crapahute
    i guess you dont use VBCCR v1.8.86 ?

  11. #51
    Lively Member
    Join Date
    Mar 2020
    Posts
    82

    Re: Windows 10 Dark Mode & VB6 apps

    I do

    Edit :

    Oops, my bad, for an obscure reason, the recorded ocx was not the one in my SYSWOW64 folder. Thank you for sending me on this track.
    Now I only have the problem with the cropped MonthView.
    Last edited by Crapahute; Apr 30th, 2026 at 01:49 AM.

  12. #52

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Crapahute View Post
    Now I only have the problem with the cropped MonthView.
    I cant reproduce this with VBCCR v1.8.86 and the MonthView.
    You should provide more information and ask Krool about this at the VBCCR thread: https://www.vbforums.com/showthread....mmon-controls)

  13. #53
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: Windows 10 Dark Mode & VB6 apps

    Mith,

    the drop-down calendar can be made to dark mode on the DropDown event. It is now fixed that it will resize itself upon WM_THEMECHANGED.

    Code:
    Private Sub DTPicker1_DropDown()
    SetWindowTheme DTPicker1.hWndCalendar, 0&, StrPtr("DarkMode::FileExplorerBannerContainer")
    End Sub
    Name:  DarkDTPicker.png
Views: 183
Size:  4.2 KB

    Crapahute,

    the MonthView now recompute itself upon WM_THEMECHANGED so you can use SetWindowTheme to make it darkmode and all is fine.
    Last edited by Krool; May 1st, 2026 at 08:15 AM.

  14. #54

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Krool View Post
    the drop-down calendar can be made to dark mode on the DropDown event. It is now fixed that it will resize itself upon WM_THEMECHANGED.
    Cool, DarkMode works now with .VisualStyles=True for the DTPicker-Control (v1.8.89)!
    Attached Images Attached Images  

  15. #55
    Lively Member
    Join Date
    Mar 2020
    Posts
    82

    Re: Windows 10 Dark Mode & VB6 apps

    This is my work in progress. I tried to find a solution for the ForeColor of OptionButtons and CheckBoxes. The code is dirty as it is only a test. It works for me (VBCCR + VBFLEXGRID).

    Name:  test04.jpg
Views: 162
Size:  43.7 KB

    Code:
    '
    ' Tested under Windows 11 with VBCCR v1.08.0092
    '
    ' Everything does not render well in DarkMode,
    ' especially the OptionButtons and the CheckBoxes.
    ' Therefore, we need to place an invisible label called
    ' LabelOption(0) on the form.
    ' This will be used to create a clickable pseudo-caption
    ' for these objects.
    ' The OptionButtons and the Checkboxes will be shorten
    ' so that their real caption disappear leaving only
    ' their icon visible. Then a LabelOption is created and
    ' positioned next to the icon. This way, the icon
    ' and the LabelOption are clickable.
    ' With VBCCR, LabelOption(0) can be a LabelW.
    ' We need to add the following to the form code :
    '
    'Private Sub LabelOption_Click(Index As Integer)
    '    LabelOptionClick Me, Index
    'End Sub
    '
    ' If you don’t put a LabelOption(0) on the form,
    ' labels are dynamically created as captions but
    ' they won’t be clickable.
    ' It is also done this way for option buttons
    ' and check boxes that are in a container.
    '
    ' For OptionButtonW and CheckBoxW, you can choose
    ' to draw the object. You have to change the
    ' property DrawMode of your object to 1.
    ' Then in your form add for each object (ex: OptionButtonW1 and CheckBoxW1):
    '
    'Private Sub OptionButtonW1_OwnerDraw(ByVal Action As Long, ByVal State As Long, ByVal hDC As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)
    '    OBWOwnerDraw Me, OptionButtonW1, hDC
    'End Sub
    '
    'Private Sub CheckBoxW1_OwnerDraw(ByVal Action As Long, ByVal State As Long, ByVal hDC As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)
    '    CBOwnerDraw Me, CheckBoxW1, hDC
    'End Sub
    '
    ' It's easier and cleaner to use BUT the drawn icons aren't in DarkMode.
    '
    mDarkMode.bas
    Last edited by Crapahute; May 3rd, 2026 at 07:02 AM.

  16. #56

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    to fix the CheckboxW and OptionButtonW color problem you should use .DrawMode=1 and at the OwnerDraw-Event you should use a function to draw the control yourself.

  17. #57

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Krool View Post
    Mith,

    the drop-down calendar can be made to dark mode on the DropDown event. It is now fixed that it will resize itself upon WM_THEMECHANGED.

    Code:
    Private Sub DTPicker1_DropDown()
    SetWindowTheme DTPicker1.hWndCalendar, 0&, StrPtr("DarkMode::FileExplorerBannerContainer")
    End Sub
    Name:  DarkDTPicker.png
Views: 183
Size:  4.2 KB
    I wanted to point out again that the dropdown calendar in dark mode style cannot be used in practice because the two buttons (arrows) for month forward and back are so tiny that you can hardly see them and it is also extremely difficult to click them. I have to use this hybrid-DarkMode-Style: https://www.vbforums.com/showthread....=1#post5690100

  18. #58
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: Windows 10 Dark Mode & VB6 apps

    Yes, and when CheckBox / OptionButton do not work out of the box then this whole dark mode thing is a mess work in progress by MS and not yet ready for production.
    The CommandButton does work. So there the internal DrawThemeText makes a light text color.
    It cannot be the solution to be forced to owner draw..

  19. #59
    Lively Member
    Join Date
    Mar 2020
    Posts
    82

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Mith View Post
    to fix the CheckboxW and OptionButtonW color problem you should use .DrawMode=1 and at the OwnerDraw-Event you should use a function to draw the control yourself.
    I have followed your suggestion and modified my code (https://www.vbforums.com/showthread....=1#post5690179).
    The problem is that the circle and the box are no longer in dark mode.

  20. #60

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Krool View Post
    Yes, and when CheckBox / OptionButton do not work out of the box then this whole dark mode thing is a mess work in progress by MS and not yet ready for production.
    The CommandButton does work. So there the internal DrawThemeText makes a light text color.
    It cannot be the solution to be forced to owner draw..
    I only use ownerdraw (DrawThemeBackground) for the CheckBox / OptionButton because i didnt found another solution to "DarkMode" them.

  21. #61

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Crapahute View Post
    The problem is that the circle and the box are no longer in dark mode.
    Which APIs do you use to draw them? DrawThemeBackground?

  22. #62
    Lively Member
    Join Date
    Mar 2020
    Posts
    82

    Re: Windows 10 Dark Mode & VB6 apps

    Here is an excerpt of my code I have uploaded above (mDarkMode.bas)

    Code:
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    Private Declare Function OpenThemeData Lib "uxtheme.dll" (ByVal hwnd As Long, ByVal pszClassList As Long) As Long
    Private Declare Function CloseThemeData Lib "uxtheme.dll" (ByVal hTheme As Long) As Long
    Private Declare Function DrawThemeBackground Lib "uxtheme.dll" (ByVal hTheme As Long, ByVal hDC As Long, ByVal iPartId As Long, ByVal iStateId As Long, pRect As RECT, ByVal pClipRect As Long) As Long
    Private Declare Function SetTextColor Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long) As Long
    Private Declare Function SetBkMode Lib "gdi32" (ByVal hDC As Long, ByVal nBkMode As Long) As Long
    Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
    Private Const BP_RADIOBUTTON = 2
    Private Const RBS_UNCHECKEDNORMAL = 1
    Private Const RBS_UNCHECKEDHOT = 2
    Private Const RBS_UNCHECKEDPRESSED = 3
    Private Const RBS_UNCHECKEDDISABLED = 4
    Private Const RBS_CHECKEDNORMAL = 5
    Private Const RBS_CHECKEDHOT = 6
    Private Const RBS_CHECKEDPRESSED = 7
    Private Const RBS_CHECKEDDISABLED = 8
    Private Const TRANSPARENT = 1
    Private Const BP_CHECKBOX = 3
    Private Const CBS_UNCHECKEDNORMAL = 1
    Private Const CBS_UNCHECKEDHOT = 2
    Private Const CBS_UNCHECKEDPRESSED = 3
    Private Const CBS_UNCHECKEDDISABLED = 4
    Private Const CBS_CHECKEDNORMAL = 5
    Private Const CBS_CHECKEDHOT = 6
    Private Const CBS_CHECKEDPRESSED = 7
    Private Const CBS_CHECKEDDISABLED = 8
    
    
    Public Sub CBOwnerDraw(frm As Form, obj As Object, ByVal hDC As Long)
    '
    ' Draw a CheckBoxW
    ' obj.DrawMode must be = 1 = ChkDrawModeOwnerDraw
    '
    ' In your form, add something like this for each of your CheckBoxW:
    '
    'Private Sub CheckBoxW1_OwnerDraw(ByVal Action As Long, ByVal State As Long, ByVal hDC As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)
    '    CBOwnerDraw Me, CheckBoxW1, hDC
    'End Sub
    '
    Dim hTheme  As Long
    Dim rc      As RECT
    Dim ST      As Long
    
        hTheme = OpenThemeData(frm.hwnd, StrPtr("BUTTON"))
    
        rc.Left = 2
        rc.Top = 2
        rc.Right = 18
        rc.Bottom = 18
    
        If obj.Value = 1 Then
            ST = CBS_CHECKEDNORMAL
        Else
            ST = CBS_UNCHECKEDNORMAL
        End If
    
        DrawThemeBackground hTheme, hDC, BP_CHECKBOX, ST, rc, 0
        CloseThemeData hTheme
        SetBkMode hDC, TRANSPARENT
        SetTextColor hDC, FRMFORECOLOR
    
        TextOut hDC, 24, 2, obj.Caption, Len(obj.Caption)
    End Sub
    
    Public Sub OBWOwnerDraw(frm As Form, obj As Object, ByVal hDC As Long)
    '
    ' Draw an OptionButtonW
    ' obj.DrawMode must be = 1 = OptDrawModeOwnerDraw
    '
    ' In your form, add something like this for each of your OptionButtonW:
    '
    'Private Sub OptionButtonW1_OwnerDraw(ByVal Action As Long, ByVal State As Long, ByVal hDC As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)
    '    OBWOwnerDraw Me, OptionButtonW1, hDC
    'End Sub
    '
    Dim hTheme  As Long
    Dim rc      As RECT
    Dim part    As Long
    Dim ST      As Long
    
        hTheme = OpenThemeData(frm.hwnd, StrPtr("BUTTON"))
    
        rc.Left = 2
        rc.Top = 2
        rc.Right = 18
        rc.Bottom = 18
    
        part = BP_RADIOBUTTON
    
        If obj.Value = True Then
            ST = RBS_CHECKEDNORMAL
        Else
            ST = RBS_UNCHECKEDNORMAL
        End If
    
        DrawThemeBackground hTheme, hDC, part, ST, rc, 0
        CloseThemeData hTheme
        SetBkMode hDC, TRANSPARENT
        SetTextColor hDC, FRMFORECOLOR
    
        TextOut hDC, 24, 2, obj.Caption, Len(obj.Caption)
    End Sub

  23. #63
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: Windows 10 Dark Mode & VB6 apps

    Another thing to think about would be a "ForceForeColor" property for CheckBoxW etc. to make a temporary API hook on DrawThemeText and redirect to DrawThemeTextEx to apply the text color. Either during WM_PAINT or on CDDS_PREPAINT until CDDS_POSTPAINT.

  24. #64
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Crapahute View Post
    Here is an excerpt of my code I have uploaded above (mDarkMode.bas)

    Code:
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End Type
    Private Declare Function OpenThemeData Lib "uxtheme.dll" (ByVal hwnd As Long, ByVal pszClassList As Long) As Long
    Private Declare Function CloseThemeData Lib "uxtheme.dll" (ByVal hTheme As Long) As Long
    Private Declare Function DrawThemeBackground Lib "uxtheme.dll" (ByVal hTheme As Long, ByVal hDC As Long, ByVal iPartId As Long, ByVal iStateId As Long, pRect As RECT, ByVal pClipRect As Long) As Long
    Private Declare Function SetTextColor Lib "gdi32" (ByVal hDC As Long, ByVal crColor As Long) As Long
    Private Declare Function SetBkMode Lib "gdi32" (ByVal hDC As Long, ByVal nBkMode As Long) As Long
    Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hDC As Long, ByVal X As Long, ByVal Y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
    Private Const BP_RADIOBUTTON = 2
    Private Const RBS_UNCHECKEDNORMAL = 1
    Private Const RBS_UNCHECKEDHOT = 2
    Private Const RBS_UNCHECKEDPRESSED = 3
    Private Const RBS_UNCHECKEDDISABLED = 4
    Private Const RBS_CHECKEDNORMAL = 5
    Private Const RBS_CHECKEDHOT = 6
    Private Const RBS_CHECKEDPRESSED = 7
    Private Const RBS_CHECKEDDISABLED = 8
    Private Const TRANSPARENT = 1
    Private Const BP_CHECKBOX = 3
    Private Const CBS_UNCHECKEDNORMAL = 1
    Private Const CBS_UNCHECKEDHOT = 2
    Private Const CBS_UNCHECKEDPRESSED = 3
    Private Const CBS_UNCHECKEDDISABLED = 4
    Private Const CBS_CHECKEDNORMAL = 5
    Private Const CBS_CHECKEDHOT = 6
    Private Const CBS_CHECKEDPRESSED = 7
    Private Const CBS_CHECKEDDISABLED = 8
    
    
    Public Sub CBOwnerDraw(frm As Form, obj As Object, ByVal hDC As Long)
    '
    ' Draw a CheckBoxW
    ' obj.DrawMode must be = 1 = ChkDrawModeOwnerDraw
    '
    ' In your form, add something like this for each of your CheckBoxW:
    '
    'Private Sub CheckBoxW1_OwnerDraw(ByVal Action As Long, ByVal State As Long, ByVal hDC As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)
    '    CBOwnerDraw Me, CheckBoxW1, hDC
    'End Sub
    '
    Dim hTheme  As Long
    Dim rc      As RECT
    Dim ST      As Long
    
        hTheme = OpenThemeData(frm.hwnd, StrPtr("BUTTON"))
    
        rc.Left = 2
        rc.Top = 2
        rc.Right = 18
        rc.Bottom = 18
    
        If obj.Value = 1 Then
            ST = CBS_CHECKEDNORMAL
        Else
            ST = CBS_UNCHECKEDNORMAL
        End If
    
        DrawThemeBackground hTheme, hDC, BP_CHECKBOX, ST, rc, 0
        CloseThemeData hTheme
        SetBkMode hDC, TRANSPARENT
        SetTextColor hDC, FRMFORECOLOR
    
        TextOut hDC, 24, 2, obj.Caption, Len(obj.Caption)
    End Sub
    
    Public Sub OBWOwnerDraw(frm As Form, obj As Object, ByVal hDC As Long)
    '
    ' Draw an OptionButtonW
    ' obj.DrawMode must be = 1 = OptDrawModeOwnerDraw
    '
    ' In your form, add something like this for each of your OptionButtonW:
    '
    'Private Sub OptionButtonW1_OwnerDraw(ByVal Action As Long, ByVal State As Long, ByVal hDC As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)
    '    OBWOwnerDraw Me, OptionButtonW1, hDC
    'End Sub
    '
    Dim hTheme  As Long
    Dim rc      As RECT
    Dim part    As Long
    Dim ST      As Long
    
        hTheme = OpenThemeData(frm.hwnd, StrPtr("BUTTON"))
    
        rc.Left = 2
        rc.Top = 2
        rc.Right = 18
        rc.Bottom = 18
    
        part = BP_RADIOBUTTON
    
        If obj.Value = True Then
            ST = RBS_CHECKEDNORMAL
        Else
            ST = RBS_UNCHECKEDNORMAL
        End If
    
        DrawThemeBackground hTheme, hDC, part, ST, rc, 0
        CloseThemeData hTheme
        SetBkMode hDC, TRANSPARENT
        SetTextColor hDC, FRMFORECOLOR
    
        TextOut hDC, 24, 2, obj.Caption, Len(obj.Caption)
    End Sub
    If needed there's a complete header port of those theme element consts already converted to VBx compatible syntax in WinDevLib; grouped into enums. If you don't want to even open it in tB it's browsable online, https://github.com/fafalone/WinDevLi...tl.twin#L11056
    Same file has all the dwm/uxtheme APIs including a number of undocumented dark mode APIs. Large majority can be copy/pasted to vb6 as-is but you need sometimes e.g. change "DeclareWide" back to "Declare" and As String back to As Long[Ptr].

  25. #65

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Crapahute View Post
    Here is an excerpt of my code I have uploaded above (mDarkMode.bas)

    [CODE]

    'Private Sub CheckBoxW1_OwnerDraw(ByVal Action As Long, ByVal State As Long, ByVal hDC As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)
    ' CBOwnerDraw Me, CheckBoxW1, hDC
    'End Sub
    '
    Dim hTheme As Long
    Dim rc As RECT
    Dim ST As Long

    hTheme = OpenThemeData(frm.hwnd, StrPtr("BUTTON"))

    rc.Left = 2
    rc.Top = 2
    rc.Right = 18
    rc.Bottom = 18

    If obj.Value = 1 Then
    ST = CBS_CHECKEDNORMAL
    Else
    ST = CBS_UNCHECKEDNORMAL
    End If

    DrawThemeBackground hTheme, hDC, BP_CHECKBOX, ST, rc, 0
    CloseThemeData hTheme
    SetBkMode hDC, TRANSPARENT
    SetTextColor hDC, FRMFORECOLOR

    TextOut hDC, 24, 2, obj.Caption, Len(obj.Caption)
    End Sub
    I guess i found your problem: after OpenThemeData you need to call the API GetThemePartSize to get the DarkMode-image.

    btw: your code also doesnt take care of the following control-properties:
    - TextAlignment
    - left, top, right, bottom
    - state (focus, disabled, enabled, show prefix, ...)
    - WordWrap
    Last edited by Mith; May 3rd, 2026 at 06:50 PM.

  26. #66
    Lively Member
    Join Date
    Mar 2020
    Posts
    82

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Mith View Post
    I guess i found your problem: after OpenThemeData you need to call the API GetThemePartSize to get the DarkMode-image.

    btw: your code also doesnt take care of the following control-properties:
    - TextAlignment
    - left, top, right, bottom
    - state (focus, disabled, enabled, show prefix, ...)
    - WordWrap
    I don't get it. I have changed my code to use GetThemePartSize to get the real size of the image but how can I use it to get the DarkMode-image ?

    For the other properties, I haven't worked on them yet as I don't need them for the moment.

    Code:
    Private Type SIZE
        cx As Long
        cy As Long
    End Type
    Private Const TS_DRAW = 2 ' TS_MIN = 0  TS_TRUE = 1
    Private Declare Function GetThemePartSize Lib "uxtheme.dll" (ByVal hTheme As Long, ByVal hDC As Long, ByVal iPartId As Long, ByVal iStateId As Long, ByVal prc As Long, ByVal eSize As Long, psz As SIZE) As Long
    
    Public Sub CBOwnerDraw(frm As Form, obj As Object, ByVal hDC As Long)
    Dim hTheme  As Long
    Dim rc      As RECT
    Dim ST      As Long
    Dim sz      As SIZE
    
        hTheme = OpenThemeData(frm.hWnd, StrPtr("BUTTON"))
        
        If obj.Value = 1 Then
            ST = CBS_CHECKEDNORMAL
        Else
            ST = CBS_UNCHECKEDNORMAL
        End If
        
        GetThemePartSize hTheme, hDC, BP_CHECKBOX, ST, &H0, TS_DRAW, sz
        rc.Left = 2
        rc.Top = 2
        rc.Right = rc.Left + sz.cx '    rc.Right = 18
        rc.Bottom = rc.Top + sz.cy '    rc.Bottom = 18
    
        DrawThemeBackground hTheme, hDC, BP_CHECKBOX, ST, rc, 0
        CloseThemeData hTheme
        SetBkMode hDC, TRANSPARENT
        SetTextColor hDC, frm.ForeColor
    
        TextOut hDC, 20, 2, obj.Caption, Len(obj.Caption) '24
    End Sub
    This is the best I can get for the moment :

    Name:  test05.jpg
Views: 144
Size:  31.8 KB
    Last edited by Crapahute; May 4th, 2026 at 02:41 AM.

  27. #67

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Crapahute View Post
    I don't get it. I have changed my code to use GetThemePartSize to get the real size of the image but how can I use it to get the DarkMode-image ?
    With OpenThemeData you get ressources from the current used windows theme. Isnt your Windows Theme set to DarkMode?

  28. #68
    Lively Member
    Join Date
    Mar 2020
    Posts
    82

    Re: Windows 10 Dark Mode & VB6 apps

    Oh, I see. My Windows theme is not in darkmode that's why I don't get the right images.

  29. #69
    Lively Member
    Join Date
    Mar 2020
    Posts
    82

    Re: Windows 10 Dark Mode & VB6 apps

    Last edited by Crapahute; May 4th, 2026 at 11:21 AM.

  30. #70

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Crapahute View Post
    Oh, I see. My Windows theme is not in darkmode that's why I don't get the right images.
    There is a way to get the Windows DarkMode settings/images when using the normal Windows theme by using OpenThemeData with the DarkMode-classes like "DarkMode_CFD" or "DarkMode_Explorer".
    I personally never tried that. I guess you will find more infos about this when searching for "OpenThemeData+DarkMode_Explorer".

  31. #71
    Lively Member
    Join Date
    Mar 2020
    Posts
    82

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Mith View Post
    There is a way to get the Windows DarkMode settings/images when using the normal Windows theme by using OpenThemeData with the DarkMode-classes like "DarkMode_CFD" or "DarkMode_Explorer".
    I personally never tried that. I guess you will find more infos about this when searching for "OpenThemeData+DarkMode_Explorer".
    Thank you, it works great.

    Name:  test06.jpg
Views: 128
Size:  40.5 KB

    Here is what I have changed in my code :

    Code:
    Public Sub OwnerDrawCheckBoxW(frm As Form, obj As Object, ByVal hDC As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)
    Dim hTheme  As Long
    Dim rc      As RECT
    Dim ST      As Long
    Dim sz      As SIZE
     
     Dim rcGlyph As RECT
     Dim rcText  As RECT
     Dim rcFull  As RECT
        
        initOwnerDraws frm ' move obj for alignment
        
        hTheme = OpenThemeData(frm.hWnd, StrPtr("DarkMode_Explorer::Button")) 'BUTTON
        
        If obj.Value = vbChecked Then
            ST = CBS_CHECKEDNORMAL
        Else
            ST = CBS_UNCHECKEDNORMAL
        End If
        
        'Check box size
        GetThemePartSize hTheme, hDC, BP_CHECKBOX, ST, rcGlyph, TS_DRAW, sz
        rcGlyph.Left = Left + 2
        rcGlyph.Top = Top + ((Bottom - Top - sz.cy) \ 2)
        rcGlyph.Right = rcGlyph.Left + sz.cx: If rcGlyph.Right < 15 Then rcGlyph.Right = 15
        rcGlyph.Bottom = rcGlyph.Top + sz.cy: If rcGlyph.Bottom < 15 Then rcGlyph.Bottom = 15
        
        rc.Left = 2
        rc.Top = 2
        rc.Right = rc.Left + sz.cx: If rc.Right < 15 Then rc.Right = 15 '    rc.Right = 18
        rc.Bottom = rc.Top + sz.cy: If rc.Bottom < 15 Then rc.Bottom = 15 '    rc.Bottom = 18
        
        'Draw Check Box
        DrawThemeBackground hTheme, hDC, BP_CHECKBOX, ST, rc, 0
        
        ' Text zone
        GetThemeBackgroundContentRect hTheme, hDC, BP_CHECKBOX, ST, rcFull, rcText
        rcText.Left = rcGlyph.Right + 4
        rcText.Top = Top
        rcText.Right = Right - 4
        rcText.Bottom = Bottom
        
        SetBkMode hDC, TRANSPARENT
        SetTextColor hDC, frm.ForeColor
    
        DrawText hDC, obj.Caption, -1, rcText, _
                 DT_LEFT Or DT_WORDBREAK 'DT_LEFT Or DT_VCENTER Or DT_SINGLELINE Or DT_END_ELLIPSIS
        CloseThemeData hTheme
    End Sub
    
    Public Sub OwnerDrawOptionButtonW(frm As Form, obj As Object, ByVal hDC As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)
    Dim hTheme  As Long
    Dim rc      As RECT
    Dim ST      As Long
    Dim sz      As SIZE
    
     Dim rcGlyph As RECT
     Dim rcText  As RECT
     Dim rcFull  As RECT
    
        initOwnerDraws frm ' move obj for alignment
    
        hTheme = OpenThemeData(frm.hWnd, StrPtr("DarkMode_Explorer::Button")) 'BUTTON
    
        If obj.Value = True Then
            ST = RBS_CHECKEDNORMAL
        Else
            ST = RBS_UNCHECKEDNORMAL
        End If
        
        'Radio button size
        GetThemePartSize hTheme, hDC, BP_RADIOBUTTON, ST, rcGlyph, TS_DRAW, sz
        rcGlyph.Left = Left + 2
        rcGlyph.Top = Top + ((Bottom - Top - sz.cy) \ 2)
        rcGlyph.Right = rcGlyph.Left + sz.cx: If rcGlyph.Right < 15 Then rcGlyph.Right = 15
        rcGlyph.Bottom = rcGlyph.Top + sz.cy: If rcGlyph.Bottom < 15 Then rcGlyph.Bottom = 15
    
        rc.Left = 2
        rc.Top = 2
        rc.Right = rc.Left + sz.cx: If rc.Right < 15 Then rc.Right = 15
        rc.Bottom = rc.Top + sz.cy: If rc.Bottom < 15 Then rc.Bottom = 15
    
        'Draw radio button
        DrawThemeBackground hTheme, hDC, BP_RADIOBUTTON, ST, rc, 0
        
        ' Text zone
        GetThemeBackgroundContentRect hTheme, hDC, BP_CHECKBOX, ST, rcFull, rcText
        rcText.Left = rcGlyph.Right + 4
        rcText.Top = Top
        rcText.Right = Right - 4
        rcText.Bottom = Bottom
        
        SetBkMode hDC, TRANSPARENT
        SetTextColor hDC, frm.ForeColor
    
        DrawText hDC, obj.Caption, -1, rcText, _
                 DT_LEFT Or DT_WORDBREAK 'DT_LEFT Or DT_VCENTER Or DT_SINGLELINE Or DT_END_ELLIPSIS
    
        CloseThemeData hTheme
    End Sub
    Last edited by Crapahute; May 4th, 2026 at 11:16 AM.

  32. #72

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Crapahute View Post
    hTheme = OpenThemeData(frm.hWnd, StrPtr("DarkMode_Explorer::Button"))
    I tried that with Win10 (my dev OS) and the controls are looking the same.
    But when testing it with Win11 the look is different (DarkMode) and i use the standard Windows theme for both OS.
    I guess you develop and work with Win11 only?

  33. #73
    Lively Member
    Join Date
    Mar 2020
    Posts
    82

    Re: Windows 10 Dark Mode & VB6 apps

    Yes, tested under Windows 11 with VBCCR v1.08.0092.

  34. #74

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Crapahute View Post
    Yes, tested under Windows 11 with VBCCR v1.08.0092.
    Its ok if you develop for win11-only but if you support win7 until win11 you will see that every OS-version reacts different! vmware is your friend

  35. #75
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: Windows 10 Dark Mode & VB6 apps

    What about the idea to hook DrawThemeText ?

  36. #76

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Krool View Post
    What about the idea to hook DrawThemeText ?
    to change the black font color of the checkbox & optionbutton control?
    I never tried that. i guess it's less overhead than owner-draw the complete control.
    Do you have to hook every form and check for DrawThemeText & checkbox/optionbutton?

  37. #77
    PowerPoster
    Join Date
    Jun 2012
    Posts
    2,728

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Mith View Post
    to change the black font color of the checkbox & optionbutton control?
    I never tried that. i guess it's less overhead than owner-draw the complete control.
    Do you have to hook every form and check for DrawThemeText & checkbox/optionbutton?
    I would hook it on CDDS_PREPAINT and release the hook on CDDS_POSTPAINT. It's a process wide hook so all controls using DrawThemeText are effected. But since the GUI is single threaded always it would be safe to hook for the time of the actual drawing for a particular control.
    Of course it would be better to have this in-built into VBCCR and just turn a new "ForceForeColor" property to true (?) For CommandButtonW, CheckBoxW and OptionButtonW.
    Last edited by Krool; May 5th, 2026 at 04:23 AM.

  38. #78

    Thread Starter
    Fanatic Member Mith's Avatar
    Join Date
    Jul 2017
    Location
    Thailand
    Posts
    540

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Krool View Post
    Of course it would be better to have this in-built into VBCCR and just turn a new "ForceForeColor" property to true (?) For CommandButtonW, CheckBoxW and OptionButtonW.
    sounds like a good idea to fix this DarkMode problem

  39. #79
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: Windows 10 Dark Mode & VB6 apps

    Quote Originally Posted by Krool View Post
    What about the idea to hook DrawThemeText ?
    This works like a charm and no custom drawing of anything. Unfortunately hooking APIs is the only sane way to impl dark-mode for Win32 apps on Windows which a sad state of affairs. It’s completely under-baked at present and there are themes like Aero Lite which support it at 15% or less.

  40. #80
    Lively Member
    Join Date
    Mar 2020
    Posts
    82

    Re: Windows 10 Dark Mode & VB6 apps

    Until better solutions are available, here is my test program.

    TestDarkMode.zip

Page 2 of 3 FirstFirst 123 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width