2

I've created a program to automatically adjust the colour filter of the screen according to sunset and sunrise. I use the GetDeviceGammaRamp() and SetDeviceGammaRamp() methods taken from here to achieve this.

However, there is a problem. When the computer wakes up from sleep, or when a UAC message pops up (e.g: from opening an installation exe file), then on my laptop, the screen colour returns to normal. All well and good if it's temporary, but the way it does this though seems non-standard, as afterwards, GetDeviceGammaRamp() returns the same previous colour, not the shown new colour! Also if I use SetDeviceGammaRamp() to try and set the old colour back again, it refuses to set. However, if I use SetDeviceGammaRamp() to change the RGB colour even just SLIGHTLY (e.g: RGB = 80,80,81 instead of the old 80,80,80), then Windows will happily set the colour to that.

If only I had a fool-proof way of detecting when Windows changes the screen's colour like this. Or failing that, if only it would respond to changing the colour back to the old colour instead of thinking "but you're already at that RGB colour, so why would you want to set it again!", when clearly it's not.

Unfortunately unless I find a solution, I have to force the program to flash to a very slightly different colour every minute or so (which many people including myself) can notice. This is in case a UAC prompt or computer wake-up happens which changes the screen's colour.

By the way, the famous F.lux program hasn't solved the problem as their program has the issue too. Interestingly, my desktop keeps the same colour when a UAC prompt comes up - it's just my laptop which has the issue.

Community
  • 1
  • 1
Dan W
  • 3,520
  • 7
  • 42
  • 69

1 Answers1

3

If only I had a fool-proof way of detecting when Windows changes the screen's colour like this

Fairly important to understand what is really going on when Windows displays the UAC prompt. It looks like it displays the dialog on the user's desktop. That however is an illusion, it actually switches the view to the secure desktop. The same one that's used to display the logon prompt when you start up or the one it switches to when you lock the workstation (Win+L key) or press the Ctrl+Alt+Del keys.

The illusion that you see your user desktop is otherwise pretty simple to implement, it just displays a screenshot in the background. Also very easy to make it look darker that way.

The secure desktop is highly tamper-proof, for obvious reasons. For one, you cannot tell that it is active, that would make it far too easy for malware to start probing. For another, SetDeviceGammaRamp() is way too dangerous if it also affected the secure desktop. Malware could do something hokey like setting the ramp to all black and thus make it look like the user completely lost control with no way to make Ctrl+Alt+Del work anymore. So it just doesn't have any effect, you get the default ramp.

While you can't detect that the secure desktop is active, you can get a notification of the session switch. WTSRegisterSessionNotification() function. Not that this helps, the ramp you set still only applies to the user's desktop. To make it permanent, you have to convince the video driver to apply a color correction profile. Normally done by the Control Panel + Color Correction applet. Or the usual shovel-ware that comes along with the video driver. How it is done in your own program is hard to find out, it surely isn't very practical since it is going to require the UAC prompt :)

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thanks for the info. Thing is, once the UAC prompt has gone, the actual screen's colour filter looks back to default (255,255,255). Yet GetDeviceGammaRamp() thinks the screen is still at the old 150,150,150 (if that's what it was before the UAC prompt). So it's mistaken! Anyway, do you think `WTSRegisterSessionNotification()` may help considering I want to apply the colour change to the user's desktop (that sounds good!). – Dan W Mar 29 '15 at 13:27
  • 2
    If it doesn't switch back then you have much bigger problems. Better start with a video driver update first. – Hans Passant Mar 29 '15 at 13:43
  • Oh my Win7 laptop's an anamoly? I think you may be right! I tested on my Win7 desktop, as well as another Win7 laptop, and another Win8 laptop, and when waking up from sleep, or when the UAC prompt comes up, the screen doesn't change to the default white colour at any stage! This makes me think that my 'anamoly' Lenevo laptop added this 'feature'. The fact that it doesn't return to the previous colour may be a bug with all Lenevo laptops, or at least this model. – Dan W Mar 29 '15 at 14:33
  • It may not be the laptop itself. It could be the video driver, or some other piece of software that does color management. You'd have to play around to find out. – andlabs Mar 29 '15 at 15:56
  • Yes, I meant to say my "setup's" an anomaly (rather than my laptop). – Dan W Mar 29 '15 at 16:03