Page 1 of 1

Change colours of window

Posted: Sat May 25, 2024 6:45 am
by coco2
How do you change all the colours of a window? Make a dark mode app? Change the toolbar colour? I can't find any options.

Re: Change colours of window

Posted: Sat May 25, 2024 8:13 am
by RASHAD
For Windows 10,11

Code: Select all

UsePNGImageDecoder()
thBrush = CreateSolidBrush_($0)

Enumeration DWMWINDOWATTRIBUTE
  #DWMWA_USE_IMMERSIVE_DARK_MODE = 20
EndEnumeration

PrototypeC.i DwmSetWindowAttribute(hwnd.i, dwAttribute.l, *pvAttribute, cbAttribute.l)

Define.DwmSetWindowAttribute DwmSetWindowAttribute  
Define.i UseDarkMode

OpenWindow(0, 50, 50, 600, 400, "DarkMode Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered |#PB_Window_SizeGadget)

UseDarkMode = 1

If OpenLibrary(0, "dwmapi")  
  DwmSetWindowAttribute = GetFunction(0, "DwmSetWindowAttribute")  
  DwmSetWindowAttribute(WindowID(0), #DWMWA_USE_IMMERSIVE_DARK_MODE, @UseDarkMode, SizeOf(UseDarkMode))
  CloseLibrary(0)
EndIf

SetWindowColor(0,0)

ContainerGadget(1,0, -2,600,24,#PB_Container_BorderLess) 
CloseGadgetList() 
TB = CreateToolBar(0, GadgetID(1))
LoadImage(0,#PB_Compiler_Home+"Examples\Sources\Data\world.png")
ToolBarImageButton(0,ImageID(0))

 SetClassLongPtr_(GadgetID(1), #GCL_HBRBACKGROUND, thBrush)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend

Re: Change colours of window

Posted: Sat May 25, 2024 8:18 am
by coco2
Looks good except can you change the toolbar colour?

Also can it be done on Linux and Mac?

Re: Change colours of window

Posted: Sat May 25, 2024 8:21 am
by RASHAD
For ToolBar Color

Code: Select all

 thBrush = CreateSolidBrush_($0) ;Change $0 to what you want
For Linux & Mac
Ask mk-soft or Shardik :D

Re: Change colours of window

Posted: Sat May 25, 2024 9:01 am
by coco2
Can you do the menus? :D

Code: Select all

UsePNGImageDecoder()
thBrush = CreateSolidBrush_($00303030)

Enumeration DWMWINDOWATTRIBUTE
  #DWMWA_USE_IMMERSIVE_DARK_MODE = 20
EndEnumeration

PrototypeC.i DwmSetWindowAttribute(hwnd.i, dwAttribute.l, *pvAttribute, cbAttribute.l)

Define.DwmSetWindowAttribute DwmSetWindowAttribute  
Define.i UseDarkMode

OpenWindow(0, 50, 50, 600, 400, "DarkMode Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered |#PB_Window_SizeGadget)

UseDarkMode = 1

If OpenLibrary(0, "dwmapi")  
  DwmSetWindowAttribute = GetFunction(0, "DwmSetWindowAttribute")  
  DwmSetWindowAttribute(WindowID(0), #DWMWA_USE_IMMERSIVE_DARK_MODE, @UseDarkMode, SizeOf(UseDarkMode))
  CloseLibrary(0)
EndIf

CreateMenu(0, WindowID(0))
MenuTitle("File")
MenuItem(MenuID(0), "Open...")
MenuItem(MenuID(0), "Save As...")
MenuItem(MenuID(0), "Save")
MenuItem(MenuID(0), "Quit")

SetWindowColor(0, $202020)

ContainerGadget(1, 0, -2, 600, 24, #PB_Container_BorderLess) 
CloseGadgetList() 
TB = CreateToolBar(0, GadgetID(1))
LoadImage(0,#PB_Compiler_Home+"Examples\Sources\Data\world.png")
ToolBarImageButton(0,ImageID(0))

SetClassLongPtr_(GadgetID(1), #GCL_HBRBACKGROUND, thBrush)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend

Re: Change colours of window

Posted: Sat May 25, 2024 9:19 am
by coco2
For some reason PureBasic also cannot set the background colour of buttons

Re: Change colours of window

Posted: Sat May 25, 2024 10:43 am
by Caronte3D

Re: Change colours of window

Posted: Sat May 25, 2024 10:35 pm
by coco2
RASHAD - looks like Linux and Mac do it automatically

Caronte3D - thank you that might do it