Page 1 of 1

EditorGadget scrollbars darkmode issue

Posted: Thu Apr 10, 2025 9:56 am
by firace
I have this color issue within editorgadget scrollbars when using dark mode (Windows 11):
Any ideas to make the white part dark?

Code: Select all


OpenWindow(0, 30, 30, 500, 400, "Demo1", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
SetWindowColor(0, 0)

EditorGadget(1, 120, 60, 300, 100)

SetGadgetText(1, "Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow" + #CRLF$ + #CRLF$ +#CRLF$ +#CRLF$ +#CRLF$ )

SetGadgetColor(1, #PB_Gadget_BackColor,  $323232)
SetGadgetColor(1, #PB_Gadget_FrontColor, $F2F2F2)

SetWindowTheme_(GadgetID(1), "DarkMode_Explorer", 0)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 

Re: EditorGadget scrollbars darkmode issue

Posted: Thu Apr 10, 2025 12:08 pm
by Fred
So there is a native dark mode in Windows 11 for Win32 controls ?

Re: EditorGadget scrollbars darkmode issue

Posted: Thu Apr 10, 2025 1:18 pm
by wombats
You can put it inside a ContainerGadget. It's not perfect - the colour is still lighter than the scrollbars, but it's not white, at least. SetGadgetColor() only seems to affect the left and top edges of that space for some reason.

Code: Select all

OpenWindow(0, 30, 30, 500, 400, "Demo1", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
SetWindowColor(0, 0)

ContainerGadget(0, 120, 60, 300, 100)
EditorGadget(1, 0, 0, 300, 100)
CloseGadgetList()

SetGadgetText(1, "Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow" + #CRLF$ + #CRLF$ +#CRLF$ +#CRLF$ +#CRLF$ )

SetGadgetColor(0, #PB_Gadget_BackColor, RGB(0, 0, 0))
SetGadgetColor(1, #PB_Gadget_BackColor,  $323232)
SetGadgetColor(1, #PB_Gadget_FrontColor, $F2F2F2)

SetWindowTheme_(GadgetID(1), "DarkMode_Explorer", 0)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
Here's a way using a callback. I'm not sure if I've done it all right - somebody more knowledgable with the Windows API might know, but it seems to work.

Code: Select all

EnableExplicit

Global proc

Procedure EditorCallback(hWnd, uMsg, wParam, lParam) 
  Select uMsg
    Case #WM_PAINT
      Define rc.Rect, hDC, hBrush, scrollX, scrollY
      CallWindowProc_(proc, hWnd, uMsg, wParam, lParam) 
      hDC = GetDC_(hWnd)
      GetClientRect_(hWnd, @rc)
      scrollX = GetSystemMetrics_(#SM_CXHSCROLL)
      scrollY = GetSystemMetrics_(#SM_CXVSCROLL)
      rc\left = rc\right
      rc\top = rc\bottom
      rc\right + scrollX
      rc\bottom + scrollY
      hBrush = CreateSolidBrush_(RGB(0, 0, 0))
      FillRect_(hDC, rc, hBrush)
      SetBkMode_(hDC, #TRANSPARENT)
      DeleteObject_(hBrush)
      ReleaseDC_(hWnd, hDC)
      ProcedureReturn 0 
  EndSelect 
  ProcedureReturn CallWindowProc_(proc, hWnd, uMsg, wParam, lParam) 
EndProcedure

OpenWindow(0, 30, 30, 500, 400, "Demo1", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
SetWindowColor(0, 0)

EditorGadget(1, 120, 60, 300, 100)

SetGadgetText(1, "Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow" + #CRLF$ + #CRLF$ +#CRLF$ +#CRLF$ +#CRLF$ )

SetGadgetColor(1, #PB_Gadget_BackColor,  $323232)
SetGadgetColor(1, #PB_Gadget_FrontColor, $F2F2F2)

SetWindowTheme_(GadgetID(1), "DarkMode_Explorer", 0)

proc = SetWindowLong_(GadgetID(1), #GWL_WNDPROC, @EditorCallback()) 

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 

Re: EditorGadget scrollbars darkmode issue

Posted: Thu Apr 10, 2025 4:02 pm
by firace
Fred: It's an undocumented API call (I think) and it's not really an easy to use solution :)

wombats: Both approaches are interesting, thanks for sharing.

Re: EditorGadget scrollbars darkmode issue

Posted: Thu Apr 10, 2025 4:14 pm
by Fred
Did you check this ? It has a special section for scrollbar: https://gist.github.com/rounk-ctrl/b04e ... d5c22b7017

Re: EditorGadget scrollbars darkmode issue

Posted: Thu Apr 10, 2025 5:29 pm
by RASHAD
Hi
Enhanced a little bit
For the white square use one of wombats splendid solution

Code: Select all

#DWMWA_USE_IMMERSIVE_DARK_MODE = 20
Prototype DwmSetWindowAttribute(hwnd.i, dwAttribute.i, *pvAttribute, cbAttribute.i)
Global DwmSetWindowAttribute.DwmSetWindowAttribute 

Procedure InitDwn()
  lib = OpenLibrary(#PB_Any, "dwmapi")  
  If lib
    DwmSetWindowAttribute = GetFunction(lib, "DwmSetWindowAttribute")
  EndIf
  ProcedureReturn lib
EndProcedure : InitDwn()

Procedure SetCaptionDarkMode(Window, State)
  If DwmSetWindowAttribute
    DwmSetWindowAttribute(WindowID(Window), #DWMWA_USE_IMMERSIVE_DARK_MODE, @State, SizeOf(State))
  EndIf
EndProcedure

OpenWindow(0, 30, 30, 500, 400, "Demo1", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget |#PB_Window_ScreenCentered)
If OSVersion() >= 10
  SetCaptionDarkMode(0, 1)
EndIf

SetWindowColor(0,0) 

EditorGadget(1, 120, 60, 300, 100)

SetGadgetText(1, "Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow" + #CRLF$ + #CRLF$ +#CRLF$ +#CRLF$ +#CRLF$ )

SetGadgetColor(1, #PB_Gadget_BackColor,  $323232)
SetGadgetColor(1, #PB_Gadget_FrontColor, $F2F2F2)

SetWindowTheme_(GadgetID(1), "DarkMode_Explorer", 0)

Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow