3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS Display Control Panel
5 * FILE: dll/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 BOOL bWallpaperChanged
;
44 BOOL bClrBackgroundChanged
;
46 BackgroundItem backgroundItems
[MAX_BACKGROUNDS
];
48 PDIBITMAP pWallpaperBitmap
;
50 int placementSelection
;
51 int backgroundSelection
;
53 COLORREF custom_colors
[16];
55 int listViewItemCount
;
62 GLOBAL_DATA g_GlobalData
;
65 /* Add the images in the C:\ReactOS directory and the current wallpaper if any */
67 AddListViewItems(HWND hwndDlg
, PDATA pData
)
71 TCHAR szSearchPath
[MAX_PATH
];
72 TCHAR szFileTypes
[MAX_PATH
];
79 TCHAR wallpaperFilename
[MAX_PATH
];
80 DWORD bufferSize
= sizeof(wallpaperFilename
);
81 TCHAR buffer
[MAX_PATH
];
82 DWORD varType
= REG_SZ
;
85 BackgroundItem
*backgroundItem
= NULL
;
86 TCHAR separators
[] = TEXT(";");
88 HWND hwndBackgroundList
;
91 hwndBackgroundList
= GetDlgItem(hwndDlg
, IDC_BACKGROUND_LIST
);
93 GetClientRect(hwndBackgroundList
, &clientRect
);
95 /* Add a new column to the list */
96 ZeroMemory(&dummy
, sizeof(LV_COLUMN
));
97 dummy
.mask
= LVCF_SUBITEM
| LVCF_WIDTH
;
99 dummy
.cx
= (clientRect
.right
- clientRect
.left
) - GetSystemMetrics(SM_CXVSCROLL
);
100 (void)ListView_InsertColumn(hwndBackgroundList
, 0, &dummy
);
102 /* Add the "None" item */
103 backgroundItem
= &pData
->backgroundItems
[pData
->listViewItemCount
];
104 backgroundItem
->bWallpaper
= FALSE
;
107 backgroundItem
->szDisplayName
,
108 sizeof(backgroundItem
->szDisplayName
) / sizeof(TCHAR
));
110 ZeroMemory(&listItem
, sizeof(LV_ITEM
));
111 listItem
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
113 listItem
.pszText
= backgroundItem
->szDisplayName
;
114 listItem
.iImage
= -1;
115 listItem
.iItem
= pData
->listViewItemCount
;
116 listItem
.lParam
= pData
->listViewItemCount
;
118 (void)ListView_InsertItem(hwndBackgroundList
, &listItem
);
119 ListView_SetItemState(hwndBackgroundList
,
120 pData
->listViewItemCount
,
124 pData
->listViewItemCount
++;
126 /* Add current wallpaper if any */
127 RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, KEY_ALL_ACCESS
, ®Key
);
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
++;
182 /* Add all the images in the C:\ReactOS directory. */
184 LoadString(hApplet
, IDS_SUPPORTED_EXT
, szFileTypes
, sizeof(szFileTypes
) / sizeof(TCHAR
));
186 token
= _tcstok(szFileTypes
, separators
);
187 while (token
!= NULL
)
189 GetWindowsDirectory(szSearchPath
, MAX_PATH
);
190 _tcscat(szSearchPath
, TEXT("\\"));
191 _tcscat(szSearchPath
, token
);
193 hFind
= FindFirstFile(szSearchPath
, &fd
);
194 while (hFind
!= INVALID_HANDLE_VALUE
)
196 TCHAR filename
[MAX_PATH
];
198 GetWindowsDirectory(filename
, MAX_PATH
);
200 _tcscat(filename
, TEXT("\\"));
201 _tcscat(filename
, fd
.cFileName
);
203 /* Don't add any hidden bitmaps. Also don't add current wallpaper once more. */
204 if (((fd
.dwFileAttributes
& FILE_ATTRIBUTE_HIDDEN
) == 0) && (_tcscmp(wallpaperFilename
, filename
) != 0))
206 himl
= (HIMAGELIST
)SHGetFileInfo(filename
,
210 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
|
218 (void)ListView_SetImageList(hwndBackgroundList
, himl
, LVSIL_SMALL
);
221 backgroundItem
= &pData
->backgroundItems
[pData
->listViewItemCount
];
223 backgroundItem
->bWallpaper
= TRUE
;
225 _tcscpy(backgroundItem
->szDisplayName
, sfi
.szDisplayName
);
226 p
= _tcsrchr(backgroundItem
->szDisplayName
, _T('.'));
229 _tcscpy(backgroundItem
->szFilename
, filename
);
231 ZeroMemory(&listItem
, sizeof(LV_ITEM
));
232 listItem
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
233 listItem
.pszText
= backgroundItem
->szDisplayName
;
235 listItem
.iImage
= sfi
.iIcon
;
236 listItem
.iItem
= pData
->listViewItemCount
;
237 listItem
.lParam
= pData
->listViewItemCount
;
239 (void)ListView_InsertItem(hwndBackgroundList
, &listItem
);
241 pData
->listViewItemCount
++;
244 if(!FindNextFile(hFind
, &fd
))
245 hFind
= INVALID_HANDLE_VALUE
;
248 token
= _tcstok(NULL
, separators
);
254 InitBackgroundDialog(HWND hwndDlg
, PDATA pData
)
259 DWORD bufferSize
= sizeof(szBuffer
);
260 DWORD varType
= REG_SZ
;
264 AddListViewItems(hwndDlg
, pData
);
266 LoadString(hApplet
, IDS_CENTER
, szString
, sizeof(szString
) / sizeof(TCHAR
));
267 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_INSERTSTRING
, PLACEMENT_CENTER
, (LPARAM
)szString
);
269 LoadString(hApplet
, IDS_STRETCH
, szString
, sizeof(szString
) / sizeof(TCHAR
));
270 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_INSERTSTRING
, PLACEMENT_STRETCH
, (LPARAM
)szString
);
272 LoadString(hApplet
, IDS_TILE
, szString
, sizeof(szString
) / sizeof(TCHAR
));
273 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_INSERTSTRING
, PLACEMENT_TILE
, (LPARAM
)szString
);
275 /* Load the default settings from the registry */
276 result
= RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, KEY_ALL_ACCESS
, ®Key
);
277 if (result
!= ERROR_SUCCESS
)
279 /* reg key open failed; maybe it does not exist? create it! */
280 DWORD dwDisposition
= 0;
281 result
= RegCreateKeyEx( HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
,
282 ®Key
, &dwDisposition
);
283 /* Now the key must be created & opened and regKey points to opened key */
284 /* On error result will not contain ERROR_SUCCESS. I don't know how to handle */
288 result
= RegQueryValueEx(regKey
, TEXT("WallpaperStyle"), 0, &varType
, (LPBYTE
)szBuffer
, &bufferSize
);
289 if (result
== ERROR_SUCCESS
)
291 if (_ttoi(szBuffer
) == 0)
293 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_CENTER
, 0);
294 pData
->placementSelection
= PLACEMENT_CENTER
;
297 if (_ttoi(szBuffer
) == 2)
299 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_STRETCH
, 0);
300 pData
->placementSelection
= PLACEMENT_STRETCH
;
305 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_CENTER
, 0);
306 pData
->placementSelection
= PLACEMENT_CENTER
;
309 result
= RegQueryValueEx(regKey
, TEXT("TileWallpaper"), 0, &varType
, (LPBYTE
)szBuffer
, &bufferSize
);
310 if (result
== ERROR_SUCCESS
)
312 if (_ttoi(szBuffer
) == 1)
314 SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_SETCURSEL
, PLACEMENT_TILE
, 0);
315 pData
->placementSelection
= PLACEMENT_TILE
;
321 pData
->hBitmap
= (HBITMAP
) LoadImage(hApplet
, MAKEINTRESOURCE(IDC_MONITOR
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
322 if (pData
->hBitmap
!= NULL
)
324 GetObject(pData
->hBitmap
, sizeof(BITMAP
), &bitmap
);
326 pData
->cxSource
= bitmap
.bmWidth
;
327 pData
->cySource
= bitmap
.bmHeight
;
333 OnColorButton(HWND hwndDlg
, PDATA pData
)
335 /* Load custom colors from Registry */
337 LONG res
= ERROR_SUCCESS
;
340 res
= RegCreateKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Appearance"), 0, NULL
, 0,
341 KEY_ALL_ACCESS
, NULL
, &hKey
, NULL
);
342 /* Now the key is either created or opened existing, if res == ERROR_SUCCESS */
343 if (res
== ERROR_SUCCESS
)
346 DWORD dwType
= REG_BINARY
;
347 DWORD cbData
= sizeof(pData
->custom_colors
);
348 res
= RegQueryValueEx(hKey
, TEXT("CustomColors"), NULL
, &dwType
,
349 (LPBYTE
)pData
->custom_colors
, &cbData
);
354 /* Launch ChooseColor() dialog */
356 cc
.lStructSize
= sizeof(CHOOSECOLOR
);
357 cc
.hwndOwner
= hwndDlg
;
359 cc
.rgbResult
= g_GlobalData
.desktop_color
;
360 cc
.lpCustColors
= pData
->custom_colors
;
361 cc
.Flags
= CC_ANYCOLOR
| /* Causes the dialog box to display all available colors in the set of basic colors. */
362 CC_FULLOPEN
| /* opens dialog in full size */
363 CC_RGBINIT
; /* init chosen color by rgbResult value */
366 cc
.lpTemplateName
= NULL
;
367 if (ChooseColor(&cc
))
369 /* Save selected color to var */
370 g_GlobalData
.desktop_color
= cc
.rgbResult
;
371 pData
->bClrBackgroundChanged
= TRUE
;
373 /* Apply button will be activated */
374 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
376 /* Window will be updated :) */
377 InvalidateRect(GetDlgItem(hwndDlg
, IDC_BACKGROUND_PREVIEW
), NULL
, TRUE
);
379 /* Save custom colors to reg. To this moment key must be created already. See above */
380 res
= RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Appearance"), 0,
382 if (res
== ERROR_SUCCESS
)
385 RegSetValueEx(hKey
, TEXT("CustomColors"), 0, REG_BINARY
,
386 (const BYTE
*)pData
->custom_colors
, sizeof(pData
->custom_colors
));
395 * ListView_FindItem() Macro: Searches for a list-view item with the specified
396 * characteristics. Returns the index of the item if successful, or -1 otherwise
399 CheckListViewFilenameExists(HWND hwndList
, LPCTSTR tszFileName
)
404 lvfi
.flags
= LVFI_STRING
; /* Search item by EXACT string */
405 lvfi
.psz
= tszFileName
; /* String to search */
407 /* Other items of this structure are not valid, besacuse flags are not set. */
408 retVal
= ListView_FindItem(hwndList
, -1, &lvfi
);
410 return TRUE
; /* item found! */
412 return FALSE
; /* item not found. */
417 OnBrowseButton(HWND hwndDlg
, PDATA pData
)
420 TCHAR filename
[MAX_PATH
];
421 TCHAR fileTitle
[256];
422 TCHAR filter
[MAX_PATH
];
423 BackgroundItem
*backgroundItem
= NULL
;
426 HWND hwndBackgroundList
;
429 hwndBackgroundList
= GetDlgItem(hwndDlg
, IDC_BACKGROUND_LIST
);
431 ZeroMemory(&ofn
, sizeof(OPENFILENAME
));
433 ofn
.lStructSize
= sizeof(OPENFILENAME
);
434 ofn
.hwndOwner
= hwndDlg
;
435 ofn
.lpstrFile
= filename
;
437 LoadString(hApplet
, IDS_BACKGROUND_COMDLG_FILTER
, filter
, sizeof(filter
) / sizeof(TCHAR
));
439 /* Set lpstrFile[0] to '\0' so that GetOpenFileName does not
440 * use the contents of szFile to initialize itself */
441 ofn
.lpstrFile
[0] = TEXT('\0');
442 ofn
.nMaxFile
= MAX_PATH
;
443 ofn
.lpstrFilter
= filter
;
444 ofn
.nFilterIndex
= 0;
445 ofn
.lpstrFileTitle
= fileTitle
;
446 ofn
.nMaxFileTitle
= 256;
447 ofn
.lpstrInitialDir
= NULL
;
448 ofn
.Flags
= OFN_PATHMUSTEXIST
| OFN_FILEMUSTEXIST
;
450 if (GetOpenFileName(&ofn
) == TRUE
)
452 /* Check if there is already a entry that holds this filename */
453 if (CheckListViewFilenameExists(hwndBackgroundList
, ofn
.lpstrFileTitle
) == TRUE
)
456 if (pData
->listViewItemCount
> (MAX_BACKGROUNDS
- 1))
459 SHGetFileInfo(filename
,
463 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_DISPLAYNAME
);
465 backgroundItem
= &pData
->backgroundItems
[pData
->listViewItemCount
];
467 backgroundItem
->bWallpaper
= TRUE
;
469 _tcscpy(backgroundItem
->szDisplayName
, sfi
.szDisplayName
);
470 p
= _tcsrchr(backgroundItem
->szDisplayName
, _T('.'));
473 _tcscpy(backgroundItem
->szFilename
, filename
);
475 ZeroMemory(&listItem
, sizeof(LV_ITEM
));
476 listItem
.mask
= LVIF_TEXT
| LVIF_PARAM
| LVIF_STATE
| LVIF_IMAGE
;
478 listItem
.pszText
= backgroundItem
->szDisplayName
;
479 listItem
.iImage
= sfi
.iIcon
;
480 listItem
.iItem
= pData
->listViewItemCount
;
481 listItem
.lParam
= pData
->listViewItemCount
;
483 (void)ListView_InsertItem(hwndBackgroundList
, &listItem
);
484 ListView_SetItemState(hwndBackgroundList
,
485 pData
->listViewItemCount
,
488 SendMessage(hwndBackgroundList
, WM_VSCROLL
, SB_BOTTOM
, 0);
490 pData
->listViewItemCount
++;
496 ListViewItemChanged(HWND hwndDlg
, PDATA pData
, int itemIndex
)
498 BackgroundItem
*backgroundItem
= NULL
;
500 pData
->backgroundSelection
= itemIndex
;
501 backgroundItem
= &pData
->backgroundItems
[pData
->backgroundSelection
];
503 if (pData
->pWallpaperBitmap
!= NULL
)
505 DibFreeImage(pData
->pWallpaperBitmap
);
506 pData
->pWallpaperBitmap
= NULL
;
509 if (backgroundItem
->bWallpaper
== TRUE
)
511 pData
->pWallpaperBitmap
= DibLoadImage(backgroundItem
->szFilename
);
513 if (pData
->pWallpaperBitmap
== NULL
)
517 pData
->bWallpaperChanged
= TRUE
;
519 InvalidateRect(GetDlgItem(hwndDlg
, IDC_BACKGROUND_PREVIEW
),
522 EnableWindow(GetDlgItem(hwndDlg
, IDC_PLACEMENT_COMBO
),
523 backgroundItem
->bWallpaper
);
525 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
530 DrawBackgroundPreview(LPDRAWITEMSTRUCT draw
, PDATA pData
)
550 hDC
= CreateCompatibleDC(draw
->hDC
);
551 hOldObj
= SelectObject(hDC
, pData
->hBitmap
);
553 if (pData
->backgroundItems
[pData
->backgroundSelection
].bWallpaper
== FALSE
)
555 /* Update desktop background color image */
556 hBrush
= CreateSolidBrush(g_GlobalData
.desktop_color
);
557 FillRect(hDC
, &rcItem
, hBrush
);
558 DeleteObject(hBrush
);
561 if (pData
->pWallpaperBitmap
!= NULL
)
563 scaleX
= ((float)GetSystemMetrics(SM_CXSCREEN
) - 1) / (float)MONITOR_WIDTH
;
564 scaleY
= ((float)GetSystemMetrics(SM_CYSCREEN
) - 1) / (float)MONITOR_HEIGHT
;
566 scaledWidth
= (int)(pData
->pWallpaperBitmap
->width
/ scaleX
);
567 scaledHeight
= (int)(pData
->pWallpaperBitmap
->height
/ scaleY
);
569 FillRect(hDC
, &rcItem
, GetSysColorBrush(COLOR_BACKGROUND
));
571 SetStretchBltMode(hDC
, COLORONCOLOR
);
573 switch (pData
->placementSelection
)
575 case PLACEMENT_CENTER
:
576 posX
= (MONITOR_WIDTH
- scaledWidth
+ 1) / 2;
577 posY
= (MONITOR_HEIGHT
- scaledHeight
+ 1) / 2;
581 if (posX
< 0) { desX
= -posX
/ 2; posX
= 0; }
582 if (posY
< 0) { desY
= -posY
/ 2; posY
= 0; }
584 if (scaledWidth
> MONITOR_WIDTH
)
585 scaledWidth
= MONITOR_WIDTH
;
587 if (scaledHeight
> MONITOR_HEIGHT
)
588 scaledHeight
= MONITOR_HEIGHT
;
597 pData
->pWallpaperBitmap
->width
- (int)(desX
* scaleX
),
598 pData
->pWallpaperBitmap
->height
- (int)(desY
* scaleY
),
599 pData
->pWallpaperBitmap
->bits
,
600 pData
->pWallpaperBitmap
->info
,
605 case PLACEMENT_STRETCH
:
613 pData
->pWallpaperBitmap
->width
,
614 pData
->pWallpaperBitmap
->height
,
615 pData
->pWallpaperBitmap
->bits
,
616 pData
->pWallpaperBitmap
->info
,
622 for (y
= 0; y
< MONITOR_HEIGHT
; y
+= scaledHeight
)
624 for (x
= 0; x
< MONITOR_WIDTH
; x
+= scaledWidth
)
626 if ((MONITOR_WIDTH
-x
) >= scaledWidth
)
629 posX
= MONITOR_WIDTH
-x
;
632 if ((MONITOR_HEIGHT
-y
) >= scaledHeight
)
635 posY
= MONITOR_HEIGHT
-y
;
644 pData
->pWallpaperBitmap
->width
* posX
/ scaledWidth
,
645 pData
->pWallpaperBitmap
->height
* posY
/ scaledHeight
,
646 pData
->pWallpaperBitmap
->bits
,
647 pData
->pWallpaperBitmap
->info
,
658 GdiTransparentBlt(draw
->hDC
,
659 draw
->rcItem
.left
, draw
->rcItem
.top
,
660 draw
->rcItem
.right
-draw
->rcItem
.left
+1,
661 draw
->rcItem
.bottom
-draw
->rcItem
.top
+1,
664 pData
->cxSource
, pData
->cySource
,
667 SelectObject(hDC
, hOldObj
);
673 SetWallpaper(PDATA pData
)
677 RegOpenKeyEx(HKEY_CURRENT_USER
, TEXT("Control Panel\\Desktop"), 0, KEY_ALL_ACCESS
, ®Key
);
679 if (pData
->placementSelection
== PLACEMENT_TILE
)
681 RegSetValueEx(regKey
, TEXT("TileWallpaper"), 0, REG_SZ
, (BYTE
*)TEXT("1"), sizeof(TCHAR
) * 2);
682 RegSetValueEx(regKey
, TEXT("WallpaperStyle"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
685 if (pData
->placementSelection
== PLACEMENT_CENTER
)
687 RegSetValueEx(regKey
, TEXT("TileWallpaper"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
688 RegSetValueEx(regKey
, TEXT("WallpaperStyle"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
691 if (pData
->placementSelection
== PLACEMENT_STRETCH
)
693 RegSetValueEx(regKey
, TEXT("TileWallpaper"), 0, REG_SZ
, (BYTE
*)TEXT("0"), sizeof(TCHAR
) * 2);
694 RegSetValueEx(regKey
, TEXT("WallpaperStyle"), 0, REG_SZ
, (BYTE
*)TEXT("2"), sizeof(TCHAR
) * 2);
699 if (pData
->backgroundItems
[pData
->backgroundSelection
].bWallpaper
== TRUE
)
701 SystemParametersInfo(SPI_SETDESKWALLPAPER
,
703 pData
->backgroundItems
[pData
->backgroundSelection
].szFilename
,
708 SystemParametersInfo(SPI_SETDESKWALLPAPER
, 0, (void*) TEXT(""), SPIF_UPDATEINIFILE
);
713 /* Change system color */
715 SetDesktopBackColor(HWND hwndDlg
, DATA
*pData
)
717 INT iElement
= COLOR_BACKGROUND
;
721 BYTE red
, green
, blue
;
724 if( !SetSysColors( 1, &iElement
, &g_GlobalData
.desktop_color
) )
725 MessageBox(hwndDlg
, TEXT("SetSysColor() failed!"), /* these error texts can need internationalization? */
726 TEXT("Error!"), MB_ICONSTOP
);
728 result
= RegCreateKeyEx( HKEY_CURRENT_USER
, TEXT("Control Panel\\Colors"), 0, NULL
, 0,
729 KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDispostion
);
730 if (result
!= ERROR_SUCCESS
)
732 red
= GetRValue(g_GlobalData
.desktop_color
);
733 green
= GetGValue(g_GlobalData
.desktop_color
);
734 blue
= GetBValue(g_GlobalData
.desktop_color
);
735 /* Format string to be set to registry */
736 wsprintf(clText
, TEXT("%d %d %d"), red
, green
, blue
);
737 RegSetValueEx(hKey
, TEXT("Background"), 0, REG_SZ
, (BYTE
*)clText
,
738 (lstrlen(clText
) + 1) * sizeof(TCHAR
));
744 BackgroundPageProc(HWND hwndDlg
,
751 pData
= (PDATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
756 pData
= (DATA
*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(DATA
));
757 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pData
);
758 InitBackgroundDialog(hwndDlg
, pData
);
763 DWORD controlId
= LOWORD(wParam
);
764 DWORD command
= HIWORD(wParam
);
768 case IDC_COLOR_BUTTON
:
769 if (command
== BN_CLICKED
)
770 OnColorButton(hwndDlg
, pData
);
773 case IDC_BROWSE_BUTTON
:
774 if (command
== BN_CLICKED
)
775 OnBrowseButton(hwndDlg
, pData
);
778 case IDC_PLACEMENT_COMBO
:
779 if (command
== CBN_SELCHANGE
)
781 pData
->placementSelection
= (int)SendDlgItemMessage(hwndDlg
, IDC_PLACEMENT_COMBO
, CB_GETCURSEL
, 0, 0);
783 InvalidateRect(GetDlgItem(hwndDlg
, IDC_BACKGROUND_PREVIEW
), NULL
, TRUE
);
785 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
793 LPDRAWITEMSTRUCT drawItem
;
794 drawItem
= (LPDRAWITEMSTRUCT
)lParam
;
796 if (drawItem
->CtlID
== IDC_BACKGROUND_PREVIEW
)
798 DrawBackgroundPreview(drawItem
, pData
);
806 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
811 if(pData
->bWallpaperChanged
)
813 if(pData
->bClrBackgroundChanged
)
814 SetDesktopBackColor(hwndDlg
, pData
);
815 SendMessage(HWND_BROADCAST
, WM_SETTINGCHANGE
, 0, (LPARAM
)_T(""));
818 case LVN_ITEMCHANGED
:
820 LPNMLISTVIEW nm
= (LPNMLISTVIEW
)lParam
;
822 if ((nm
->uNewState
& LVIS_SELECTED
) == 0)
825 ListViewItemChanged(hwndDlg
, pData
, nm
->iItem
);
833 if (pData
->pWallpaperBitmap
!= NULL
)
834 DibFreeImage(pData
->pWallpaperBitmap
);
836 DeleteObject(pData
->hBitmap
);
837 HeapFree(GetProcessHeap(), 0, pData
);