Page 1 of 1

Why doesn't this work on 32 bit

Posted: Fri Jun 07, 2024 9:05 am
by coco2
Does anyone know why this doesn't work on 32 bit Windows? Not a bit issue, just curious is all and I would like to learn about programming Windows.

Code: Select all

PrototypeC.i DwmSetWindowAttribute(hwnd.i, dwAttribute.l, *pvAttribute, cbAttribute.l)
Global DwmSetWindowAttribute.DwmSetWindowAttribute
#DWMWA_USE_IMMERSIVE_DARK_MODE = 20  
Define darkMode.i = 1
Define window.i = 0
Debug @window
Debug @darkMode
Procedure ShowWindow(window.i, darkMode.i)
  OpenWindow(window, 100, 100, 400, 400, "Test", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
  Debug @window
  Debug @darkMode
  If OpenLibrary(0, "dwmapi")  
    DwmSetWindowAttribute = GetFunction(0, "DwmSetWindowAttribute")  
    DwmSetWindowAttribute(WindowID(window), #DWMWA_USE_IMMERSIVE_DARK_MODE, @darkMode, SizeOf(darkMode))
    CloseLibrary(0)
  EndIf
  Debug window
  SetWindowColor(window, $303030)
EndProcedure
ShowWindow(0, 1)
Repeat
  event = WaitWindowEvent(10)
Until event = #PB_Event_CloseWindow
EDIT: my mistake, I misinterpreted the original problem. I will need to get back to this with the actual problem as this code will run in 32 bit Windows

Re: Why doesn't this work on 32 bit

Posted: Fri Jun 07, 2024 10:18 am
by coco2
I have edited the code now, it runs on 64 bit Windows but not 32 bit. I suspect that the DwmSetWindowAttribute is not being used correctly and is overwriting the memory for the window argument.

Re: Why doesn't this work on 32 bit

Posted: Fri Jun 07, 2024 10:54 am
by spikey
#DWMWA_USE_IMMERSIVE_DARK_MODE is only implemented from Windows 11 Build 22000. See DWMWINDOWATTRIBUTE enumeration. There's no 32-bit version of this, so I guess you're referring to an earlier Windows version and this is unimplemented. You're not checking the result of the call but it's probably returning an error code.

Re: Why doesn't this work on 32 bit

Posted: Fri Jun 07, 2024 11:21 am
by coco2
Ah right so I need to restrict this to Windows 11?

Any idea how to use dark mode in Windows 10?

Also any idea how to detect whether dark mode in Windows 10 is turned on? And Windows 11?

Re: Why doesn't this work on 32 bit

Posted: Fri Jun 07, 2024 1:50 pm
by spikey
coco2 wrote: Fri Jun 07, 2024 11:21 am Ah right so I need to restrict this to Windows 11?
Yes.
coco2 wrote: Fri Jun 07, 2024 11:21 am Any idea how to use dark mode in Windows 10?
If I've understood correctly, there isn't really a dark mode in Windows 10, it's a composite effect of using the desktop window manager and user elective theme files rather than some feature which gets switched on or off binarily. It's up to applications to work out what the specific implications of a particular theme should be for themselves.

I didn't read everything available by any means. Just enough to decide that I had other priorities! You can read up on the DWM at https://learn.microsoft.com/en-us/windo ... m-overview.
coco2 wrote: Fri Jun 07, 2024 11:21 am Also any idea how to detect whether dark mode in Windows 10 is turned on?
According to https://stackoverflow.com/questions/622 ... pplication, there are two registry settings to check:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\AppsUseLightTheme
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\SystemUsesLightTheme

Note the different spellings of 'Use' in the two keys, they aren't the same (but are grammatically correct). The values should be 1 or 0,
but according to other sources the 'AppsUseLightTheme' key can be missing entirely so you will need to handle that too.
coco2 wrote: Fri Jun 07, 2024 11:21 am And Windows 11?
In W11 there is DwmGetWindowAttribute and there is a message too WM_DWMColorizationColorChanged.

Re: Why doesn't this work on 32 bit

Posted: Tue Jun 11, 2024 6:26 am
by coco2
Thanks, I might make another post just to check for cross platform detection of dark mode. I have searched the forum and haven't found anything like it.