Page 1 of 1

Set desktop background color

Posted: Wed May 31, 2017 3:16 pm
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.

Re: Set desktop background color

Posted: Wed May 31, 2017 4:34 pm
by alter Mann

Re: Set desktop background color

Posted: Wed May 31, 2017 5:10 pm
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

Re: Set desktop background color

Posted: Thu Jun 01, 2017 1:53 am
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! :)