Set desktop background color

Just starting out? Need help? Post your questions and find answers here.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Set desktop background color

Post by Dude »

I'm trying to set the desktop background color to red (no wallpaper), using this code which fails:

Code: Select all

If SetSysColors_(1,#COLOR_BACKGROUND,RGB(255,0,0))=0
  Debug GetLastError_() ; Returns 998
EndIf
I can't find anything with Google to explain what error 998 means. :(

According to this VB article, the code above should work without problem:

http://allapi.mentalis.org/tips/tip8.shtml

Any suggestions? Thanks.
alter Mann
User
User
Posts: 39
Joined: Fri Oct 17, 2014 8:52 pm

Re: Set desktop background color

Post by alter Mann »

User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Re: Set desktop background color

Post by Fluid Byte »

It won't work like this, you need to use pointers

Code: Select all

Dim lpaElements(0)
Dim lpaRgbValues(0)

lpaElements(0) = #COLOR_BACKGROUND
lpaRgbValues(0) = RGB(255,0,255)

Debug SetSysColors_(1,@lpaElements(),@lpaRgbValues(0))
https://msdn.microsoft.com/de-de/library/windows/desktop/ms724940(v=vs.85).aspx
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Set desktop background color

Post by Dude »

@Fluid Byte: Thanks for the example and explanation. I was just copying the VB snippet that I posted as I assumed it would immediately work the same way.

@alter Mann: I did see that page but because it said 998 was "invalid access to memory location", I didn't understand how that would be relevant. However, from Fluid Byte's example I see now that I had to use a pointer and that was why.

Again, thanks so much to both of you! :)
Post Reply