360不是有个眼睛卫士能把窗口设置成视力保护色的功能,我感觉挺好的,另外我增加了桌面背景色设置选项,反正我们搞开发的要那么多花哨的背景干嘛,我一般都喜欢纯色背景
首先我们先定义几个辅助函数
//选择颜色控件
BOOL ChooseColorDlg(
HWND hWnd,
COLORREF &rgbResult,
COLORREF *prgbCustom
)
{
CHOOSECOLOR clr = {0};
clr.lStructSize = sizeof(CHOOSECOLOR);
clr.hwndOwner = hWnd;
clr.hInstance = 0;
clr.rgbResult = rgbResult;
clr.lpCustColors = prgbCustom;
clr.Flags = CC_RGBINIT | CC_ANYCOLOR | CC_FULLOPEN;
if(!ChooseColor(&clr))
return FALSE;
rgbResult = clr.rgbResult;
return TRUE;
}
//获取当前墙纸
BOOL GetWallPaper(
LPWSTR lpszWallPaper,
LPDWORD lpdwStyle
)
{
HRESULT hr;
WALLPAPEROPT wallPaperOpt;
IActiveDesktop *pActiveDesktop;
WCHAR szPathFile[MAX_PATH];
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);
if(hr != S_OK)
return FALSE;
if(lpdwStyle)
{
wallPaperOpt.dwSize = sizeof(WALLPAPEROPT);
wallPaperOpt.dwStyle = 0;
hr = pActiveDesktop->GetWallpaperOptions(&wallPaperOpt, 0);
if(hr != S_OK)
{
pActiveDesktop->Release();
return FALSE;
}
*lpdwStyle = wallPaperOpt.dwStyle;
}
if(lpszWallPaper)
{
hr = pActiveDesktop->GetWallpaper(szPathFile, MAX_PATH, AD_GETWP_LAST_APPLIED);
if(hr != S_OK)
{
pActiveDesktop->Release();
return FALSE;
}
lstrcpyW(lpszWallPaper, szPathFile);
}
pActiveDesktop->Release();
return TRUE;
}
//设置墙纸
BOOL SetWallPaper(
LPCWSTR lpszWallPaper,
LPDWORD lpdwStyle
)
{
HRESULT hr;
WALLPAPEROPT wallPaperOpt;
IActiveDesktop *pActiveDesktop;
hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
IID_IActiveDesktop, (void**)&pActiveDesktop);
if(hr != S_OK)
return FALSE;
if(lpdwStyle)
{
wallPaperOpt.dwSize = sizeof(WALLPAPEROPT);
wallPaperOpt.dwStyle = *lpdwStyle;
hr = pActiveDesktop->SetWallpaperOptions(&wallPaperOpt, 0);
if(hr != S_OK)
{
pActiveDesktop->Release();
return FALSE;
}
}
if(lpszWallPaper)
{
pActiveDesktop->SetWallpaper(lpszWallPaper, 0);
if(hr != S_OK)
{
pActiveDesktop->Release();
return FALSE;
}
}
pActiveDesktop->ApplyChanges(AD_APPLY_ALL);
pActiveDesktop->Release();
return TRUE;
}
//获取注册表值
DWORD ReadRegValue(
HKEY hkey, LPTSTR lpSubKey,
LPTSTR lpValueName,
LPBYTE lpValue,
DWORD &cbValue
)
{
HKEY hResult;
DWORD dwType;
//打开键
if(RegOpenKeyEx(hkey, lpSubKey, 0, KEY_READ, &hResult) != ERROR_SUCCESS)
return -1;
//读取值
if(RegQueryValueEx(hResult, lpValueName, 0, &dwType, lpValue, &cbValue) != ERROR_SUCCESS)
{
RegCloseKey(hResult);
return -1;
}
//关闭键
RegCloseKey(hResult);
return dwType;
}
//设置注册值
BOOL SetRegValue(
HKEY hkey,
LPTSTR lpSubKey,
LPTSTR lpValueName,
LPBYTE lpValue,
DWORD cbValue,
DWORD dwType
)
{
HKEY hResult;
//打开键
if( RegOpenKeyEx(hkey, lpSubKey, 0, KEY_WRITE, &hResult) != ERROR_SUCCESS )
return FALSE;
//设置注册表值
if( RegSetValueEx(hResult, lpValueName, 0, dwType, lpValue, cbValue) != ERROR_SUCCESS )
{
RegCloseKey(hResult);
return FALSE;
}
//关闭键
RegCloseKey(hResult);
return TRUE;
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课