2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: dll/cpl/desk/background.c
5 * PURPOSE: Background property page
7 * PROGRAMMERS: Trevor McCort (lycan359@gmail.com)
8 * Alexey Minnekhanov (minlexx@rambler.ru)
13 #define MAX_BACKGROUNDS 100
15 #define PLACEMENT_CENTER 0
16 #define PLACEMENT_STRETCH 1
17 #define PLACEMENT_TILE 2
19 /* The values in these macros are dependant on the
20 * layout of the monitor image and they must be adjusted
21 * if that image will be changed.
23 #define MONITOR_LEFT 18
24 #define MONITOR_TOP 18
25 #define MONITOR_RIGHT 168
26 #define MONITOR_BOTTOM 128
28 #define MONITOR_WIDTH (MONITOR_RIGHT-MONITOR_LEFT)
29 #define MONITOR_HEIGHT (MONITOR_BOTTOM-MONITOR_TOP)
33 BOOL bWallpaper
; /* Is this background a wallpaper */
35 TCHAR szFilename
[MAX_PATH
];
36 TCHAR szDisplayName
[256];
42 BOOL bWallpaperChanged
;
43 BOOL bClrBackgroundChanged
;
45 BackgroundItem backgroundItems
[MAX_BACKGROUNDS
];
47 PDIBITMAP pWallpaperBitmap
;
49 int placementSelection
;
50 int backgroundSelection
;
52 COLORREF custom_colors
[16];
54 int listViewItemCount
;
61 GLOBAL_DATA g_GlobalData
;
64 /* Add the images in the C:\ReactOS directory and the current wallpaper if any */
66 AddListViewItems(HWND hwndDlg
, PDATA pData
)
70 TCHAR szSearchPath
[MAX_PATH
];
71 TCHAR szFileTypes
[MAX_PATH
];
78 TCHAR wallpaperFilename
[MAX_PATH
];
79 DWORD bufferSize
= sizeof(wallpaperFilename
);
80 TCHAR buffer
[MAX_PATH
];
81 DWORD varType
= REG_SZ
;
84 BackgroundItem
*backgroundItem
= NULL
;
85 TCHAR separators
[] = TEXT(";");
87 HWND hwndBackgroundList
;
90 hwndBackgroundList
= GetDlgItem(hwndDlg
, IDC_BACKGROUND_LIST
);
92 GetClientRect(hwndBackgroundList
, &clientRect
);
94 /* Add a new column to the list */
95 ZeroMemory(&dummy
, sizeof(LV_COLUMN
));
96 dummy
.mask
= LVCF_SUBITEM
| LVCF_WIDTH
;
98 dummy
.cx
= (clientRect
.right
- clientRect
.left
) - GetSystemMetrics(SM_CXVSCROLL
);
99 (void)ListView_InsertColumn(hwndBackgroundList
, 0, &dummy
);
101 /* Add the "None" item */
102 backgroundItem
= &pData
->backgroundItems
[pData
->listViewItemCount
];
103 backgroundItem
->bWallpaper
= FALSE
;
106 backgroundItem
->szDisplayName
,
107 sizeof(backgroundItem
->szDisplayName
) / sizeof(TCHAR
));
109 ZeroMemory(&listItem
, sizeof(LV_ITEM
));
110 listItem
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
112 listItem
.pszText
= backgroundItem
->szDisplayName
;
113 listItem
.iImage
= -1;
114 listItem
.iItem
= pData
->listViewItemCount
;
115 listItem
.lParam
= pData
->listViewItemCount
;
117 (void)ListView_InsertItem(hwndBackgroundList
, &listItem
);
118 ListView_SetItemState(hwndBackgroundList
,
119 pData
->listViewItemCount
,
123 pData
->listViewItemCount
++;
125 /* Add current wallpaper if any */
126 result
= RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, KEY_ALL_ACCESS
, ®Key
);
127 if (result
== ERROR_SUCCESS
)
129 result
= RegQueryValueEx(regKey
, TEXT("Wallpaper"), 0, &varType
, (LPBYTE
)wallpaperFilename
, &bufferSize
);
130 if ((result
== ERROR_SUCCESS
) && (_tcslen(wallpaperFilename
) > 0))
132 /* Allow environment variables in file name */
133 if (ExpandEnvironmentStrings(wallpaperFilename
, buffer
, MAX_PATH
))
135 _tcscpy(wallpaperFilename
, buffer
);
138 himl
= (HIMAGELIST
)SHGetFileInfo(wallpaperFilename
,
142 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
|
149 (void)ListView_SetImageList(hwndBackgroundList
, himl
, LVSIL_SMALL
);
152 backgroundItem
= &pData
->backgroundItems
[pData
->listViewItemCount
];
154 backgroundItem
->bWallpaper
= TRUE
;
156 _tcscpy(backgroundItem
->szDisplayName
, sfi
.szDisplayName
);
157 p
= _tcsrchr(backgroundItem
->szDisplayName
, _T('.'));
160 _tcscpy(backgroundItem
->szFilename
, wallpaperFilename
);
162 ZeroMemory(&listItem
, sizeof(LV_ITEM
));
163 listItem
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
165 listItem
.pszText
= backgroundItem
->szDisplayName
;
166 listItem
.iImage
= sfi
.iIcon
;
167 listItem
.iItem
= pData
->listViewItemCount
;
168 listItem
.lParam
= pData
->listViewItemCount
;
170 (void)ListView_InsertItem(hwndBackgroundList
, &listItem
);
171 ListView_SetItemState(hwndBackgroundList
,
172 pData
->listViewItemCount
,
176 pData
->listViewItemCount
++;
183 /* Add all the images in the C:\ReactOS directory. */
185 LoadString(hApplet
, IDS_SUPPORTED_EXT
, szFileTypes
, sizeof(szFileTypes
) / sizeof(TCHAR
));
187 token
= _tcstok(szFileTypes
, separators
);
188 while (token
!= NULL
)
190 GetWindowsDirectory(szSearchPath
, MAX_PATH
);
191 _tcscat(szSearchPath
, TEXT("\\"));
192 _tcscat(szSearchPath
, token
);
194 hFind
= FindFirstFile(szSearchPath
, &fd
);
195 while (hFind
!= INVALID_HANDLE_VALUE
)
197 TCHAR filename
[MAX_PATH
];
199 GetWindowsDirectory(filename
, MAX_PATH
);
201 _tcscat(filename
, TEXT("\\"));
202 _tcscat(filename
, fd
.cFileName
);
204 /* Don't add any hidden bitmaps. Also don't add current wallpaper once more. */
205 if (((fd
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
) == 0) && (_tcscmp(wallpaperFilename
, filename
) != 0))
207 himl
= (HIMAGELIST
)SHGetFileInfo(filename
,
211 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
|
219 (void)ListView_SetImageList(hwndBackgroundList
, himl
, LVSIL_SMALL
);
222 backgroundItem
= &pData
->backgroundItems
[pData
->listViewItemCount
];
224 backgroundItem
->bWallpaper
= TRUE
;
226 _tcscpy(backgroundItem
->szDisplayName
, sfi
.szDisplayName
);
227 p
= _tcsrchr(backgroundItem
->szDisplayName
, _T('.'));
230 _tcscpy(backgroundItem
->szFilename
, filename
);
232 ZeroMemory(&listItem
, sizeof(LV_ITEM
));
233 listItem
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
234 listItem
.pszText
= backgroundItem
->szDisplayName
;
236 listItem
.iImage
= sfi
.iIcon
;
237 listItem
.iItem
= pData
->listViewItemCount
;
238 listItem
.lParam
= pData
->listViewItemCount
;
240 (void)ListView_InsertItem(hwndBackgroundList
, &listItem
);
242 pData
->listViewItemCount
++;
245 if(!FindNextFile(hFind
, &fd
))
246 hFind
= INVALID_HANDLE_VALUE
;
249 token
= _tcstok(NULL
, separators
);
255 InitBackgroundDialog(HWND hwndDlg
, PDATA pData
)
260 DWORD bufferSize
= sizeof(szBuffer
);
261 DWORD varType
= REG_SZ
;
265 AddListViewItems(hwndDlg
, pData
);
267 LoadString(hApplet
, IDS_CENTER
, szString
, sizeof(szString
) / sizeof(TCHAR
));
268 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_INSERTSTRING
, PLACEMENT_CENTER
, (LPARAM
)szString
);
270 LoadString(hApplet
, IDS_STRETCH
, szString
, sizeof(szString
) / sizeof(TCHAR
));
271 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_INSERTSTRING
, PLACEMENT_STRETCH
, (LPARAM
)szString
);
273 LoadString(hApplet
, IDS_TILE
, szString
, sizeof(szString
) / sizeof(TCHAR
));
274 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_INSERTSTRING
, PLACEMENT_TILE
, (LPARAM
)szString
);
276 /* Load the default settings from the registry */
277 result
= RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, KEY_ALL_ACCESS
, ®Key
);
278 if (result
!= ERROR_SUCCESS
)
280 /* reg key open failed; maybe it does not exist? create it! */
281 DWORD dwDisposition
= 0;
282 result
= RegCreateKeyEx( HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
,
283 ®Key
, &dwDisposition
);
284 /* Now the key must be created & opened and regKey points to opened key */
285 /* On error result will not contain ERROR_SUCCESS. I don't know how to handle */
289 result
= RegQueryValueEx(regKey
, TEXT("WallpaperStyle"), 0, &varType
, (LPBYTE
)szBuffer
, &bufferSize
);
290 if (result
== ERROR_SUCCESS
)
292 if (_ttoi(szBuffer
) == 0)
294 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_CENTER
, 0);
295 pData
->placementSelection
= PLACEMENT_CENTER
;
298 if (_ttoi(szBuffer
) == 2)
300 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_STRETCH
, 0);
301 pData
->placementSelection
= PLACEMENT_STRETCH
;
306 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_CENTER
, 0);
307 pData
->placementSelection
= PLACEMENT_CENTER
;
310 result
= RegQueryValueEx(regKey
, TEXT("TileWallpaper"), 0, &varType
, (LPBYTE
)szBuffer
, &bufferSize
);
311 if (result
== ERROR_SUCCESS
)
313 if (_ttoi(szBuffer
) == 1)
315 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_TILE
, 0);
316 pData
->placementSelection
= PLACEMENT_TILE
;
322 pData
->hBitmap
= (HBITMAP
) LoadImage(hApplet
, MAKEINTRESOURCE(IDC_MONITOR
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
323 if (pData
->hBitmap
!= NULL
)
325 GetObject(pData
->hBitmap
, sizeof(BITMAP
), &bitmap
);
327 pData
->cxSource
= bitmap
.bmWidth
;
328 pData
->cySource
= bitmap
.bmHeight
;
334 OnColorButton(HWND hwndDlg
, PDATA pData
)
336 /* Load custom colors from Registry */
338 LONG res
= ERROR_SUCCESS
;
341 res
= RegCreateKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Appearance"), 0, NULL
, 0,
342 KEY_ALL_ACCESS
, NULL
, &hKey
, NULL
);
343 /* Now the key is either created or opened existing, if res == ERROR_SUCCESS */
344 if (res
== ERROR_SUCCESS
)
347 DWORD dwType
= REG_BINARY
;
348 DWORD cbData
= sizeof(pData
->custom_colors
);
349 res
= RegQueryValueEx(hKey
, TEXT("CustomColors"), NULL
, &dwType
,
350 (LPBYTE
)pData
->custom_colors
, &cbData
);
355 /* Launch ChooseColor() dialog */
357 cc
.lStructSize
= sizeof(CHOOSECOLOR
);
358 cc
.hwndOwner
= hwndDlg
;
360 cc
.rgbResult
= g_GlobalData
.desktop_color
;
361 cc
.lpCustColors
= pData
->custom_colors
;
362 cc
.Flags
= CC_ANYCOLOR
| /* Causes the dialog box to display all available colors in the set of basic colors. */
363 CC_FULLOPEN
| /* opens dialog in full size */
364 CC_RGBINIT
; /* init chosen color by rgbResult value */
367 cc
.lpTemplateName
= NULL
;
368 if (ChooseColor(&cc
))
370 /* Save selected color to var */
371 g_GlobalData
.desktop_color
= cc
.rgbResult
;
372 pData
->bClrBackgroundChanged
= TRUE
;
374 /* Apply button will be activated */
375 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
377 /* Window will be updated :) */
378 InvalidateRect(GetDlgItem(hwndDlg
, IDC_BACKGROUND_PREVIEW
), NULL
, TRUE
);
380 /* Save custom colors to reg. To this moment key must be created already. See above */
381 res
= RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Appearance"), 0,
383 if (res
== ERROR_SUCCESS
)
386 RegSetValueEx(hKey
, TEXT("CustomColors"), 0, REG_BINARY
,
387 (const BYTE
*)pData
->custom_colors
, sizeof(pData
->custom_colors
));
396 * ListView_FindItem() Macro: Searches for a list-view item with the specified
397 * characteristics. Returns the index of the item if successful, or -1 otherwise
400 CheckListViewFilenameExists(HWND hwndList
, LPCTSTR tszFileName
)
405 lvfi
.flags
= LVFI_STRING
; /* Search item by EXACT string */
406 lvfi
.psz
= tszFileName
; /* String to search */
408 /* Other items of this structure are not valid, besacuse flags are not set. */
409 retVal
= ListView_FindItem(hwndList
, -1, &lvfi
);
411 return TRUE
; /* item found! */
413 return FALSE
; /* item not found. */
418 OnBrowseButton(HWND hwndDlg
, PDATA pData
)
421 TCHAR filename
[MAX_PATH
];
422 TCHAR fileTitle
[256];
423 TCHAR filter
[MAX_PATH
];
424 BackgroundItem
*backgroundItem
= NULL
;
427 HWND hwndBackgroundList
;
430 hwndBackgroundList
= GetDlgItem(hwndDlg
, IDC_BACKGROUND_LIST
);
432 ZeroMemory(&ofn
, sizeof(OPENFILENAME
));
434 ofn
.lStructSize
= sizeof(OPENFILENAME
);
435 ofn
.hwndOwner
= hwndDlg
;
436 ofn
.lpstrFile
= filename
;
438 LoadString(hApplet
, IDS_BACKGROUND_COMDLG_FILTER
, filter
, sizeof(filter
) / sizeof(TCHAR
));
440 /* Set lpstrFile[0] to '\0' so that GetOpenFileName does not
441 * use the contents of szFile to initialize itself */
442 ofn
.lpstrFile
[0] = TEXT('\0');
443 ofn
.nMaxFile
= MAX_PATH
;
444 ofn
.lpstrFilter
= filter
;
445 ofn
.nFilterIndex
= 0;
446 ofn
.lpstrFileTitle
= fileTitle
;
447 ofn
.nMaxFileTitle
= 256;
448 ofn
.lpstrInitialDir
= NULL
;
449 ofn
.Flags
= OFN_PATHMUSTEXIST
| OFN_FILEMUSTEXIST
;
451 if (GetOpenFileName(&ofn
) == TRUE
)
453 /* Check if there is already a entry that holds this filename */
454 if (CheckListViewFilenameExists(hwndBackgroundList
, ofn
.lpstrFileTitle
) == TRUE
)
457 if (pData
->listViewItemCount
> (MAX_BACKGROUNDS
- 1))
460 SHGetFileInfo(filename
,
464 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_DISPLAYNAME
);
466 backgroundItem
= &pData
->backgroundItems
[pData
->listViewItemCount
];
468 backgroundItem
->bWallpaper
= TRUE
;
470 _tcscpy(backgroundItem
->szDisplayName
, sfi
.szDisplayName
);
471 p
= _tcsrchr(backgroundItem
->szDisplayName
, _T('.'));
474 _tcscpy(backgroundItem
->szFilename
, filename
);
476 ZeroMemory(&listItem
, sizeof(LV_ITEM
));
477 listItem
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
479 listItem
.pszText
= backgroundItem
->szDisplayName
;
480 listItem
.iImage
= sfi
.iIcon
;
481 listItem
.iItem
= pData
->listViewItemCount
;
482 listItem
.lParam
= pData
->listViewItemCount
;
484 (void)ListView_InsertItem(hwndBackgroundList
, &listItem
);
485 ListView_SetItemState(hwndBackgroundList
,
486 pData
->listViewItemCount
,
489 SendMessage(hwndBackgroundList
, WM_VSCROLL
, SB_BOTTOM
, 0);
491 pData
->listViewItemCount
++;
497 ListViewItemChanged(HWND hwndDlg
, PDATA pData
, int itemIndex
)
499 BackgroundItem
*backgroundItem
= NULL
;
501 pData
->backgroundSelection
= itemIndex
;
502 backgroundItem
= &pData
->backgroundItems
[pData
->backgroundSelection
];
504 if (pData
->pWallpaperBitmap
!= NULL
)
506 DibFreeImage(pData
->pWallpaperBitmap
);
507 pData
->pWallpaperBitmap
= NULL
;
510 if (backgroundItem
->bWallpaper
== TRUE
)
512 pData
->pWallpaperBitmap
= DibLoadImage(backgroundItem
->szFilename
);
514 if (pData
->pWallpaperBitmap
== NULL
)
518 pData
->bWallpaperChanged
= TRUE
;
520 InvalidateRect(GetDlgItem(hwndDlg
, IDC_BACKGROUND_PREVIEW
),
523 EnableWindow(GetDlgItem(hwndDlg
, IDC_PLACEMENT_COMBO
),
524 backgroundItem
->bWallpaper
);
526 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
531 DrawBackgroundPreview(LPDRAWITEMSTRUCT draw
, PDATA pData
)
551 hDC
= CreateCompatibleDC(draw
->hDC
);
552 hOldObj
= SelectObject(hDC
, pData
->hBitmap
);
554 if (pData
->backgroundItems
[pData
->backgroundSelection
].bWallpaper
== FALSE
)
556 /* Update desktop background color image */
557 hBrush
= CreateSolidBrush(g_GlobalData
.desktop_color
);
558 FillRect(hDC
, &rcItem
, hBrush
);
559 DeleteObject(hBrush
);
562 if (pData
->pWallpaperBitmap
!= NULL
)
564 scaleX
= ((float)GetSystemMetrics(SM_CXSCREEN
) - 1) / (float)MONITOR_WIDTH
;
565 scaleY
= ((float)GetSystemMetrics(SM_CYSCREEN
) - 1) / (float)MONITOR_HEIGHT
;
567 scaledWidth
= (int)(pData
->pWallpaperBitmap
->width
/ scaleX
);
568 scaledHeight
= (int)(pData
->pWallpaperBitmap
->height
/ scaleY
);
570 FillRect(hDC
, &rcItem
, GetSysColorBrush(COLOR_BACKGROUND
));
572 SetStretchBltMode(hDC
, COLORONCOLOR
);
574 switch (pData
->placementSelection
)
576 case PLACEMENT_CENTER
:
577 posX
= (MONITOR_WIDTH
- scaledWidth
+ 1) / 2;
578 posY
= (MONITOR_HEIGHT
- scaledHeight
+ 1) / 2;
582 if (posX
< 0) { desX
= -posX
/ 2; posX
= 0; }
583 if (posY
< 0) { desY
= -posY
/ 2; posY
= 0; }
585 if (scaledWidth
> MONITOR_WIDTH
)
586 scaledWidth
= MONITOR_WIDTH
;
588 if (scaledHeight
> MONITOR_HEIGHT
)
589 scaledHeight
= MONITOR_HEIGHT
;
598 pData
->pWallpaperBitmap
->width
- (int)(desX
* scaleX
),
599 pData
->pWallpaperBitmap
->height
- (int)(desY
* scaleY
),
600 pData
->pWallpaperBitmap
->bits
,
601 pData
->pWallpaperBitmap
->info
,
606 case PLACEMENT_STRETCH
:
614 pData
->pWallpaperBitmap
->width
,
615 pData
->pWallpaperBitmap
->height
,
616 pData
->pWallpaperBitmap
->bits
,
617 pData
->pWallpaperBitmap
->info
,
623 for (y
= 0; y
< MONITOR_HEIGHT
; y
+= scaledHeight
)
625 for (x
= 0; x
< MONITOR_WIDTH
; x
+= scaledWidth
)
627 if ((MONITOR_WIDTH
-x
) >= scaledWidth
)
630 posX
= MONITOR_WIDTH
-x
;
633 if ((MONITOR_HEIGHT
-y
) >= scaledHeight
)
636 posY
= MONITOR_HEIGHT
-y
;
645 pData
->pWallpaperBitmap
->width
* posX
/ scaledWidth
,
646 pData
->pWallpaperBitmap
->height
* posY
/ scaledHeight
,
647 pData
->pWallpaperBitmap
->bits
,
648 pData
->pWallpaperBitmap
->info
,
659 GdiTransparentBlt(draw
->hDC
,
660 draw
->rcItem
.left
, draw
->rcItem
.top
,
661 draw
->rcItem
.right
-draw
->rcItem
.left
+1,
662 draw
->rcItem
.bottom
-draw
->rcItem
.top
+1,
665 pData
->cxSource
, pData
->cySource
,
668 SelectObject(hDC
, hOldObj
);
674 SetWallpaper(PDATA pData
)
678 RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, KEY_ALL_ACCESS
, ®Key
);
680 if (pData
->placementSelection
== PLACEMENT_TILE
)
682 RegSetValueEx(regKey
, TEXT("TileWallpaper"), 0, REG_SZ
, (BYTE
*)TEXT("1"), sizeof(TCHAR
) * 2);
683 RegSetValueEx(regKey
, TEXT("WallpaperStyle"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
686 if (pData
->placementSelection
== PLACEMENT_CENTER
)
688 RegSetValueEx(regKey
, TEXT("TileWallpaper"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
689 RegSetValueEx(regKey
, TEXT("WallpaperStyle"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
692 if (pData
->placementSelection
== PLACEMENT_STRETCH
)
694 RegSetValueEx(regKey
, TEXT("TileWallpaper"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
695 RegSetValueEx(regKey
, TEXT("WallpaperStyle"), 0, REG_SZ
, (BYTE
*)TEXT("2"), sizeof(TCHAR
) * 2);
700 if (pData
->backgroundItems
[pData
->backgroundSelection
].bWallpaper
== TRUE
)
702 SystemParametersInfo(SPI_SETDESKWALLPAPER
,
704 pData
->backgroundItems
[pData
->backgroundSelection
].szFilename
,
709 SystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, (void*) TEXT(""), SPIF_UPDATEINIFILE
);
714 /* Change system color */
716 SetDesktopBackColor(HWND hwndDlg
, DATA
*pData
)
718 INT iElement
= COLOR_BACKGROUND
;
722 BYTE red
, green
, blue
;
725 if( !SetSysColors( 1, &iElement
, &g_GlobalData
.desktop_color
) )
726 MessageBox(hwndDlg
, TEXT("SetSysColor() failed!"), /* these error texts can need internationalization? */
727 TEXT("Error!"), MB_ICONSTOP
);
729 result
= RegCreateKeyEx( HKEY_CURRENT_USER
, TEXT("Control Panel\\Colors"), 0, NULL
, 0,
730 KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDispostion
);
731 if (result
!= ERROR_SUCCESS
)
733 red
= GetRValue(g_GlobalData
.desktop_color
);
734 green
= GetGValue(g_GlobalData
.desktop_color
);
735 blue
= GetBValue(g_GlobalData
.desktop_color
);
736 /* Format string to be set to registry */
737 wsprintf(clText
, TEXT("%d %d %d"), red
, green
, blue
);
738 RegSetValueEx(hKey
, TEXT("Background"), 0, REG_SZ
, (BYTE
*)clText
,
739 (lstrlen(clText
) + 1) * sizeof(TCHAR
));
745 BackgroundPageProc(HWND hwndDlg
,
752 pData
= (PDATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
757 pData
= (DATA
*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DATA
));
758 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pData
);
759 InitBackgroundDialog(hwndDlg
, pData
);
764 DWORD controlId
= LOWORD(wParam
);
765 DWORD command
= HIWORD(wParam
);
769 case IDC_COLOR_BUTTON
:
770 if (command
== BN_CLICKED
)
771 OnColorButton(hwndDlg
, pData
);
774 case IDC_BROWSE_BUTTON
:
775 if (command
== BN_CLICKED
)
776 OnBrowseButton(hwndDlg
, pData
);
779 case IDC_PLACEMENT_COMBO
:
780 if (command
== CBN_SELCHANGE
)
782 pData
->placementSelection
= (int)SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_GETCURSEL
, 0, 0);
784 InvalidateRect(GetDlgItem(hwndDlg
, IDC_BACKGROUND_PREVIEW
), NULL
, TRUE
);
786 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
794 LPDRAWITEMSTRUCT drawItem
;
795 drawItem
= (LPDRAWITEMSTRUCT
)lParam
;
797 if (drawItem
->CtlID
== IDC_BACKGROUND_PREVIEW
)
799 DrawBackgroundPreview(drawItem
, pData
);
807 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
812 if(pData
->bWallpaperChanged
)
814 if(pData
->bClrBackgroundChanged
)
815 SetDesktopBackColor(hwndDlg
, pData
);
816 SendMessage(HWND_BROADCAST
, WM_SETTINGCHANGE
, 0, (LPARAM
)_T(""));
819 case LVN_ITEMCHANGED
:
821 LPNMLISTVIEW nm
= (LPNMLISTVIEW
)lParam
;
823 if ((nm
->uNewState
& LVIS_SELECTED
) == 0)
826 ListViewItemChanged(hwndDlg
, pData
, nm
->iItem
);
834 if (pData
->pWallpaperBitmap
!= NULL
)
835 DibFreeImage(pData
->pWallpaperBitmap
);
837 DeleteObject(pData
->hBitmap
);
838 HeapFree(GetProcessHeap(), 0, pData
);