以下代码为功能定义:// 将本程序设置为屏保
//const uint SPI_SETSCREENSAVERRUNNING = 0x0061;
// 屏保状态
const uint SPI_SETSCREENSAVEACTIVE = 0x0011;
// 获取屏幕壁纸地址
const uint SPI_GETDESKWALLPAPER = 0x0073; [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SystemParametersInfo(uint uAction, uint uParam, StringBuilder lpvParam, uint init);
//static extern bool SystemParametersInfo(uint uAction, uint uParam, uint lpvParam, uint init);
/*
* 设置壁纸
* private const int SPI_SETDESKWALLPAPER = 20
* SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, filename, 1);
*/以下两行代码分别为设置或取消屏保:
public static void SetScreener()
{
bool ok;
StringBuilder str = new StringBuilder(100);
ok = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 1, str, 0);
} public static void CancelScreener()
{
bool ok;
StringBuilder str = new StringBuilder(100);
ok = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, 0, str, 0);
}但是还有一点,当返回值为 true 时,win,ctrl+del+alt,alt+tab,ctrl+esc 等功能键都还能用,实际上,如果设置成屏保,这些键应该是不能用的才对。
const uint SPI_SETSCREENSAVEACTIVE = 0x0011;为
readonly uint SPI_SETSCREENSAVEACTIVE = 0x0011;的时候,vs2005的自动提示里为什么没有 设置为 readonly 时的 SPI_SETSCREENSAVEACTIVE 的值?