Disable Windows Visual Effects through SystemParametersInfo

戏子无情 提交于 2019-12-24 22:25:13

问题


I am trying to disable all visual effects programmatically in a Windows Forms App. Other than an extense list of registry values to be changed, i found this option, but I cant seem to get it to work.

Searched in pinvoke.net and on MSDN for a more specific answer, but I could not find one.

So, heres the data I have:

Info about SPI_SETUIEFFECTS

SPI_SETUIEFFECTS 0x103F

Enables or disables UI effects. Set the pvParam parameter to TRUE to enable all UI effects or FALSE to disable all UI effects.

I need to pass it a bool as the pvParam, which seems to be an exception to the general rule... ok, then I try declaring it as:

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SystemParametersInfo(uint uiAction, uint uiParam, bool pvParam, uint fWinIni);

now, to call it:

const uint SPI_SETUIEFFECTS = 0x103F;
const uint SPIF_SENDCHANGE = 0x02;

bool result = SystemParametersInfo(SPI_SETUIEFFECTS, 0, false, SPIF_SENDCHANGE);

And it builds, runs... and does nothing. No error, no change. "result" is set to true.

What am I missing here?


回答1:


This code

[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SystemParametersInfo(
    uint uiAction, 
    uint uiParam, 
    bool pvParam, 
    uint fWinIni
);
....
bool enabled = false;
SystemParametersInfo(SPI_SETUIEFFECTS, 0, enabled, 0);

works perfectly. I tested by looking at the drop-down effect of a combo box. When enabled is false then the combo's list appears instantly. When enabled is true then the combo's list slides down.

Most likely you are looking at a control which is not painted by the system and that control is ignoring this option.



来源:https://stackoverflow.com/questions/16564925/disable-windows-visual-effects-through-systemparametersinfo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!