前言
看到Demo中,在内存中做了一个位图文件, 按照参数写上文字内容,保存成bmp, 设置该bmp为桌面背景. 设置桌面背景只用一个API : SystemParametersInfo.
如果是一个后台程序,要显示一些提示性的信息,用墙纸和用户交互也是一个有趣的选择.
试验
// hw.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main(int argc, char* argv[])
{
char szBuf[MAXBYTE] = {'\0'};
for (int i = 0; i < 5; i++) {
// 换桌面背景, 只支持bmp格式
SystemParametersInfoA(
SPI_SETDESKWALLPAPER,
0,
"D:\\pic\\1.bmp",
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
Sleep(3000); // 3秒换一张背景图片
// 取消墙纸
SystemParametersInfoA(
SPI_SETDESKWALLPAPER,
0,
szBuf,
SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
Sleep(3000); // 3秒换一张背景图片
}
return 0;
}