EditorGadget scrollbars darkmode issue

Just starting out? Need help? Post your questions and find answers here.
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

EditorGadget scrollbars darkmode issue

Post 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 
Fred
Administrator
Administrator
Posts: 18150
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: EditorGadget scrollbars darkmode issue

Post by Fred »

So there is a native dark mode in Windows 11 for Win32 controls ?
wombats
Enthusiast
Enthusiast
Posts: 716
Joined: Thu Dec 29, 2011 5:03 pm

Re: EditorGadget scrollbars darkmode issue

Post 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 
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

Re: EditorGadget scrollbars darkmode issue

Post 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.
Fred
Administrator
Administrator
Posts: 18150
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: EditorGadget scrollbars darkmode issue

Post by Fred »

Did you check this ? It has a special section for scrollbar: https://gist.github.com/rounk-ctrl/b04e ... d5c22b7017
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4941
Joined: Sun Apr 12, 2009 6:27 am

Re: EditorGadget scrollbars darkmode issue

Post 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 

Egypt my love
Post Reply