简体   繁体   中英

Screen colour defaulting to normal when UAC message pops up (undetectable)

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 (eg: 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 (eg: 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.

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM