3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS Display Control Panel
5 * FILE: lib/cpl/desk/background.c
6 * PURPOSE: Background property page
8 * PROGRAMMERS: Trevor McCort (lycan359@gmail.com)
9 * Alexey Minnekhanov (minlexx@rambler.ru)
14 #define MAX_BACKGROUNDS 100
16 #define PLACEMENT_CENTER 0
17 #define PLACEMENT_STRETCH 1
18 #define PLACEMENT_TILE 2
20 /* The values in these macros are dependant on the
21 * layout of the monitor image and they must be adjusted
22 * if that image will be changed.
24 #define MONITOR_LEFT 18
25 #define MONITOR_TOP 18
26 #define MONITOR_RIGHT 168
27 #define MONITOR_BOTTOM 128
29 #define MONITOR_WIDTH (MONITOR_RIGHT-MONITOR_LEFT)
30 #define MONITOR_HEIGHT (MONITOR_BOTTOM-MONITOR_TOP)
34 BOOL bWallpaper
; /* Is this background a wallpaper */
36 TCHAR szFilename
[MAX_PATH
];
37 TCHAR szDisplayName
[256];
43 BackgroundItem backgroundItems
[MAX_BACKGROUNDS
];
45 PDIBITMAP pWallpaperBitmap
;
47 int placementSelection
;
48 int backgroundSelection
;
50 COLORREF custom_colors
[16];
52 int listViewItemCount
;
59 GLOBAL_DATA g_GlobalData
;
62 /* Add the images in the C:\ReactOS directory and the current wallpaper if any */
64 AddListViewItems(HWND hwndDlg
, PDATA pData
)
68 TCHAR szSearchPath
[MAX_PATH
];
69 TCHAR szFileTypes
[MAX_PATH
];
76 TCHAR wallpaperFilename
[MAX_PATH
];
77 DWORD bufferSize
= sizeof(wallpaperFilename
);
78 TCHAR buffer
[MAX_PATH
];
79 DWORD varType
= REG_SZ
;
82 BackgroundItem
*backgroundItem
= NULL
;
83 TCHAR separators
[] = TEXT(";");
85 HWND hwndBackgroundList
;
88 hwndBackgroundList
= GetDlgItem(hwndDlg
, IDC_BACKGROUND_LIST
);
90 GetClientRect(hwndBackgroundList
, &clientRect
);
92 /* Add a new column to the list */
93 ZeroMemory(&dummy
, sizeof(LV_COLUMN
));
94 dummy
.mask
= LVCF_SUBITEM
| LVCF_WIDTH
;
96 dummy
.cx
= (clientRect
.right
- clientRect
.left
) - GetSystemMetrics(SM_CXVSCROLL
);
97 (void)ListView_InsertColumn(hwndBackgroundList
, 0, &dummy
);
99 /* Add the "None" item */
100 backgroundItem
= &pData
->backgroundItems
[pData
->listViewItemCount
];
101 backgroundItem
->bWallpaper
= FALSE
;
104 backgroundItem
->szDisplayName
,
105 sizeof(backgroundItem
->szDisplayName
) / sizeof(TCHAR
));
107 ZeroMemory(&listItem
, sizeof(LV_ITEM
));
108 listItem
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
110 listItem
.pszText
= backgroundItem
->szDisplayName
;
111 listItem
.iImage
= -1;
112 listItem
.iItem
= pData
->listViewItemCount
;
113 listItem
.lParam
= pData
->listViewItemCount
;
115 (void)ListView_InsertItem(hwndBackgroundList
, &listItem
);
116 ListView_SetItemState(hwndBackgroundList
,
117 pData
->listViewItemCount
,
121 pData
->listViewItemCount
++;
123 /* Add current wallpaper if any */
124 RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, KEY_ALL_ACCESS
, ®Key
);
126 result
= RegQueryValueEx(regKey
, TEXT("Wallpaper"), 0, &varType
, (LPBYTE
)wallpaperFilename
, &bufferSize
);
127 if ((result
== ERROR_SUCCESS
) && (_tcslen(wallpaperFilename
) > 0))
129 /* Allow environment variables in file name */
130 if (ExpandEnvironmentStrings(wallpaperFilename
, buffer
, MAX_PATH
))
132 _tcscpy(wallpaperFilename
, buffer
);
135 himl
= (HIMAGELIST
)SHGetFileInfo(wallpaperFilename
,
139 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
|
146 (void)ListView_SetImageList(hwndBackgroundList
, himl
, LVSIL_SMALL
);
149 backgroundItem
= &pData
->backgroundItems
[pData
->listViewItemCount
];
151 backgroundItem
->bWallpaper
= TRUE
;
153 _tcscpy(backgroundItem
->szDisplayName
, sfi
.szDisplayName
);
154 p
= _tcsrchr(backgroundItem
->szDisplayName
, _T('.'));
157 _tcscpy(backgroundItem
->szFilename
, wallpaperFilename
);
159 ZeroMemory(&listItem
, sizeof(LV_ITEM
));
160 listItem
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
162 listItem
.pszText
= backgroundItem
->szDisplayName
;
163 listItem
.iImage
= sfi
.iIcon
;
164 listItem
.iItem
= pData
->listViewItemCount
;
165 listItem
.lParam
= pData
->listViewItemCount
;
167 (void)ListView_InsertItem(hwndBackgroundList
, &listItem
);
168 ListView_SetItemState(hwndBackgroundList
,
169 pData
->listViewItemCount
,
173 pData
->listViewItemCount
++;
179 /* Add all the images in the C:\ReactOS directory. */
181 LoadString(hApplet
, IDS_SUPPORTED_EXT
, szFileTypes
, sizeof(szFileTypes
) / sizeof(TCHAR
));
183 token
= _tcstok(szFileTypes
, separators
);
184 while (token
!= NULL
)
186 GetWindowsDirectory(szSearchPath
, MAX_PATH
);
187 _tcscat(szSearchPath
, TEXT("\\"));
188 _tcscat(szSearchPath
, token
);
190 hFind
= FindFirstFile(szSearchPath
, &fd
);
191 while (hFind
!= INVALID_HANDLE_VALUE
)
193 TCHAR filename
[MAX_PATH
];
195 GetWindowsDirectory(filename
, MAX_PATH
);
197 _tcscat(filename
, TEXT("\\"));
198 _tcscat(filename
, fd
.cFileName
);
200 /* Don't add any hidden bitmaps. Also don't add current wallpaper once more. */
201 if (((fd
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
) == 0) && (_tcscmp(wallpaperFilename
, filename
) != 0))
203 himl
= (HIMAGELIST
)SHGetFileInfo(filename
,
207 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
|
215 (void)ListView_SetImageList(hwndBackgroundList
, himl
, LVSIL_SMALL
);
218 backgroundItem
= &pData
->backgroundItems
[pData
->listViewItemCount
];
220 backgroundItem
->bWallpaper
= TRUE
;
222 _tcscpy(backgroundItem
->szDisplayName
, sfi
.szDisplayName
);
223 p
= _tcsrchr(backgroundItem
->szDisplayName
, _T('.'));
226 _tcscpy(backgroundItem
->szFilename
, filename
);
228 ZeroMemory(&listItem
, sizeof(LV_ITEM
));
229 listItem
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
230 listItem
.pszText
= backgroundItem
->szDisplayName
;
232 listItem
.iImage
= sfi
.iIcon
;
233 listItem
.iItem
= pData
->listViewItemCount
;
234 listItem
.lParam
= pData
->listViewItemCount
;
236 (void)ListView_InsertItem(hwndBackgroundList
, &listItem
);
238 pData
->listViewItemCount
++;
241 if(!FindNextFile(hFind
, &fd
))
242 hFind
= INVALID_HANDLE_VALUE
;
245 token
= _tcstok(NULL
, separators
);
251 InitBackgroundDialog(HWND hwndDlg
, PDATA pData
)
256 DWORD bufferSize
= sizeof(szBuffer
);
257 DWORD varType
= REG_SZ
;
261 AddListViewItems(hwndDlg
, pData
);
263 LoadString(hApplet
, IDS_CENTER
, szString
, sizeof(szString
) / sizeof(TCHAR
));
264 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_INSERTSTRING
, PLACEMENT_CENTER
, (LPARAM
)szString
);
266 LoadString(hApplet
, IDS_STRETCH
, szString
, sizeof(szString
) / sizeof(TCHAR
));
267 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_INSERTSTRING
, PLACEMENT_STRETCH
, (LPARAM
)szString
);
269 LoadString(hApplet
, IDS_TILE
, szString
, sizeof(szString
) / sizeof(TCHAR
));
270 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_INSERTSTRING
, PLACEMENT_TILE
, (LPARAM
)szString
);
272 /* Load the default settings from the registry */
273 result
= RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, KEY_ALL_ACCESS
, ®Key
);
274 if (result
!= ERROR_SUCCESS
)
276 /* reg key open failed; maybe it does not exist? create it! */
277 DWORD dwDisposition
= 0;
278 result
= RegCreateKeyEx( HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
,
279 ®Key
, &dwDisposition
);
280 /* now the key must be created & opened and regKey points to opened key */
281 /* On error result will not contain ERROR_SUCCESS. I don't know how to handle */
285 result
= RegQueryValueEx(regKey
, TEXT("WallpaperStyle"), 0, &varType
, (LPBYTE
)szBuffer
, &bufferSize
);
286 if (result
== ERROR_SUCCESS
)
288 if (_ttoi(szBuffer
) == 0)
290 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_CENTER
, 0);
291 pData
->placementSelection
= PLACEMENT_CENTER
;
294 if (_ttoi(szBuffer
) == 2)
296 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_STRETCH
, 0);
297 pData
->placementSelection
= PLACEMENT_STRETCH
;
302 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_CENTER
, 0);
303 pData
->placementSelection
= PLACEMENT_CENTER
;
306 result
= RegQueryValueEx(regKey
, TEXT("TileWallpaper"), 0, &varType
, (LPBYTE
)szBuffer
, &bufferSize
);
307 if (result
== ERROR_SUCCESS
)
309 if (_ttoi(szBuffer
) == 1)
311 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_TILE
, 0);
312 pData
->placementSelection
= PLACEMENT_TILE
;
318 pData
->hBitmap
= (HBITMAP
) LoadImage(hApplet
, MAKEINTRESOURCE(IDC_MONITOR
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
319 if (pData
->hBitmap
!= NULL
)
321 GetObject(pData
->hBitmap
, sizeof(BITMAP
), &bitmap
);
323 pData
->cxSource
= bitmap
.bmWidth
;
324 pData
->cySource
= bitmap
.bmHeight
;
330 OnColorButton(HWND hwndDlg
, PDATA pData
)
332 /* Load custom colors from Registry */
334 LONG res
= ERROR_SUCCESS
;
337 res
= RegCreateKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Appearance"), 0, NULL
, 0,
338 KEY_ALL_ACCESS
, NULL
, &hKey
, NULL
);
339 /* Now the key is either created or opened existing, if res == ERROR_SUCCESS */
340 if (res
== ERROR_SUCCESS
)
343 DWORD dwType
= REG_BINARY
;
344 DWORD cbData
= sizeof(pData
->custom_colors
);
345 res
= RegQueryValueEx(hKey
, TEXT("CustomColors"), NULL
, &dwType
,
346 (LPBYTE
)pData
->custom_colors
, &cbData
);
351 /* Launch ChooseColor() dialog */
353 cc
.lStructSize
= sizeof(CHOOSECOLOR
);
354 cc
.hwndOwner
= hwndDlg
;
356 cc
.rgbResult
= g_GlobalData
.desktop_color
;
357 cc
.lpCustColors
= pData
->custom_colors
;
358 cc
.Flags
= CC_ANYCOLOR
| /* Causes the dialog box to display all available colors in the set of basic colors. */
359 CC_FULLOPEN
| /* opens dialog in full size */
360 CC_RGBINIT
; /* init chosen color by rgbResult value */
363 cc
.lpTemplateName
= NULL
;
364 if (ChooseColor(&cc
))
366 /* Save selected color to var */
367 g_GlobalData
.desktop_color
= cc
.rgbResult
;
369 /* Apply button will be activated */
370 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
372 /* Window will be updated :) */
373 InvalidateRect(GetDlgItem(hwndDlg
, IDC_BACKGROUND_PREVIEW
), NULL
, TRUE
);
375 /* Save custom colors to reg. To this moment key must be created already. See above */
376 res
= RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Appearance"), 0,
378 if (res
== ERROR_SUCCESS
)
381 RegSetValueEx(hKey
, TEXT("CustomColors"), 0, REG_BINARY
,
382 (const BYTE
*)pData
->custom_colors
, sizeof(pData
->custom_colors
));
391 * ListView_FindItem() Macro: Searches for a list-view item with the specified
392 * characteristics. Returns the index of the item if successful, or -1 otherwise
395 CheckListViewFilenameExists(HWND hwndList
, LPCTSTR tszFileName
)
400 lvfi
.flags
= LVFI_STRING
; /* search item by EXACT string */
401 lvfi
.psz
= tszFileName
; /* string to search */
403 /* other items of this structure are not valid, besacuse flags are not set. */
404 retVal
= ListView_FindItem(hwndList
, -1, &lvfi
);
406 return TRUE
; /* item found! */
408 return FALSE
; /* item not found. */
413 OnBrowseButton(HWND hwndDlg
, PDATA pData
)
416 TCHAR filename
[MAX_PATH
];
417 TCHAR fileTitle
[256];
418 TCHAR filter
[MAX_PATH
];
419 BackgroundItem
*backgroundItem
= NULL
;
422 HWND hwndBackgroundList
;
425 hwndBackgroundList
= GetDlgItem(hwndDlg
, IDC_BACKGROUND_LIST
);
427 ZeroMemory(&ofn
, sizeof(OPENFILENAME
));
429 ofn
.lStructSize
= sizeof(OPENFILENAME
);
430 ofn
.hwndOwner
= hwndDlg
;
431 ofn
.lpstrFile
= filename
;
433 LoadString(hApplet
, IDS_BACKGROUND_COMDLG_FILTER
, filter
, sizeof(filter
) / sizeof(TCHAR
));
435 /* Set lpstrFile[0] to '\0' so that GetOpenFileName does not
436 * use the contents of szFile to initialize itself */
437 ofn
.lpstrFile
[0] = TEXT('\0');
438 ofn
.nMaxFile
= MAX_PATH
;
439 ofn
.lpstrFilter
= filter
;
440 ofn
.nFilterIndex
= 0;
441 ofn
.lpstrFileTitle
= fileTitle
;
442 ofn
.nMaxFileTitle
= 256;
443 ofn
.lpstrInitialDir
= NULL
;
444 ofn
.Flags
= OFN_PATHMUSTEXIST
| OFN_FILEMUSTEXIST
;
446 if (GetOpenFileName(&ofn
) == TRUE
)
448 /* Check if there is already a entry that holds this filename */
449 if (CheckListViewFilenameExists(hwndBackgroundList
, ofn
.lpstrFileTitle
) == TRUE
)
452 if (pData
->listViewItemCount
> (MAX_BACKGROUNDS
- 1))
455 SHGetFileInfo(filename
,
459 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_DISPLAYNAME
);
461 backgroundItem
= &pData
->backgroundItems
[pData
->listViewItemCount
];
463 backgroundItem
->bWallpaper
= TRUE
;
465 _tcscpy(backgroundItem
->szDisplayName
, sfi
.szDisplayName
);
466 p
= _tcsrchr(backgroundItem
->szDisplayName
, _T('.'));
469 _tcscpy(backgroundItem
->szFilename
, filename
);
471 ZeroMemory(&listItem
, sizeof(LV_ITEM
));
472 listItem
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
474 listItem
.pszText
= backgroundItem
->szDisplayName
;
475 listItem
.iImage
= sfi
.iIcon
;
476 listItem
.iItem
= pData
->listViewItemCount
;
477 listItem
.lParam
= pData
->listViewItemCount
;
479 (void)ListView_InsertItem(hwndBackgroundList
, &listItem
);
480 ListView_SetItemState(hwndBackgroundList
,
481 pData
->listViewItemCount
,
484 SendMessage(hwndBackgroundList
, WM_VSCROLL
, SB_BOTTOM
, 0);
486 pData
->listViewItemCount
++;
492 ListViewItemChanged(HWND hwndDlg
, PDATA pData
, int itemIndex
)
494 BackgroundItem
*backgroundItem
= NULL
;
496 pData
->backgroundSelection
= itemIndex
;
497 backgroundItem
= &pData
->backgroundItems
[pData
->backgroundSelection
];
499 if (pData
->pWallpaperBitmap
!= NULL
)
501 DibFreeImage(pData
->pWallpaperBitmap
);
502 pData
->pWallpaperBitmap
= NULL
;
505 if (backgroundItem
->bWallpaper
== TRUE
)
507 pData
->pWallpaperBitmap
= DibLoadImage(backgroundItem
->szFilename
);
509 if (pData
->pWallpaperBitmap
== NULL
)
513 InvalidateRect(GetDlgItem(hwndDlg
, IDC_BACKGROUND_PREVIEW
),
516 EnableWindow(GetDlgItem(hwndDlg
, IDC_PLACEMENT_COMBO
),
517 backgroundItem
->bWallpaper
);
519 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
524 DrawBackgroundPreview(LPDRAWITEMSTRUCT draw
, PDATA pData
)
544 hDC
= CreateCompatibleDC(draw
->hDC
);
545 hOldObj
= SelectObject(hDC
, pData
->hBitmap
);
547 if (pData
->backgroundItems
[pData
->backgroundSelection
].bWallpaper
== FALSE
)
549 /* update desktop background color image */
550 hBrush
= CreateSolidBrush(g_GlobalData
.desktop_color
);
551 FillRect(hDC
, &rcItem
, hBrush
);
552 DeleteObject(hBrush
);
555 if (pData
->pWallpaperBitmap
!= NULL
)
557 scaleX
= ((float)GetSystemMetrics(SM_CXSCREEN
) - 1) / (float)MONITOR_WIDTH
;
558 scaleY
= ((float)GetSystemMetrics(SM_CYSCREEN
) - 1) / (float)MONITOR_HEIGHT
;
560 scaledWidth
= (int)(pData
->pWallpaperBitmap
->width
/ scaleX
);
561 scaledHeight
= (int)(pData
->pWallpaperBitmap
->height
/ scaleY
);
563 FillRect(hDC
, &rcItem
, GetSysColorBrush(COLOR_BACKGROUND
));
565 SetStretchBltMode(hDC
, COLORONCOLOR
);
567 switch (pData
->placementSelection
)
569 case PLACEMENT_CENTER
:
570 posX
= (MONITOR_WIDTH
- scaledWidth
+ 1) / 2;
571 posY
= (MONITOR_HEIGHT
- scaledHeight
+ 1) / 2;
575 if (posX
< 0) { desX
= -posX
/ 2; posX
= 0; }
576 if (posY
< 0) { desY
= -posY
/ 2; posY
= 0; }
578 if (scaledWidth
> MONITOR_WIDTH
)
579 scaledWidth
= MONITOR_WIDTH
;
581 if (scaledHeight
> MONITOR_HEIGHT
)
582 scaledHeight
= MONITOR_HEIGHT
;
591 pData
->pWallpaperBitmap
->width
- (int)(desX
* scaleX
),
592 pData
->pWallpaperBitmap
->height
- (int)(desY
* scaleY
),
593 pData
->pWallpaperBitmap
->bits
,
594 pData
->pWallpaperBitmap
->info
,
599 case PLACEMENT_STRETCH
:
607 pData
->pWallpaperBitmap
->width
,
608 pData
->pWallpaperBitmap
->height
,
609 pData
->pWallpaperBitmap
->bits
,
610 pData
->pWallpaperBitmap
->info
,
616 for (y
= 0; y
< MONITOR_HEIGHT
; y
+= scaledHeight
)
618 for (x
= 0; x
< MONITOR_WIDTH
; x
+= scaledWidth
)
620 if ((MONITOR_WIDTH
-x
) >= scaledWidth
)
623 posX
= MONITOR_WIDTH
-x
;
626 if ((MONITOR_HEIGHT
-y
) >= scaledHeight
)
629 posY
= MONITOR_HEIGHT
-y
;
638 pData
->pWallpaperBitmap
->width
* posX
/ scaledWidth
,
639 pData
->pWallpaperBitmap
->height
* posY
/ scaledHeight
,
640 pData
->pWallpaperBitmap
->bits
,
641 pData
->pWallpaperBitmap
->info
,
652 TransparentBlt(draw
->hDC
,
653 draw
->rcItem
.left
, draw
->rcItem
.top
,
654 draw
->rcItem
.right
-draw
->rcItem
.left
+1,
655 draw
->rcItem
.bottom
-draw
->rcItem
.top
+1,
658 pData
->cxSource
, pData
->cySource
,
661 SelectObject(hDC
, hOldObj
);
667 SetWallpaper(PDATA pData
)
671 RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, KEY_ALL_ACCESS
, ®Key
);
673 if (pData
->placementSelection
== PLACEMENT_TILE
)
675 RegSetValueEx(regKey
, TEXT("TileWallpaper"), 0, REG_SZ
, (BYTE
*)TEXT("1"), sizeof(TCHAR
) * 2);
676 RegSetValueEx(regKey
, TEXT("WallpaperStyle"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
679 if (pData
->placementSelection
== PLACEMENT_CENTER
)
681 RegSetValueEx(regKey
, TEXT("TileWallpaper"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
682 RegSetValueEx(regKey
, TEXT("WallpaperStyle"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
685 if (pData
->placementSelection
== PLACEMENT_STRETCH
)
687 RegSetValueEx(regKey
, TEXT("TileWallpaper"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
688 RegSetValueEx(regKey
, TEXT("WallpaperStyle"), 0, REG_SZ
, (BYTE
*)TEXT("2"), sizeof(TCHAR
) * 2);
693 if (pData
->backgroundItems
[pData
->backgroundSelection
].bWallpaper
== TRUE
)
695 SystemParametersInfo(SPI_SETDESKWALLPAPER
,
697 pData
->backgroundItems
[pData
->backgroundSelection
].szFilename
,
702 SystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, (void*) TEXT(""), SPIF_UPDATEINIFILE
);
707 /* Change system color */
709 SetDesktopBackColor(HWND hwndDlg
, DATA
*pData
)
711 INT iElement
= COLOR_BACKGROUND
;
715 BYTE red
, green
, blue
;
718 if( !SetSysColors( 1, &iElement
, &g_GlobalData
.desktop_color
) )
719 MessageBox(hwndDlg
, TEXT("SetSysColor() failed!"), /* these error texts can need internationalization? */
720 TEXT("Error!"), MB_ICONSTOP
);
722 result
= RegCreateKeyEx( HKEY_CURRENT_USER
, TEXT("Control Panel\\Colors"), 0, NULL
, 0,
723 KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDispostion
);
724 if (result
!= ERROR_SUCCESS
)
726 red
= GetRValue(g_GlobalData
.desktop_color
);
727 green
= GetGValue(g_GlobalData
.desktop_color
);
728 blue
= GetBValue(g_GlobalData
.desktop_color
);
729 /* format string to be set to registry */
730 wsprintf(clText
, TEXT("%d %d %d"), red
, green
, blue
);
731 RegSetValueEx(hKey
, TEXT("Background"), 0, REG_SZ
, (BYTE
*)clText
,
732 (lstrlen(clText
) + 1) * sizeof(TCHAR
));
738 BackgroundPageProc(HWND hwndDlg
,
745 pData
= (PDATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
750 pData
= (DATA
*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DATA
));
751 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pData
);
752 InitBackgroundDialog(hwndDlg
, pData
);
757 DWORD controlId
= LOWORD(wParam
);
758 DWORD command
= HIWORD(wParam
);
762 case IDC_COLOR_BUTTON
:
763 if (command
== BN_CLICKED
)
764 OnColorButton(hwndDlg
, pData
);
767 case IDC_BROWSE_BUTTON
:
768 if (command
== BN_CLICKED
)
769 OnBrowseButton(hwndDlg
, pData
);
772 case IDC_PLACEMENT_COMBO
:
773 if (command
== CBN_SELCHANGE
)
775 pData
->placementSelection
= (int)SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_GETCURSEL
, 0, 0);
777 InvalidateRect(GetDlgItem(hwndDlg
, IDC_BACKGROUND_PREVIEW
), NULL
, TRUE
);
779 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
787 LPDRAWITEMSTRUCT drawItem
;
788 drawItem
= (LPDRAWITEMSTRUCT
)lParam
;
790 if (drawItem
->CtlID
== IDC_BACKGROUND_PREVIEW
)
792 DrawBackgroundPreview(drawItem
, pData
);
800 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
806 SetDesktopBackColor(hwndDlg
, pData
);
809 case LVN_ITEMCHANGED
:
811 LPNMLISTVIEW nm
= (LPNMLISTVIEW
)lParam
;
813 if ((nm
->uNewState
& LVIS_SELECTED
) == 0)
816 ListViewItemChanged(hwndDlg
, pData
, nm
->iItem
);
824 if (pData
->pWallpaperBitmap
!= NULL
)
825 DibFreeImage(pData
->pWallpaperBitmap
);
827 DeleteObject(pData
->hBitmap
);
828 HeapFree(GetProcessHeap(), 0, pData
);