Change colours of window

Just starting out? Need help? Post your questions and find answers here.
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Change colours of window

Post 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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Change colours of window

Post 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
Egypt my love
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Change colours of window

Post by coco2 »

Looks good except can you change the toolbar colour?

Also can it be done on Linux and Mac?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: Change colours of window

Post 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
Egypt my love
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Change colours of window

Post 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
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Change colours of window

Post by coco2 »

For some reason PureBasic also cannot set the background colour of buttons
User avatar
Caronte3D
Addict
Addict
Posts: 1371
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Change colours of window

Post by Caronte3D »

coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Change colours of window

Post by coco2 »

RASHAD - looks like Linux and Mac do it automatically

Caronte3D - thank you that might do it
Post Reply