DropDownList have a problem on windows 11

Report problems with documented functionality
contra3
Posts: 3
Joined: 19 Jun 2020, 22:49

DropDownList have a problem on windows 11

Post by contra3 » 27 Nov 2021, 04:06

hi.
I've tested my script on windows 11 and then a problem happened.
if you use DropDownList control and gui color command with "Black" of window color parameter, the Control's background color is very very dark and I can't read that contents.
In windows 10, This is not the case.
thanks

a sample code:

Code: Select all

#Singleinstance force
Gui, Color, Black
Gui, Add, DropDownList, w50 h100, 1|2|3|4|5
Gui, Show
Return

esc::
ExitApp

lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: DropDownList have a problem on windows 11

Post by lexikos » 20 Apr 2022, 07:12

Change the background to a bright colour, and you will see that the control acts like it is transparent. I suppose that's a new "feature" Microsoft have added. It certainly isn't an AutoHotkey bug.

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: DropDownList have a problem on windows 11

Post by jNizM » 20 Apr 2022, 08:19

I have already noticed that. ComboBox even works only half. At startup it has the gui background color and after the first popup it is white again, till you click in another control. Buttons in turn are default white and gray in hover.


OT @lexikos: Is WinUI on the later roadmap of AutoHotkey v2? Or even possible to integrate at all or are we stuck with Win32 Gui?
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: DropDownList have a problem on windows 11

Post by lexikos » 06 May 2022, 22:18

OT @jNizM
Yes. Native support for WinRT (and therefore WinUI) is a long term goal. For the shorter term and as part of studying the feasibility of WinRT support, I have already done significant work on a script that brings a very high level of support for WinRT, and have successfully utilized XAML to create a basic GUI. I wrote about it here. I am not working on it at the moment, but bringing it to a level of completion suitable for public use is the next project in my queue.

lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: DropDownList have a problem on windows 11

Post by lexikos » 07 May 2022, 02:18

After investigation, I still consider this a Windows 11 bug, or a break in compatibility, which amounts to the same thing. I didn't find other occurrences of this exact issue, but I found a couple of other ComboBox rendering issues caused by Windows 11 (also seemingly related to painting - or not painting - the background):
ComboBox ghost after Windows 11 upgrade - Microsoft Tech Community
ComboBoxGadgets do not render correctly on Windows 11 when a window background color is set - PureBasic Forums - English

The transparency effect is achieved by a WM_ERASEBKGND message being sent to the parent window to erase the region occupied by the control before it repaints its content. WM_ERASEBKGND is also the means by which the window's background is customized. On all previous versions of Windows, the ComboBox paints its own background and ignores the window's background.

The following workaround can be used to prevent the black background from showing behind the control, instead painting it some other colour:

Code: Select all

#Requires AutoHotkey v1.1

OnMessage(0x14, "Erase")
Erase(hdc, lParam, nmsg, hgui) {
    if !A_Gui
        return
    Loop {
        GuiControlGet hctrl, Hwnd, ComboBox%A_Index%
        if !hctrl
            break
        if !DllCall("uxtheme\GetWindowTheme", "ptr", hctrl)
            continue  ; Skip controls with -Theme.
        VarSetCapacity(rect, 16, 0)
        ; Get control rectangle in client coordinates.
        DllCall("GetWindowRect", "ptr", hctrl, "ptr", &rect)
        DllCall("MapWindowPoints", "ptr", 0, "ptr", hgui, "ptr", &rect, "int", 2)
        ; Shrink inward by 1 pixel to avoid white dots in corners.
        DllCall("InflateRect", "ptr", &rect, "int", -1, "int", -1)
        if !DllCall("RectVisible", "ptr", hdc, "ptr", &rect)
            continue  ; Control is not inside clipping region.
        ; Fill control background with COLOR_WINDOW (seems to match the Edit).
        static hbrush := DllCall("GetSysColorBrush", "int", 5, "ptr")
        DllCall("FillRect", "ptr", hdc, "ptr", &rect, "ptr", hbrush)
        ; Exclude the control from default handling of WM_ERASEBKGND.
        DllCall("ExcludeClipRect", "ptr", hdc
            , "int", NumGet(rect, 0, "int"), "int", NumGet(rect, 4, "int")
            , "int", NumGet(rect, 8, "int"), "int", NumGet(rect, 12, "int"))
    }
}
Gui, -MinimizeBox
Gui, Color, Black
Gui, Add, DropDownList, w100 h100, 1|2|3|4|5
Gui, Add, DropDownList, w100 h100 -Theme, 1|2|3|4|5
Gui, Add, ComboBox, w100 h100, 1|2|3|4|5
Gui, Show
Return

Esc::
GuiClose:
ExitApp

Code: Select all

#Requires AutoHotkey v2.0-

OnMessage(0x14, Erase)
Erase(hdc, lParam, nmsg, hgui) {
    if !g := GuiFromHwnd(hGui)
        return
    Loop {
        try hctrl := g['ComboBox' A_Index].hwnd
        catch
            break
        if !DllCall("uxtheme\GetWindowTheme", "ptr", hctrl)
            continue  ; Skip controls with -Theme.
        rect := Buffer(16, 0)
        ; Get control rectangle in client coordinates.
        DllCall("GetWindowRect", "ptr", hctrl, "ptr", rect)
        DllCall("MapWindowPoints", "ptr", 0, "ptr", hgui, "ptr", rect, "int", 2)
        ; Shrink inward by 1 pixel to avoid white dots in corners.
        DllCall("InflateRect", "ptr", rect, "int", -1, "int", -1)
        if !DllCall("RectVisible", "ptr", hdc, "ptr", rect)
            continue  ; Control is not inside clipping region.
        ; Fill control background with COLOR_WINDOW (seems to match the Edit).
        static hbrush := DllCall("GetSysColorBrush", "int", 5, "ptr")
        DllCall("FillRect", "ptr", hdc, "ptr", rect, "ptr", hbrush)
        ; Exclude the control from default handling of WM_ERASEBKGND.
        DllCall("ExcludeClipRect", "ptr", hdc
            , "int", NumGet(rect, 0, "int"), "int", NumGet(rect, 4, "int")
            , "int", NumGet(rect, 8, "int"), "int", NumGet(rect, 12, "int"))
    }
}
g := Gui('-MinimizeBox')
g.BackColor := "Black"
g.AddDDL('w100 h100', [1,2,3,4,5])
g.AddDDL('w100 h100 -Theme', [1,2,3,4,5])
g.AddComboBox('w100 h100', [1,2,3,4,5])
g.OnEvent('Escape', g => g.Destroy())
g.Show()
I am not inclined to do this by default due to complexity, and doubts about how it will affect any other version of Windows, including future versions. It may also be undesirable on Windows 11 in scripts which use a non-default light background.

Post Reply

Return to “Bug Reports”