Author: ekohl
Date: Sun Nov 26 15:47:56 2006
New Revision: 24836
URL:
http://svn.reactos.org/svn/reactos?rev=24836&view=rev
Log:
- Move global variables into a struct that is attached to the property sheet page dialog.
- Remove trailing whitespace and tabs.
- Clean up the source code.
Modified:
trunk/reactos/dll/cpl/desk/appearance.c
trunk/reactos/dll/cpl/desk/background.c
trunk/reactos/dll/cpl/desk/de.rc
trunk/reactos/dll/cpl/desk/desk.c
trunk/reactos/dll/cpl/desk/desk.h
trunk/reactos/dll/cpl/desk/dibitmap.c
trunk/reactos/dll/cpl/desk/screensaver.c
Modified: trunk/reactos/dll/cpl/desk/appearance.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/desk/appearance.c?…
==============================================================================
--- trunk/reactos/dll/cpl/desk/appearance.c (original)
+++ trunk/reactos/dll/cpl/desk/appearance.c Sun Nov 26 15:47:56 2006
@@ -10,26 +10,25 @@
#include "desk.h"
-INT_PTR CALLBACK AppearancePageProc(HWND hwndDlg,
- UINT uMsg,
- WPARAM wParam,
- LPARAM lParam)
+INT_PTR CALLBACK
+AppearancePageProc(HWND hwndDlg,
+ UINT uMsg,
+ WPARAM wParam,
+ LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
UNREFERENCED_PARAMETER(wParam);
UNREFERENCED_PARAMETER(hwndDlg);
- switch(uMsg)
+ switch (uMsg)
{
case WM_INITDIALOG:
- {
- } break;
-
+ break;
+
case WM_COMMAND:
- {
- } break;
+ break;
}
-
+
return FALSE;
}
Modified: trunk/reactos/dll/cpl/desk/background.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/desk/background.c?…
==============================================================================
--- trunk/reactos/dll/cpl/desk/background.c (original)
+++ trunk/reactos/dll/cpl/desk/background.c Sun Nov 26 15:47:56 2006
@@ -20,40 +20,36 @@
typedef struct
{
BOOL bWallpaper; /* Is this background a wallpaper */
-
+
TCHAR szFilename[MAX_PATH];
TCHAR szDisplayName[256];
-
+
} BackgroundItem;
-BackgroundItem g_backgroundItems[MAX_BACKGROUNDS];
-
-DIBitmap *g_pWallpaperBitmap = NULL;
-
-int g_placementSelection = 0;
-int g_backgroundSelection = 0;
-
-/* this holds current selection of background color */
-COLORREF g_backgroundDesktopColor = 0;
-/* this holds selection of custom colors in dialog box */
-COLORREF custom_colors[16] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
-
-int g_listViewItemCount = 0;
-
-HWND g_hBackgroundPage = NULL;
-HWND g_hBackgroundList = NULL;
-HWND g_hBackgroundPreview = NULL;
-
-HWND g_hPlacementCombo = NULL;
-HWND g_hColorButton = NULL;
-
-HIMAGELIST g_hShellImageList = NULL;
-
-static HBITMAP hBitmap = NULL;
-static int cxSource, cySource;
+typedef struct _GLOBAL_DATA
+{
+ BackgroundItem backgroundItems[MAX_BACKGROUNDS];
+
+ PDIBITMAP pWallpaperBitmap;
+
+ int placementSelection;
+ int backgroundSelection;
+
+ COLORREF backgroundDesktopColor;
+ COLORREF custom_colors[16];
+
+ int listViewItemCount;
+
+ HBITMAP hBitmap;
+ int cxSource;
+ int cySource;
+} GLOBAL_DATA, *PGLOBAL_DATA;
+
+
/* Add the images in the C:\ReactOS directory and the current wallpaper if any */
-void AddListViewItems()
+static VOID
+AddListViewItems(HWND hwndDlg, PGLOBAL_DATA pGlobalData)
{
WIN32_FIND_DATA fd;
HANDLE hFind;
@@ -73,42 +69,45 @@
BackgroundItem *backgroundItem = NULL;
TCHAR separators[] = TEXT(";");
TCHAR *token;
-
- GetClientRect(g_hBackgroundList, &clientRect);
-
+ HWND hwndBackgroundList;
+
+ hwndBackgroundList = GetDlgItem(hwndDlg, IDC_BACKGROUND_LIST);
+
+ GetClientRect(hwndBackgroundList, &clientRect);
+
+ /* Add a new column to the list */
ZeroMemory(&dummy, sizeof(LV_COLUMN));
dummy.mask = LVCF_SUBITEM | LVCF_WIDTH;
dummy.iSubItem = 0;
dummy.cx = (clientRect.right - clientRect.left) -
GetSystemMetrics(SM_CXVSCROLL);
-
- (void)ListView_InsertColumn(g_hBackgroundList, 0, &dummy);
-
+ ListView_InsertColumn(hwndBackgroundList, 0, &dummy);
+
/* Add the "None" item */
- backgroundItem = &g_backgroundItems[g_listViewItemCount];
+ backgroundItem =
&pGlobalData->backgroundItems[pGlobalData->listViewItemCount];
backgroundItem->bWallpaper = FALSE;
LoadString(hApplet,
IDS_NONE,
backgroundItem->szDisplayName,
sizeof(backgroundItem->szDisplayName) / sizeof(TCHAR));
-
+
ZeroMemory(&listItem, sizeof(LV_ITEM));
listItem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
listItem.state = LVIS_SELECTED;
listItem.pszText = backgroundItem->szDisplayName;
listItem.iImage = -1;
- listItem.iItem = g_listViewItemCount;
- listItem.lParam = g_listViewItemCount;
-
- (void)ListView_InsertItem(g_hBackgroundList, &listItem);
- ListView_SetItemState(g_hBackgroundList, g_listViewItemCount, LVIS_SELECTED,
LVIS_SELECTED);
-
- g_listViewItemCount++;
+ listItem.iItem = pGlobalData->listViewItemCount;
+ listItem.lParam = pGlobalData->listViewItemCount;
+
+ ListView_InsertItem(hwndBackgroundList, &listItem);
+ ListView_SetItemState(hwndBackgroundList, pGlobalData->listViewItemCount,
LVIS_SELECTED, LVIS_SELECTED);
+
+ pGlobalData->listViewItemCount++;
/* Add current wallpaper if any */
RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0,
KEY_ALL_ACCESS, ®Key);
+
result = RegQueryValueEx(regKey, TEXT("Wallpaper"), 0, &varType,
(LPBYTE)wallpaperFilename, &bufferSize);
-
- if((result == ERROR_SUCCESS) && (_tcslen(wallpaperFilename) > 0))
+ if ((result == ERROR_SUCCESS) && (_tcslen(wallpaperFilename) > 0))
{
himl = (HIMAGELIST)SHGetFileInfo(wallpaperFilename,
0,
@@ -117,16 +116,15 @@
SHGFI_SYSICONINDEX | SHGFI_SMALLICON |
SHGFI_DISPLAYNAME);
- if(himl != NULL)
+ if (himl != NULL)
{
- if(i++ == 0)
+ if (i++ == 0)
{
- g_hShellImageList = himl;
- (void)ListView_SetImageList(g_hBackgroundList, himl, LVSIL_SMALL);
+ ListView_SetImageList(hwndBackgroundList, himl, LVSIL_SMALL);
}
- backgroundItem = &g_backgroundItems[g_listViewItemCount];
-
+ backgroundItem =
&pGlobalData->backgroundItems[pGlobalData->listViewItemCount];
+
backgroundItem->bWallpaper = TRUE;
_tcscpy(backgroundItem->szDisplayName, sfi.szDisplayName);
@@ -137,43 +135,42 @@
listItem.state = LVIS_SELECTED;
listItem.pszText = backgroundItem->szDisplayName;
listItem.iImage = sfi.iIcon;
- listItem.iItem = g_listViewItemCount;
- listItem.lParam = g_listViewItemCount;
-
- (void)ListView_InsertItem(g_hBackgroundList, &listItem);
- ListView_SetItemState(g_hBackgroundList, g_listViewItemCount, LVIS_SELECTED,
LVIS_SELECTED);
-
- g_listViewItemCount++;
+ listItem.iItem = pGlobalData->listViewItemCount;
+ listItem.lParam = pGlobalData->listViewItemCount;
+
+ ListView_InsertItem(hwndBackgroundList, &listItem);
+ ListView_SetItemState(hwndBackgroundList, pGlobalData->listViewItemCount,
LVIS_SELECTED, LVIS_SELECTED);
+
+ pGlobalData->listViewItemCount++;
}
}
-
+
RegCloseKey(regKey);
/* Add all the images in the C:\ReactOS directory. */
LoadString(hApplet, IDS_SUPPORTED_EXT, szFileTypes, sizeof(szFileTypes) /
sizeof(TCHAR));
-
-
- token = _tcstok ( szFileTypes, separators );
- while ( token != NULL )
+
+ token = _tcstok(szFileTypes, separators);
+ while (token != NULL)
{
GetWindowsDirectory(szSearchPath, MAX_PATH);
_tcscat(szSearchPath, TEXT("\\"));
_tcscat(szSearchPath, token);
-
+
hFind = FindFirstFile(szSearchPath, &fd);
- while(hFind != INVALID_HANDLE_VALUE)
+ while (hFind != INVALID_HANDLE_VALUE)
{
/* Don't add any hidden bitmaps */
- if((fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == 0)
+ if ((fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == 0)
{
TCHAR filename[MAX_PATH];
-
+
GetWindowsDirectory(filename, MAX_PATH);
_tcscat(filename, TEXT("\\"));
_tcscat(filename, fd.cFileName);
-
+
himl = (HIMAGELIST)SHGetFileInfo(filename,
0,
&sfi,
@@ -181,18 +178,18 @@
SHGFI_SYSICONINDEX | SHGFI_SMALLICON |
SHGFI_DISPLAYNAME);
- if(himl == NULL) break;
-
- if(i++ == 0)
+ if (himl == NULL)
+ break;
+
+ if (i++ == 0)
{
- g_hShellImageList = himl;
- (void)ListView_SetImageList(g_hBackgroundList, himl, LVSIL_SMALL);
+ ListView_SetImageList(hwndBackgroundList, himl, LVSIL_SMALL);
}
- backgroundItem = &g_backgroundItems[g_listViewItemCount];
+ backgroundItem =
&pGlobalData->backgroundItems[pGlobalData->listViewItemCount];
backgroundItem->bWallpaper = TRUE;
-
+
_tcscpy(backgroundItem->szDisplayName, sfi.szDisplayName);
_tcscpy(backgroundItem->szFilename, filename);
@@ -201,23 +198,25 @@
listItem.pszText = backgroundItem->szDisplayName;
listItem.state = 0;
listItem.iImage = sfi.iIcon;
- listItem.iItem = g_listViewItemCount;
- listItem.lParam = g_listViewItemCount;
-
- (void)ListView_InsertItem(g_hBackgroundList, &listItem);
-
- g_listViewItemCount++;
+ listItem.iItem = pGlobalData->listViewItemCount;
+ listItem.lParam = pGlobalData->listViewItemCount;
+
+ ListView_InsertItem(hwndBackgroundList, &listItem);
+
+ pGlobalData->listViewItemCount++;
}
-
+
if(!FindNextFile(hFind, &fd))
hFind = INVALID_HANDLE_VALUE;
}
- token = _tcstok ( NULL, separators );
- }
-}
-
-void InitBackgroundDialog()
+ token = _tcstok(NULL, separators);
+ }
+}
+
+
+static VOID
+InitBackgroundDialog(HWND hwndDlg, PGLOBAL_DATA pGlobalData)
{
TCHAR szString[256];
HKEY regKey;
@@ -226,27 +225,23 @@
DWORD varType = REG_SZ;
LONG result;
BITMAP bitmap;
-
- g_backgroundDesktopColor = GetSysColor( COLOR_BACKGROUND );
- g_hBackgroundList = GetDlgItem(g_hBackgroundPage, IDC_BACKGROUND_LIST);
- g_hBackgroundPreview = GetDlgItem(g_hBackgroundPage, IDC_BACKGROUND_PREVIEW);
- g_hPlacementCombo = GetDlgItem(g_hBackgroundPage, IDC_PLACEMENT_COMBO);
- g_hColorButton = GetDlgItem(g_hBackgroundPage, IDC_COLOR_BUTTON);
-
- AddListViewItems();
-
+
+ pGlobalData->backgroundDesktopColor = GetSysColor(COLOR_BACKGROUND);
+
+ AddListViewItems(hwndDlg, pGlobalData);
+
LoadString(hApplet, IDS_CENTER, szString, sizeof(szString) / sizeof(TCHAR));
- SendMessage(g_hPlacementCombo, CB_INSERTSTRING, PLACEMENT_CENTER, (LPARAM)szString);
+ SendDlgItemMessage(hwndDlg, IDC_PLACEMENT_COMBO, CB_INSERTSTRING, PLACEMENT_CENTER,
(LPARAM)szString);
LoadString(hApplet, IDS_STRETCH, szString, sizeof(szString) / sizeof(TCHAR));
- SendMessage(g_hPlacementCombo, CB_INSERTSTRING, PLACEMENT_STRETCH,
(LPARAM)szString);
+ SendDlgItemMessage(hwndDlg, IDC_PLACEMENT_COMBO, CB_INSERTSTRING, PLACEMENT_STRETCH,
(LPARAM)szString);
LoadString(hApplet, IDS_TILE, szString, sizeof(szString) / sizeof(TCHAR));
- SendMessage(g_hPlacementCombo, CB_INSERTSTRING, PLACEMENT_TILE, (LPARAM)szString);
+ SendDlgItemMessage(hwndDlg, IDC_PLACEMENT_COMBO, CB_INSERTSTRING, PLACEMENT_TILE,
(LPARAM)szString);
/* Load the default settings from the registry */
result = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0,
KEY_ALL_ACCESS, ®Key);
- if( result != ERROR_SUCCESS )
+ if (result != ERROR_SUCCESS)
{
/* reg key open failed; maybe it does not exist? create it! */
DWORD dwDisposition = 0;
@@ -256,122 +251,136 @@
/* On error result will not contain ERROR_SUCCESS. I don't know how to handle
*/
/* this case :( */
}
-
+
result = RegQueryValueEx(regKey, TEXT("WallpaperStyle"), 0, &varType,
(LPBYTE)szBuffer, &bufferSize);
-
- if(result == ERROR_SUCCESS)
- {
- if(_ttoi(szBuffer) == 0)
+ if (result == ERROR_SUCCESS)
+ {
+ if (_ttoi(szBuffer) == 0)
{
- SendMessage(g_hPlacementCombo, CB_SETCURSEL, PLACEMENT_CENTER, 0);
- g_placementSelection = PLACEMENT_CENTER;
+ SendDlgItemMessage(hwndDlg, IDC_PLACEMENT_COMBO, CB_SETCURSEL,
PLACEMENT_CENTER, 0);
+ pGlobalData->placementSelection = PLACEMENT_CENTER;
}
- if(_ttoi(szBuffer) == 2)
+ if (_ttoi(szBuffer) == 2)
{
- SendMessage(g_hPlacementCombo, CB_SETCURSEL, PLACEMENT_STRETCH, 0);
- g_placementSelection = PLACEMENT_STRETCH;
+ SendDlgItemMessage(hwndDlg, IDC_PLACEMENT_COMBO, CB_SETCURSEL,
PLACEMENT_STRETCH, 0);
+ pGlobalData->placementSelection = PLACEMENT_STRETCH;
}
}
else
{
- SendMessage(g_hPlacementCombo, CB_SETCURSEL, PLACEMENT_CENTER, 0);
- g_placementSelection = PLACEMENT_CENTER;
- }
-
+ SendDlgItemMessage(hwndDlg, IDC_PLACEMENT_COMBO, CB_SETCURSEL, PLACEMENT_CENTER,
0);
+ pGlobalData->placementSelection = PLACEMENT_CENTER;
+ }
+
result = RegQueryValueEx(regKey, TEXT("TileWallpaper"), 0, &varType,
(LPBYTE)szBuffer, &bufferSize);
-
- if(result == ERROR_SUCCESS)
- {
- if(_ttoi(szBuffer) == 1)
+ if (result == ERROR_SUCCESS)
+ {
+ if (_ttoi(szBuffer) == 1)
{
- SendMessage(g_hPlacementCombo, CB_SETCURSEL, PLACEMENT_TILE, 0);
- g_placementSelection = PLACEMENT_TILE;
+ SendDlgItemMessage(hwndDlg, IDC_PLACEMENT_COMBO, CB_SETCURSEL,
PLACEMENT_TILE, 0);
+ pGlobalData->placementSelection = PLACEMENT_TILE;
}
}
RegCloseKey(regKey);
- hBitmap = LoadImage(hApplet, MAKEINTRESOURCE(IDC_MONITOR), IMAGE_BITMAP, 0, 0,
LR_LOADTRANSPARENT);
- if (hBitmap != NULL)
- {
- GetObject(hBitmap, sizeof(BITMAP), &bitmap);
-
- cxSource = bitmap.bmWidth;
- cySource = bitmap.bmHeight;
- }
-}
-
-void OnColorButton()
+ pGlobalData->hBitmap = LoadImage(hApplet, MAKEINTRESOURCE(IDC_MONITOR),
IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
+ if (pGlobalData->hBitmap != NULL)
+ {
+ GetObject(pGlobalData->hBitmap, sizeof(BITMAP), &bitmap);
+
+ pGlobalData->cxSource = bitmap.bmWidth;
+ pGlobalData->cySource = bitmap.bmHeight;
+ }
+}
+
+
+static VOID
+OnColorButton(HWND hwndDlg, PGLOBAL_DATA pGlobalData)
{
/* Load custom colors from Registry */
HKEY hKey = NULL;
LONG res = ERROR_SUCCESS;
CHOOSECOLOR cc;
- res = RegCreateKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance"),
0, NULL, 0,
- KEY_ALL_ACCESS, NULL, &hKey, NULL );
+
+ res = RegCreateKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Appearance"),
0, NULL, 0,
+ KEY_ALL_ACCESS, NULL, &hKey, NULL);
/* Now the key is either created or opened existing, if res == ERROR_SUCCESS */
- if( res == ERROR_SUCCESS )
+ if (res == ERROR_SUCCESS)
{
/* Key opened */
DWORD dwType = REG_BINARY;
- DWORD cbData = sizeof(custom_colors);
- res = RegQueryValueEx( hKey, TEXT("CustomColors"), NULL, &dwType,
- (LPBYTE)custom_colors, &cbData );
- RegCloseKey( hKey );
+ DWORD cbData = sizeof(pGlobalData->custom_colors);
+ res = RegQueryValueEx(hKey, TEXT("CustomColors"), NULL, &dwType,
+ (LPBYTE)pGlobalData->custom_colors, &cbData);
+ RegCloseKey(hKey);
hKey = NULL;
}
-
+
/* Launch ChooseColor() dialog */
cc.lStructSize = sizeof(CHOOSECOLOR);
- cc.hwndOwner = g_hBackgroundPage;
+ cc.hwndOwner = hwndDlg;
cc.hInstance = NULL;
- cc.rgbResult = g_backgroundDesktopColor;
- cc.lpCustColors = custom_colors;
+ cc.rgbResult = pGlobalData->backgroundDesktopColor;
+ cc.lpCustColors = pGlobalData->custom_colors;
cc.Flags = CC_ANYCOLOR | /* Causes the dialog box to display all available colors in
the set of basic colors. */
CC_FULLOPEN | /* opens dialog in full size */
CC_RGBINIT ; /* init chosen color by rgbResult value */
cc.lCustData = 0;
cc.lpfnHook = NULL;
cc.lpTemplateName = NULL;
- if( ChooseColor( &cc ) )
+ if (ChooseColor(&cc))
{
/* Save selected color to var */
- g_backgroundDesktopColor = cc.rgbResult;
+ pGlobalData->backgroundDesktopColor = cc.rgbResult;
+
/* Allpy buuton will be activated */
- PropSheet_Changed( GetParent( g_hBackgroundPage ), g_hBackgroundPage );
+ PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+
/* Window will be updated :) */
- InvalidateRect(g_hBackgroundPreview, NULL, TRUE);
+ InvalidateRect(GetDlgItem(hwndDlg, IDC_BACKGROUND_PREVIEW), NULL, TRUE);
+
/* Save custom colors to reg. To this moment key must be ceated already. See
above */
- res = RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Control
Panel\\Appearance"), 0,
- KEY_WRITE, &hKey );
- if( res == ERROR_SUCCESS )
+ res = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control
Panel\\Appearance"), 0,
+ KEY_WRITE, &hKey);
+ if (res == ERROR_SUCCESS)
{
/* Key opened */
- RegSetValueEx( hKey, TEXT("CustomColors"), 0, REG_BINARY,
- (const BYTE *)custom_colors, sizeof(custom_colors) );
- RegCloseKey( hKey );
+ RegSetValueEx(hKey, TEXT("CustomColors"), 0, REG_BINARY,
+ (const BYTE *)pGlobalData->custom_colors,
sizeof(pGlobalData->custom_colors));
+ RegCloseKey(hKey);
hKey = NULL;
}
}
}
-BOOL CheckListViewFilenameExists(HWND hWndList, LPCTSTR tszFileName)
-{
- /* ListView_FindItem() Macro: Searches for a list-view item with the specified *
- * characteristics. Returns the index of the item if successful, or -1 otherwise */
+
+/*
+ * ListView_FindItem() Macro: Searches for a list-view item with the specified
+ * characteristics. Returns the index of the item if successful, or -1 otherwise
+ */
+static BOOL
+CheckListViewFilenameExists(HWND hwndList, LPCTSTR tszFileName)
+{
LVFINDINFO lvfi;
int retVal;
+
lvfi.flags = LVFI_STRING; /* search item by EXACT string */
lvfi.psz = tszFileName; /* string to search */
+
/* other items of this structure are not valid, besacuse flags are not set. */
- retVal = ListView_FindItem( hWndList, -1, &lvfi );
- if( retVal != -1 ) return TRUE; /* item found! */
+ retVal = ListView_FindItem(hwndList, -1, &lvfi);
+ if (retVal != -1)
+ return TRUE; /* item found! */
+
return FALSE; /* item not found. */
}
-void OnBrowseButton()
+
+static VOID
+OnBrowseButton(HWND hwndDlg, PGLOBAL_DATA pGlobalData)
{
OPENFILENAME ofn;
TCHAR filename[MAX_PATH];
@@ -380,11 +389,14 @@
BackgroundItem *backgroundItem = NULL;
SHFILEINFO sfi;
LV_ITEM listItem;
+ HWND hwndBackgroundList;
+
+ hwndBackgroundList = GetDlgItem(hwndDlg, IDC_BACKGROUND_LIST);
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
- ofn.hwndOwner = g_hBackgroundPage;
+ ofn.hwndOwner = hwndDlg;
ofn.lpstrFile = filename;
LoadString(hApplet, IDS_BACKGROUND_COMDLG_FILTER, filter, sizeof(filter) /
sizeof(TCHAR));
@@ -400,74 +412,79 @@
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
- if(GetOpenFileName(&ofn) == TRUE)
+ if (GetOpenFileName(&ofn) == TRUE)
{
/* Check if there is already a entry that holds this filename */
- if(CheckListViewFilenameExists(g_hBackgroundList, ofn.lpstrFileTitle) == TRUE)
+ if (CheckListViewFilenameExists(hwndBackgroundList, ofn.lpstrFileTitle) == TRUE)
return;
-
- if(g_listViewItemCount > (MAX_BACKGROUNDS - 1))
+
+ if (pGlobalData->listViewItemCount > (MAX_BACKGROUNDS - 1))
return;
-
+
SHGetFileInfo(filename,
0,
&sfi,
sizeof(sfi),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_DISPLAYNAME);
-
- backgroundItem = &g_backgroundItems[g_listViewItemCount];
-
+
+ backgroundItem =
&pGlobalData->backgroundItems[pGlobalData->listViewItemCount];
+
backgroundItem->bWallpaper = TRUE;
-
+
_tcscpy(backgroundItem->szDisplayName, sfi.szDisplayName);
_tcscpy(backgroundItem->szFilename, filename);
-
+
ZeroMemory(&listItem, sizeof(LV_ITEM));
listItem.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
listItem.state = 0;
listItem.pszText = backgroundItem->szDisplayName;
listItem.iImage = sfi.iIcon;
- listItem.iItem = g_listViewItemCount;
- listItem.lParam = g_listViewItemCount;
-
- (void)ListView_InsertItem(g_hBackgroundList, &listItem);
-
- g_listViewItemCount++;
- }
-}
-
-void ListViewItemChanged(int itemIndex)
+ listItem.iItem = pGlobalData->listViewItemCount;
+ listItem.lParam = pGlobalData->listViewItemCount;
+
+ ListView_InsertItem(hwndBackgroundList, &listItem);
+
+ pGlobalData->listViewItemCount++;
+ }
+}
+
+
+static VOID
+ListViewItemChanged(HWND hwndDlg, PGLOBAL_DATA pGlobalData, int itemIndex)
{
BackgroundItem *backgroundItem = NULL;
-
- g_backgroundSelection = itemIndex;
- backgroundItem = &g_backgroundItems[g_backgroundSelection];
-
- if(g_pWallpaperBitmap != NULL)
- {
- DibFreeImage(g_pWallpaperBitmap);
- g_pWallpaperBitmap = NULL;
- }
-
- if(backgroundItem->bWallpaper == TRUE)
- {
- g_pWallpaperBitmap = DibLoadImage(backgroundItem->szFilename);
-
- if(g_pWallpaperBitmap == NULL)
- {
+
+ pGlobalData->backgroundSelection = itemIndex;
+ backgroundItem =
&pGlobalData->backgroundItems[pGlobalData->backgroundSelection];
+
+ if (pGlobalData->pWallpaperBitmap != NULL)
+ {
+ DibFreeImage(pGlobalData->pWallpaperBitmap);
+ pGlobalData->pWallpaperBitmap = NULL;
+ }
+
+ if (backgroundItem->bWallpaper == TRUE)
+ {
+ pGlobalData->pWallpaperBitmap = DibLoadImage(backgroundItem->szFilename);
+
+ if (pGlobalData->pWallpaperBitmap == NULL)
return;
- }
- }
-
- InvalidateRect(g_hBackgroundPreview, NULL, TRUE);
-
- EnableWindow(g_hColorButton, (backgroundItem->bWallpaper == FALSE ? TRUE :
FALSE));
- EnableWindow(g_hPlacementCombo, backgroundItem->bWallpaper);
-
- PropSheet_Changed(GetParent(g_hBackgroundPage), g_hBackgroundPage);
-}
-
-void DrawBackgroundPreview(LPDRAWITEMSTRUCT draw)
+ }
+
+ InvalidateRect(GetDlgItem(hwndDlg, IDC_BACKGROUND_PREVIEW),
+ NULL, TRUE);
+
+ EnableWindow(GetDlgItem(hwndDlg, IDC_COLOR_BUTTON),
+ (backgroundItem->bWallpaper == FALSE ? TRUE : FALSE));
+ EnableWindow(GetDlgItem(hwndDlg, IDC_PLACEMENT_COMBO),
+ backgroundItem->bWallpaper);
+
+ PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+}
+
+
+static VOID
+DrawBackgroundPreview(LPDRAWITEMSTRUCT draw, PGLOBAL_DATA pGlobalData)
{
float scaleX;
float scaleY;
@@ -475,143 +492,147 @@
int scaledHeight;
int posX;
int posY;
-
- if(g_backgroundItems[g_backgroundSelection].bWallpaper == FALSE)
+ HBRUSH hBrush;
+ int x;
+ int y;
+
+ if (pGlobalData->backgroundItems[pGlobalData->backgroundSelection].bWallpaper
== FALSE)
{
/* update desktop background color image */
- HBRUSH hBrush = CreateSolidBrush( g_backgroundDesktopColor );
- FillRect(draw->hDC, &draw->rcItem, hBrush );
- DeleteObject( hBrush );
+ hBrush = CreateSolidBrush(pGlobalData->backgroundDesktopColor);
+ FillRect(draw->hDC, &draw->rcItem, hBrush);
+ DeleteObject(hBrush);
return;
}
-
- if(g_pWallpaperBitmap == NULL)
+
+ if (pGlobalData->pWallpaperBitmap == NULL)
return;
scaleX = ((float)GetSystemMetrics(SM_CXSCREEN) - 1) / (float)draw->rcItem.right;
scaleY = ((float)GetSystemMetrics(SM_CYSCREEN) - 1) / (float)draw->rcItem.bottom;
- scaledWidth = g_pWallpaperBitmap->width / scaleX;
- scaledHeight = g_pWallpaperBitmap->height / scaleY;
-
+ scaledWidth = pGlobalData->pWallpaperBitmap->width / scaleX;
+ scaledHeight = pGlobalData->pWallpaperBitmap->height / scaleY;
+
posX = (draw->rcItem.right / 2) - (scaledWidth / 2);
posY = (draw->rcItem.bottom / 2) - (scaledHeight / 2);
-
+
FillRect(draw->hDC, &draw->rcItem, GetSysColorBrush(COLOR_BACKGROUND));
-
+
SetStretchBltMode(draw->hDC, COLORONCOLOR);
-
- if(g_placementSelection == PLACEMENT_CENTER)
- {
- StretchDIBits(draw->hDC,
- posX,
- posY,
- scaledWidth,
- scaledHeight,
- 0,
- 0,
- g_pWallpaperBitmap->width,
- g_pWallpaperBitmap->height,
- g_pWallpaperBitmap->bits,
- g_pWallpaperBitmap->info,
- DIB_RGB_COLORS,
- SRCCOPY);
- }
-
- if(g_placementSelection == PLACEMENT_STRETCH)
- {
- StretchDIBits(draw->hDC,
- 0,
- 0,
- draw->rcItem.right,
- draw->rcItem.bottom,
- 0,
- 0,
- g_pWallpaperBitmap->width,
- g_pWallpaperBitmap->height,
- g_pWallpaperBitmap->bits,
- g_pWallpaperBitmap->info,
- DIB_RGB_COLORS,
- SRCCOPY);
- }
-
- if(g_placementSelection == PLACEMENT_TILE)
- {
- int x;
- int y;
-
- for(y = 0; y < draw->rcItem.bottom; y += scaledHeight)
- {
- for(x = 0; x < draw->rcItem.right; x += scaledWidth)
+
+ switch (pGlobalData->placementSelection)
+ {
+ case PLACEMENT_CENTER:
+ StretchDIBits(draw->hDC,
+ posX,
+ posY,
+ scaledWidth,
+ scaledHeight,
+ 0,
+ 0,
+ pGlobalData->pWallpaperBitmap->width,
+ pGlobalData->pWallpaperBitmap->height,
+ pGlobalData->pWallpaperBitmap->bits,
+ pGlobalData->pWallpaperBitmap->info,
+ DIB_RGB_COLORS,
+ SRCCOPY);
+ break;
+
+ case PLACEMENT_STRETCH:
+ StretchDIBits(draw->hDC,
+ 0,
+ 0,
+ draw->rcItem.right,
+ draw->rcItem.bottom,
+ 0,
+ 0,
+ pGlobalData->pWallpaperBitmap->width,
+ pGlobalData->pWallpaperBitmap->height,
+ pGlobalData->pWallpaperBitmap->bits,
+ pGlobalData->pWallpaperBitmap->info,
+ DIB_RGB_COLORS,
+ SRCCOPY);
+ break;
+
+ case PLACEMENT_TILE:
+ for (y = 0; y < draw->rcItem.bottom; y += scaledHeight)
{
- StretchDIBits(draw->hDC,
- x,
- y,
- scaledWidth,
- scaledHeight,
- 0,
- 0,
- g_pWallpaperBitmap->width,
- g_pWallpaperBitmap->height,
- g_pWallpaperBitmap->bits,
- g_pWallpaperBitmap->info,
- DIB_RGB_COLORS,
- SRCCOPY);
+ for (x = 0; x < draw->rcItem.right; x += scaledWidth)
+ {
+ StretchDIBits(draw->hDC,
+ x,
+ y,
+ scaledWidth,
+ scaledHeight,
+ 0,
+ 0,
+ pGlobalData->pWallpaperBitmap->width,
+ pGlobalData->pWallpaperBitmap->height,
+ pGlobalData->pWallpaperBitmap->bits,
+ pGlobalData->pWallpaperBitmap->info,
+ DIB_RGB_COLORS,
+ SRCCOPY);
+ }
}
- }
- }
-}
-
-void SetWallpaper()
+ break;
+ }
+}
+
+
+static VOID
+SetWallpaper(PGLOBAL_DATA pGlobalData)
{
HKEY regKey;
-
+
RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0,
KEY_ALL_ACCESS, ®Key);
- if(g_placementSelection == PLACEMENT_TILE)
+ if (pGlobalData->placementSelection == PLACEMENT_TILE)
{
RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (BYTE
*)TEXT("1"), sizeof(TCHAR) * 2);
RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (BYTE
*)TEXT("0"), sizeof(TCHAR) * 2);
}
-
- if(g_placementSelection == PLACEMENT_CENTER)
+
+ if (pGlobalData->placementSelection == PLACEMENT_CENTER)
{
RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (BYTE
*)TEXT("0"), sizeof(TCHAR) * 2);
RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (BYTE
*)TEXT("0"), sizeof(TCHAR) * 2);
}
- if(g_placementSelection == PLACEMENT_STRETCH)
+ if (pGlobalData->placementSelection == PLACEMENT_STRETCH)
{
RegSetValueEx(regKey, TEXT("TileWallpaper"), 0, REG_SZ, (BYTE
*)TEXT("0"), sizeof(TCHAR) * 2);
RegSetValueEx(regKey, TEXT("WallpaperStyle"), 0, REG_SZ, (BYTE
*)TEXT("2"), sizeof(TCHAR) * 2);
}
-
+
RegCloseKey(regKey);
-
- if(g_backgroundItems[g_backgroundSelection].bWallpaper == TRUE)
+
+ if (pGlobalData->backgroundItems[pGlobalData->backgroundSelection].bWallpaper
== TRUE)
{
SystemParametersInfo(SPI_SETDESKWALLPAPER,
0,
- g_backgroundItems[g_backgroundSelection].szFilename,
+
pGlobalData->backgroundItems[pGlobalData->backgroundSelection].szFilename,
SPIF_UPDATEINIFILE);
}
else
- {
+ {
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, TEXT(""),
SPIF_UPDATEINIFILE);
}
}
-void SetDesktopBackColor()
-{
- /* Change system color */
+
+/* Change system color */
+static VOID
+SetDesktopBackColor(HWND hwndDlg, PGLOBAL_DATA pGlobalData)
+{
INT iElement = COLOR_BACKGROUND;
- HKEY hKey;
- LONG result;
+ HKEY hKey;
+ LONG result;
TCHAR clText[16];
- DWORD red, green, blue;
-
- if( !SetSysColors( 1, &iElement, &g_backgroundDesktopColor ) )
- MessageBox( g_hBackgroundPage, TEXT("SetSysColor() failed!"), /* these
error texts can need internationalization? */
+ DWORD red, green, blue;
+
+ if( !SetSysColors( 1, &iElement, &pGlobalData->backgroundDesktopColor ) )
+ MessageBox(hwndDlg, TEXT("SetSysColor() failed!"), /* these error texts
can need internationalization? */
TEXT("Error!"), MB_ICONSTOP );
/* Write color to registry key: HKEY_CURRENT_USER\Control Panel\Colors\Background */
hKey = NULL;
@@ -626,61 +647,60 @@
/* On error result will not contain ERROR_SUCCESS. I don't know how to handle
*/
/* this case :( */
}
- red = GetRValue( g_backgroundDesktopColor );
- green = GetGValue( g_backgroundDesktopColor );
- blue = GetBValue( g_backgroundDesktopColor );
- _stprintf( clText, TEXT("%d %d %d"), red, green, blue ); /* format string
to be set to registry */
- RegSetValueEx( hKey, TEXT("Background"), 0, REG_SZ, (BYTE *)clText,
lstrlen( clText )*sizeof(TCHAR) + sizeof(TCHAR) );
- RegCloseKey( hKey );
-}
-
-INT_PTR CALLBACK BackgroundPageProc(HWND hwndDlg,
- UINT uMsg,
- WPARAM wParam,
- LPARAM lParam)
-{
- g_hBackgroundPage = hwndDlg;
-
- switch(uMsg)
+ red = GetRValue(pGlobalData->backgroundDesktopColor);
+ green = GetGValue(pGlobalData->backgroundDesktopColor);
+ blue = GetBValue(pGlobalData->backgroundDesktopColor);
+ _stprintf(clText, TEXT("%d %d %d"), red, green, blue ); /* format string to
be set to registry */
+ RegSetValueEx(hKey, TEXT("Background"), 0, REG_SZ, (BYTE *)clText, lstrlen(
clText )*sizeof(TCHAR) + sizeof(TCHAR) );
+ RegCloseKey(hKey);
+}
+
+
+INT_PTR CALLBACK
+BackgroundPageProc(HWND hwndDlg,
+ UINT uMsg,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ PGLOBAL_DATA pGlobalData;
+
+ pGlobalData = (PGLOBAL_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
+
+ switch (uMsg)
{
case WM_INITDIALOG:
+ pGlobalData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(GLOBAL_DATA));
+ SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
+ InitBackgroundDialog(hwndDlg, pGlobalData);
+ break;
+
+ case WM_COMMAND:
{
- InitBackgroundDialog();
- } break;
-
- case WM_COMMAND:
- {
DWORD controlId = LOWORD(wParam);
DWORD command = HIWORD(wParam);
-
- switch(controlId)
+
+ switch (controlId)
{
case IDC_COLOR_BUTTON:
+ if (command == BN_CLICKED)
+ OnColorButton(hwndDlg, pGlobalData);
+ break;
+
+ case IDC_BROWSE_BUTTON:
+ if (command == BN_CLICKED)
+ OnBrowseButton(hwndDlg, pGlobalData);
+ break;
+
+ case IDC_PLACEMENT_COMBO:
+ if (command == CBN_SELCHANGE)
{
- if(command == BN_CLICKED)
- OnColorButton();
-
- } break;
-
- case IDC_BROWSE_BUTTON:
- {
- if(command == BN_CLICKED)
- OnBrowseButton();
-
- } break;
-
- case IDC_PLACEMENT_COMBO:
- {
- if(command == CBN_SELCHANGE)
- {
- g_placementSelection =
(int)SendMessage(g_hPlacementCombo, CB_GETCURSEL, 0, 0);
-
- InvalidateRect(g_hBackgroundPreview, NULL, TRUE);
-
- PropSheet_Changed(GetParent(g_hBackgroundPage),
g_hBackgroundPage);
- }
-
- } break;
+ pGlobalData->placementSelection =
(int)SendDlgItemMessage(hwndDlg, IDC_PLACEMENT_COMBO, CB_GETCURSEL, 0, 0);
+
+ InvalidateRect(GetDlgItem(hwndDlg, IDC_BACKGROUND_PREVIEW),
NULL, TRUE);
+
+ PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
+ }
+ break;
}
} break;
@@ -688,71 +708,68 @@
{
PAINTSTRUCT ps;
HDC hdc, hdcMem;
-
+
hdc = BeginPaint(hwndDlg, &ps);
-
+
hdcMem = CreateCompatibleDC(hdc);
- SelectObject(hdcMem, hBitmap);
-
- TransparentBlt(hdc, 98, 0, cxSource, cySource, hdcMem, 0, 0, cxSource,
cySource, 0xFF80FF);
+ SelectObject(hdcMem, pGlobalData->hBitmap);
+
+ TransparentBlt(hdc, 98, 0,
+ pGlobalData->cxSource, pGlobalData->cySource,
hdcMem, 0, 0,
+ pGlobalData->cxSource, pGlobalData->cySource,
0xFF80FF);
DeleteDC(hdcMem);
EndPaint(hwndDlg, &ps);
-
- } break;
+ }
+ break;
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT drawItem;
drawItem = (LPDRAWITEMSTRUCT)lParam;
- if(drawItem->CtlID == IDC_BACKGROUND_PREVIEW)
+ if (drawItem->CtlID == IDC_BACKGROUND_PREVIEW)
{
- DrawBackgroundPreview(drawItem);
+ DrawBackgroundPreview(drawItem, pGlobalData);
}
- } break;
-
+ }
+ break;
+
case WM_NOTIFY:
{
LPNMHDR lpnm = (LPNMHDR)lParam;
-
+
switch(lpnm->code)
- {
+ {
case PSN_APPLY:
- {
- SetWallpaper();
- SetDesktopBackColor();
- return TRUE;
- } break;
+ SetWallpaper(pGlobalData);
+ SetDesktopBackColor(hwndDlg, pGlobalData);
+ return TRUE;
case LVN_ITEMCHANGED:
{
LPNMLISTVIEW nm = (LPNMLISTVIEW)lParam;
-
- if((nm->uNewState & LVIS_SELECTED) == 0)
+
+ if ((nm->uNewState & LVIS_SELECTED) == 0)
return FALSE;
-
- ListViewItemChanged(nm->iItem);
+
+ ListViewItemChanged(hwndDlg, pGlobalData, nm->iItem);
} break;
-
- default:
- break;
}
-
- } break;
+ }
+ break;
case WM_DESTROY:
- {
- if(g_pWallpaperBitmap != NULL)
- DibFreeImage(g_pWallpaperBitmap);
-
- DeleteObject(hBitmap);
-
- } break;
- }
-
+ if (pGlobalData->pWallpaperBitmap != NULL)
+ DibFreeImage(pGlobalData->pWallpaperBitmap);
+
+ DeleteObject(pGlobalData->hBitmap);
+ HeapFree(GetProcessHeap(), 0, pGlobalData);
+ break;
+ }
+
return FALSE;
}
Modified: trunk/reactos/dll/cpl/desk/de.rc
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/desk/de.rc?rev=248…
==============================================================================
--- trunk/reactos/dll/cpl/desk/de.rc (original)
+++ trunk/reactos/dll/cpl/desk/de.rc Sun Nov 26 15:47:56 2006
@@ -2,7 +2,7 @@
IDD_BACKGROUND DIALOGEX DISCARDABLE 0, 0, 246, 205
STYLE DS_SHELLFONT | WS_CHILD | WS_DISABLED | WS_CAPTION
-CAPTION "Desktop"
+CAPTION "Hintergrund"
FONT 8, "MS Shell Dlg"
BEGIN
CONTROL "", IDC_BACKGROUND_PREVIEW, "Static",
SS_OWNERDRAW, 80, 10, 83, 57, WS_EX_STATICEDGE
Modified: trunk/reactos/dll/cpl/desk/desk.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/desk/desk.c?rev=24…
==============================================================================
--- trunk/reactos/dll/cpl/desk/desk.c (original)
+++ trunk/reactos/dll/cpl/desk/desk.c Sun Nov 26 15:47:56 2006
@@ -32,7 +32,9 @@
}
};
-static VOID InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)
+
+static VOID
+InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc)
{
ZeroMemory(psp, sizeof(PROPSHEETPAGE));
psp->dwSize = sizeof(PROPSHEETPAGE);
@@ -42,20 +44,22 @@
psp->pfnDlgProc = DlgProc;
}
+
/* Display Applet */
-LONG APIENTRY DisplayApplet(HWND hwnd, UINT uMsg, LONG wParam, LONG lParam)
+LONG APIENTRY
+DisplayApplet(HWND hwnd, UINT uMsg, LONG wParam, LONG lParam)
{
PROPSHEETPAGE psp[4];
PROPSHEETHEADER psh;
TCHAR Caption[1024];
-
+
UNREFERENCED_PARAMETER(lParam);
UNREFERENCED_PARAMETER(wParam);
UNREFERENCED_PARAMETER(uMsg);
UNREFERENCED_PARAMETER(hwnd);
LoadString(hApplet, IDS_CPLNAME, Caption, sizeof(Caption) / sizeof(TCHAR));
-
+
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK | PSH_PROPTITLE;
@@ -66,33 +70,30 @@
psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
psh.nStartPage = 0;
psh.ppsp = psp;
-
+
InitPropSheetPage(&psp[0], IDD_BACKGROUND, (DLGPROC) BackgroundPageProc);
InitPropSheetPage(&psp[1], IDD_SCREENSAVER, (DLGPROC) ScreenSaverPageProc);
InitPropSheetPage(&psp[2], IDD_APPEARANCE, (DLGPROC) AppearancePageProc);
InitPropSheetPage(&psp[3], IDD_SETTINGS, (DLGPROC) SettingsPageProc);
-
+
return (LONG)(PropertySheet(&psh) != -1);
}
/* Control Panel Callback */
-LONG CALLBACK CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
+LONG CALLBACK
+CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
{
int i = (int)lParam1;
-
- switch(uMsg)
+
+ switch (uMsg)
{
case CPL_INIT:
- {
- return TRUE;
- }
-
+ return TRUE;
+
case CPL_GETCOUNT:
- {
- return NUM_APPLETS;
- }
-
+ return NUM_APPLETS;
+
case CPL_INQUIRE:
{
CPLINFO *CPlInfo = (CPLINFO*)lParam2;
@@ -100,30 +101,30 @@
CPlInfo->idIcon = Applets[i].idIcon;
CPlInfo->idName = Applets[i].idName;
CPlInfo->idInfo = Applets[i].idDescription;
- } break;
-
+ }
+ break;
+
case CPL_DBLCLK:
- {
- Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
- } break;
+ Applets[i].AppletProc(hwndCPl, uMsg, lParam1, lParam2);
+ break;
}
-
+
return FALSE;
}
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
+BOOL WINAPI
+DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpvReserved)
{
UNREFERENCED_PARAMETER(lpvReserved);
- switch(dwReason)
+
+ switch (dwReason)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
- {
- hApplet = hinstDLL;
- } break;
+ hApplet = hinstDLL;
+ break;
}
-
+
return TRUE;
}
-
Modified: trunk/reactos/dll/cpl/desk/desk.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/desk/desk.h?rev=24…
==============================================================================
--- trunk/reactos/dll/cpl/desk/desk.h (original)
+++ trunk/reactos/dll/cpl/desk/desk.h Sun Nov 26 15:47:56 2006
@@ -11,31 +11,27 @@
#include "resource.h"
-typedef struct
+typedef struct _APPLET
{
int idIcon;
int idName;
int idDescription;
-
APPLET_PROC AppletProc;
-
} APPLET, *PAPPLET;
-extern HINSTANCE hApplet;
-
-typedef struct
+typedef struct _DIBITMAP
{
BITMAPFILEHEADER *header;
BITMAPINFO *info;
BYTE *bits;
-
int width;
int height;
+} DIBITMAP, *PDIBITMAP;
-} DIBitmap;
+extern HINSTANCE hApplet;
-extern DIBitmap *DibLoadImage(TCHAR *filename);
-extern void DibFreeImage(DIBitmap *bitmap);
+PDIBITMAP DibLoadImage(LPTSTR lpFilename);
+VOID DibFreeImage(PDIBITMAP lpBitmap);
DWORD DbgPrint(PCH Format,...);
Modified: trunk/reactos/dll/cpl/desk/dibitmap.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/desk/dibitmap.c?re…
==============================================================================
--- trunk/reactos/dll/cpl/desk/dibitmap.c (original)
+++ trunk/reactos/dll/cpl/desk/dibitmap.c Sun Nov 26 15:47:56 2006
@@ -10,83 +10,85 @@
#include "desk.h"
-DIBitmap *DibLoadImage(TCHAR *filename)
+PDIBITMAP
+DibLoadImage(LPTSTR lpFilename)
{
- BOOL bSuccess;
- DWORD dwFileSize, dwHighSize, dwBytesRead;
- HANDLE hFile;
- DIBitmap *bitmap;
-
- hFile = CreateFile(filename,
+ BOOL bSuccess;
+ DWORD dwFileSize, dwHighSize, dwBytesRead;
+ HANDLE hFile;
+ PDIBITMAP lpBitmap;
+
+ hFile = CreateFile(lpFilename,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
-
- if(hFile == INVALID_HANDLE_VALUE)
+ if (hFile == INVALID_HANDLE_VALUE)
return NULL;
-
+
dwFileSize = GetFileSize(hFile, &dwHighSize);
-
- if(dwHighSize)
+
+ if (dwHighSize)
{
CloseHandle(hFile);
return NULL;
}
- bitmap = malloc(sizeof(DIBitmap));
- if(!bitmap)
+ lpBitmap = HeapAlloc(GetProcessHeap(), 0, sizeof(DIBITMAP));
+ if (lpBitmap == NULL)
return NULL;
-
- bitmap->header = malloc(dwFileSize);
- if(!bitmap->header)
+
+ lpBitmap->header = HeapAlloc(GetProcessHeap(), 0, dwFileSize);
+ if (lpBitmap->header == NULL)
{
CloseHandle(hFile);
return NULL;
}
-
- bSuccess = ReadFile(hFile, bitmap->header, dwFileSize, &dwBytesRead, NULL);
+
+ bSuccess = ReadFile(hFile, lpBitmap->header, dwFileSize, &dwBytesRead, NULL);
CloseHandle(hFile);
-
- if(!bSuccess || (dwBytesRead != dwFileSize)
- || (bitmap->header->bfType != * (WORD *) "BM")
- || (bitmap->header->bfSize != dwFileSize))
+
+ if (!bSuccess ||
+ (dwBytesRead != dwFileSize) ||
+ (lpBitmap->header->bfType != * (WORD *) "BM") ||
+ (lpBitmap->header->bfSize != dwFileSize))
{
- free(bitmap->header);
+ HeapFree(GetProcessHeap(), 0, lpBitmap->header);
return NULL;
}
-
- bitmap->info = (BITMAPINFO *)(bitmap->header + 1);
- bitmap->bits = (BYTE *)bitmap->header + bitmap->header->bfOffBits;
-
+
+ lpBitmap->info = (BITMAPINFO *)(lpBitmap->header + 1);
+ lpBitmap->bits = (BYTE *)lpBitmap->header + lpBitmap->header->bfOffBits;
+
/* Get the DIB width and height */
- if(bitmap->info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
+ if (lpBitmap->info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
{
- bitmap->width = ((BITMAPCOREHEADER *)bitmap->info)->bcWidth;
- bitmap->height = ((BITMAPCOREHEADER *)bitmap->info)->bcHeight;
+ lpBitmap->width = ((BITMAPCOREHEADER *)lpBitmap->info)->bcWidth;
+ lpBitmap->height = ((BITMAPCOREHEADER *)lpBitmap->info)->bcHeight;
}
else
{
- bitmap->width = bitmap->info->bmiHeader.biWidth;
- bitmap->height = abs(bitmap->info->bmiHeader.biHeight);
+ lpBitmap->width = lpBitmap->info->bmiHeader.biWidth;
+ lpBitmap->height = abs(lpBitmap->info->bmiHeader.biHeight);
}
-
- return bitmap;
+
+ return lpBitmap;
}
-void DibFreeImage(DIBitmap *bitmap)
+
+VOID
+DibFreeImage(PDIBITMAP lpBitmap)
{
- if(bitmap == NULL)
+ if (lpBitmap == NULL)
return;
/* Free the header */
- if(bitmap->header != NULL)
- free(bitmap->header);
+ if (lpBitmap->header != NULL)
+ HeapFree(GetProcessHeap(), 0, lpBitmap->header);
/* Free the bitmap structure */
- if(bitmap != NULL)
- free(bitmap);
+ if (lpBitmap != NULL)
+ HeapFree(GetProcessHeap(), 0, lpBitmap);
}
-
Modified: trunk/reactos/dll/cpl/desk/screensaver.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/desk/screensaver.c…
==============================================================================
--- trunk/reactos/dll/cpl/desk/screensaver.c (original)
+++ trunk/reactos/dll/cpl/desk/screensaver.c Sun Nov 26 15:47:56 2006
@@ -13,10 +13,6 @@
#define MAX_SCREENSAVERS 100
-static VOID SetScreenSaver(VOID);
-static VOID AddListViewItems(HWND);
-static VOID CheckRegScreenSaverIsSecure(HWND);
-
typedef struct
{
BOOL bIsScreenSaver; /* Is this background a wallpaper */
@@ -24,12 +20,18 @@
TCHAR szDisplayName[256];
} ScreenSaverItem;
-int ImageListSelection = -1;
-ScreenSaverItem g_ScreenSaverItems[MAX_SCREENSAVERS];
-
-HMENU g_hPopupMenu = NULL;
-
-VOID ListViewItemAreChanged(HWND hwndDlg, int itemIndex)
+
+typedef struct _GLOBAL_DATA
+{
+ ScreenSaverItem g_ScreenSaverItems[MAX_SCREENSAVERS];
+ int ImageListSelection;
+ HMENU g_hPopupMenu;
+} GLOBAL_DATA, *PGLOBAL_DATA;
+
+
+
+static VOID
+ListViewItemAreChanged(HWND hwndDlg, PGLOBAL_DATA pGlobalData, int itemIndex)
{
BOOL bEnable;
LV_ITEM lvItem;
@@ -41,7 +43,7 @@
if (!ListView_GetItem(GetDlgItem(hwndDlg, IDC_SCREENS_CHOICES), &lvItem))
return;
- ImageListSelection = lvItem.lParam;
+ pGlobalData->ImageListSelection = lvItem.lParam;
bEnable = (lvItem.lParam != 0);
@@ -52,8 +54,9 @@
EnableWindow(GetDlgItem(hwndDlg, IDC_SCREENS_TIME), bEnable);
}
-VOID
-ScreensaverConfig(HWND hwndDlg)
+
+static VOID
+ScreensaverConfig(HWND hwndDlg, PGLOBAL_DATA pGlobalData)
{
/*
/p:<hwnd> Run in preview
@@ -66,25 +69,26 @@
STARTUPINFO si;
PROCESS_INFORMATION pi;
- if (ImageListSelection < 1)
+ if (pGlobalData->ImageListSelection < 1)
return;
swprintf(szCmdline, L"%s /c:%u",
- g_ScreenSaverItems[ImageListSelection].szFilename,
+
pGlobalData->g_ScreenSaverItems[pGlobalData->ImageListSelection].szFilename,
hwndDlg);
- ZeroMemory( &si, sizeof(si) );
+ ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
- ZeroMemory( &pi, sizeof(pi) );
- if(CreateProcess( NULL, szCmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si,
&pi ))
- {
- CloseHandle( pi.hProcess );
- CloseHandle( pi.hThread );
- }
-}
-
-VOID
-ScreensaverPreview(HWND hwndDlg)
+ ZeroMemory(&pi, sizeof(pi));
+ if(CreateProcess(NULL, szCmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si,
&pi))
+ {
+ CloseHandle(pi.hProcess);
+ CloseHandle(pi.hThread);
+ }
+}
+
+
+static VOID
+ScreensaverPreview(HWND hwndDlg, PGLOBAL_DATA pGlobalData)
{
/*
/p:<hwnd> Run in preview
@@ -97,151 +101,42 @@
STARTUPINFO si;
PROCESS_INFORMATION pi;
- if (ImageListSelection < 1)
+ if (pGlobalData->ImageListSelection < 1)
return;
- swprintf(szCmdline, L"%s /p",
g_ScreenSaverItems[ImageListSelection].szFilename);
-
- ZeroMemory( &si, sizeof(si) );
+ swprintf(szCmdline, L"%s /p",
+
pGlobalData->g_ScreenSaverItems[pGlobalData->ImageListSelection].szFilename);
+
+ ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
- ZeroMemory( &pi, sizeof(pi) );
- if(CreateProcess( NULL, szCmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi
))
- {
- CloseHandle( pi.hProcess );
- CloseHandle( pi.hThread );
- }
-}
-
-VOID
-ScreensaverDelete(HWND hwndDlg)
+ ZeroMemory(&pi, sizeof(pi));
+ if(CreateProcess(NULL, szCmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si,
&pi))
+ {
+ CloseHandle(pi.hProcess);
+ CloseHandle(pi.hThread);
+ }
+}
+
+
+static VOID
+ScreensaverDelete(HWND hwndDlg, PGLOBAL_DATA pGlobalData)
{
SHFILEOPSTRUCT fos;
- if (ImageListSelection < 1) // Can NOT delete anything :-)
+ if (pGlobalData->ImageListSelection < 1) // Can NOT delete anything :-)
return;
fos.hwnd = hwndDlg;
fos.wFunc = FO_DELETE;
fos.fFlags = 0;
- fos.pFrom = g_ScreenSaverItems[ImageListSelection].szFilename;
+ fos.pFrom =
pGlobalData->g_ScreenSaverItems[pGlobalData->ImageListSelection].szFilename;
SHFileOperationW(&fos);
}
-INT_PTR
-CALLBACK
-ScreenSaverPageProc(HWND hwndDlg,
- UINT uMsg,
- WPARAM wParam,
- LPARAM lParam)
-{
- switch (uMsg)
- {
- case WM_DESTROY:
- {
- DestroyMenu(g_hPopupMenu);
- break;
- }
- case WM_INITDIALOG:
- {
- SendDlgItemMessage(hwndDlg, IDC_SCREENS_TIME, UDM_SETRANGE, 0, MAKELONG
((short) 240, (short) 0));
- AddListViewItems(hwndDlg);
-
- g_hPopupMenu = LoadMenu(hApplet, MAKEINTRESOURCE(IDR_POPUP_MENU));
- g_hPopupMenu = GetSubMenu(g_hPopupMenu, 0);
-
- CheckRegScreenSaverIsSecure(hwndDlg);
- } break;
-
- case WM_COMMAND:
- {
- DWORD controlId = LOWORD(wParam);
- DWORD command = HIWORD(wParam);
-
- switch(controlId) {
- case IDC_SCREENS_POWER_BUTTON: // Start Powercfg.Cpl
- {
- if (command == BN_CLICKED)
- WinExec("rundll32 shell32.dll,Control_RunDLL
powercfg.cpl,,",SW_SHOWNORMAL);
- } break;
- case IDC_SCREENS_TESTSC: // Screensaver Preview
- {
- if(command == BN_CLICKED)
- ScreensaverPreview(hwndDlg);
- break;
- }
- case ID_MENU_PREVIEW:
- {
- ScreensaverPreview(hwndDlg);
- break;
- }
- case ID_MENU_CONFIG:
- {
- ScreensaverConfig(hwndDlg);
- break;
- }
- case ID_MENU_DELETE: // Delete Screensaver
- {
- if(command == BN_CLICKED) {
- ScreensaverDelete(hwndDlg);
- }
- } break;
- case IDC_SCREENS_SETTINGS: // Screensaver Settings
- {
- if(command == BN_CLICKED)
- ScreensaverConfig(hwndDlg);
- break;
- }
- case IDC_SCREENS_USEPASSCHK: // Screensaver Is Secure
- {
- if(command == BN_CLICKED)
- MessageBox(NULL, TEXT("That button doesn't do anything
yet"), TEXT("Whoops"), MB_OK);
- } break;
- case IDC_SCREENS_TIME: // Delay before show screensaver
- {
- }
- default:
- break;
- } break;
- }
- case WM_NOTIFY:
- {
- LPNMHDR lpnm = (LPNMHDR)lParam;
- LPNMITEMACTIVATE nmia = (LPNMITEMACTIVATE) lParam;
- RECT rc;
-
- switch(lpnm->code)
- {
- case PSN_APPLY:
- {
- SetScreenSaver();
- return TRUE;
- } break;
- case NM_RCLICK:
- {
- GetWindowRect(GetDlgItem(hwndDlg, IDC_SCREENS_CHOICES), &rc);
- TrackPopupMenuEx(g_hPopupMenu, TPM_RIGHTBUTTON,
- rc.left + nmia->ptAction.x, rc.top +
nmia->ptAction.y, hwndDlg, NULL);
- break;
- }
- case LVN_ITEMCHANGED:
- {
- LPNMLISTVIEW nm = (LPNMLISTVIEW)lParam;
- if ((nm->uNewState & LVIS_SELECTED) == 0)
- return FALSE;
- ListViewItemAreChanged(hwndDlg, nm->iItem);
- break;
- }
- default:
- break;
- }
- } break;
- }
-
- return FALSE;
-}
-
-VOID CheckRegScreenSaverIsSecure(HWND hwndDlg)
+
+static VOID
+CheckRegScreenSaverIsSecure(HWND hwndDlg)
{
HKEY hKey;
TCHAR szBuffer[2];
@@ -255,7 +150,7 @@
if (result == ERROR_SUCCESS)
{
- if(_ttoi(szBuffer) == 1)
+ if (_ttoi(szBuffer) == 1)
{
SendDlgItemMessage(hwndDlg, IDC_SCREENS_USEPASSCHK, BM_SETCHECK,
(WPARAM)BST_CHECKED, 0);
return;
@@ -266,7 +161,8 @@
}
-VOID AddListViewItems(HWND hwndDlg)
+static VOID
+AddListViewItems(HWND hwndDlg, PGLOBAL_DATA pGlobalData)
{
HWND hwndScreenSaverList = GetDlgItem(hwndDlg, IDC_SCREENS_CHOICES);
WIN32_FIND_DATA fd;
@@ -298,7 +194,7 @@
(void)ListView_InsertColumn(hwndScreenSaverList, 0, &dummy);
/* Add the "None" item */
- ScreenSaverItem = &g_ScreenSaverItems[ScreenlistViewItemCount];
+ ScreenSaverItem = &pGlobalData->g_ScreenSaverItems[ScreenlistViewItemCount];
ScreenSaverItem->bIsScreenSaver = FALSE;
@@ -326,7 +222,7 @@
result = RegQueryValueEx(regKey, TEXT("SCRNSAVE.EXE"), 0, &varType,
(LPBYTE)wallpaperFilename, &bufferSize);
- if((result == ERROR_SUCCESS) && (_tcslen(wallpaperFilename) > 0))
+ if ((result == ERROR_SUCCESS) && (_tcslen(wallpaperFilename) > 0))
{
himl = (HIMAGELIST)SHGetFileInfo(wallpaperFilename,
0,
@@ -335,9 +231,9 @@
SHGFI_SYSICONINDEX | SHGFI_SMALLICON |
SHGFI_DISPLAYNAME);
- if(himl != NULL)
+ if (himl != NULL)
{
- if(i++ == 0)
+ if (i++ == 0)
{
g_hScreenShellImageList = himl;
(void)ListView_SetImageList(g_hScreengroundList, himl, LVSIL_SMALL);
@@ -406,7 +302,7 @@
(VOID)ListView_SetImageList(hwndScreenSaverList, himl, LVSIL_SMALL);
}
- ScreenSaverItem = &g_ScreenSaverItems[ScreenlistViewItemCount];
+ ScreenSaverItem =
&pGlobalData->g_ScreenSaverItems[ScreenlistViewItemCount];
ScreenSaverItem->bIsScreenSaver = TRUE;
@@ -445,14 +341,16 @@
}
}
-VOID SetScreenSaver(VOID)
+
+static VOID
+SetScreenSaver(PGLOBAL_DATA pGlobalData)
{
HKEY regKey;
RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0,
KEY_ALL_ACCESS, ®Key);
- RegSetValueEx(regKey, TEXT("SCRNSAVE.EXE"), 0, REG_SZ, (BYTE
*)g_ScreenSaverItems[ImageListSelection].szFilename,
_tcslen(g_ScreenSaverItems[ImageListSelection].szFilename)*sizeof(TCHAR));
- // RegSetValueEx(regKey, TEXT("SCRNSAVE.EXE"), 0, REG_SZ,
g_ScreenSaverItems[ImageListSelection].szFilename, sizeof(TCHAR) * 2);
-
+ RegSetValueEx(regKey, TEXT("SCRNSAVE.EXE"), 0, REG_SZ,
+ (BYTE
*)pGlobalData->g_ScreenSaverItems[pGlobalData->ImageListSelection].szFilename,
+
_tcslen(pGlobalData->g_ScreenSaverItems[pGlobalData->ImageListSelection].szFilename)
* sizeof(TCHAR));
RegCloseKey(regKey);
@@ -468,3 +366,122 @@
// SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, TEXT(""),
SPIF_UPDATEINIFILE);
//}
}
+
+
+INT_PTR CALLBACK
+ScreenSaverPageProc(HWND hwndDlg,
+ UINT uMsg,
+ WPARAM wParam,
+ LPARAM lParam)
+{
+ PGLOBAL_DATA pGlobalData;
+
+ pGlobalData = (PGLOBAL_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
+
+ switch (uMsg)
+ {
+ case WM_INITDIALOG:
+ pGlobalData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(GLOBAL_DATA));
+ SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
+
+ pGlobalData->ImageListSelection = -1;
+
+ SendDlgItemMessage(hwndDlg, IDC_SCREENS_TIME, UDM_SETRANGE, 0, MAKELONG
((short) 240, (short) 0));
+ AddListViewItems(hwndDlg, pGlobalData);
+
+ pGlobalData->g_hPopupMenu = LoadMenu(hApplet,
MAKEINTRESOURCE(IDR_POPUP_MENU));
+ pGlobalData->g_hPopupMenu = GetSubMenu(pGlobalData->g_hPopupMenu, 0);
+
+ CheckRegScreenSaverIsSecure(hwndDlg);
+ break;
+
+ case WM_DESTROY:
+ DestroyMenu(pGlobalData->g_hPopupMenu);
+ HeapFree(GetProcessHeap(), 0, pGlobalData);
+ break;
+
+ case WM_COMMAND:
+ {
+ DWORD controlId = LOWORD(wParam);
+ DWORD command = HIWORD(wParam);
+
+ switch (controlId)
+ {
+ case IDC_SCREENS_POWER_BUTTON: // Start Powercfg.Cpl
+ if (command == BN_CLICKED)
+ WinExec("rundll32 shell32.dll,Control_RunDLL
powercfg.cpl,,",SW_SHOWNORMAL);
+ break;
+
+ case IDC_SCREENS_TESTSC: // Screensaver Preview
+ if(command == BN_CLICKED)
+ ScreensaverPreview(hwndDlg, pGlobalData);
+ break;
+
+ case ID_MENU_PREVIEW:
+ ScreensaverPreview(hwndDlg, pGlobalData);
+ break;
+
+ case ID_MENU_CONFIG:
+ ScreensaverConfig(hwndDlg, pGlobalData);
+ break;
+
+ case ID_MENU_DELETE: // Delete Screensaver
+ if (command == BN_CLICKED)
+ ScreensaverDelete(hwndDlg, pGlobalData);
+ break;
+
+ case IDC_SCREENS_SETTINGS: // Screensaver Settings
+ if (command == BN_CLICKED)
+ ScreensaverConfig(hwndDlg, pGlobalData);
+ break;
+
+ case IDC_SCREENS_USEPASSCHK: // Screensaver Is Secure
+ if (command == BN_CLICKED)
+ MessageBox(NULL, TEXT("That button doesn't do anything
yet"), TEXT("Whoops"), MB_OK);
+ break;
+
+ case IDC_SCREENS_TIME: // Delay before show screensaver
+ break;
+
+ default:
+ break;
+ }
+ break;
+ }
+
+ case WM_NOTIFY:
+ {
+ LPNMHDR lpnm = (LPNMHDR)lParam;
+ LPNMITEMACTIVATE nmia = (LPNMITEMACTIVATE) lParam;
+ RECT rc;
+
+ switch(lpnm->code)
+ {
+ case PSN_APPLY:
+ SetScreenSaver(pGlobalData);
+ return TRUE;
+
+ case NM_RCLICK:
+ GetWindowRect(GetDlgItem(hwndDlg, IDC_SCREENS_CHOICES), &rc);
+ TrackPopupMenuEx(pGlobalData->g_hPopupMenu, TPM_RIGHTBUTTON,
+ rc.left + nmia->ptAction.x, rc.top +
nmia->ptAction.y, hwndDlg, NULL);
+ break;
+
+ case LVN_ITEMCHANGED:
+ {
+ LPNMLISTVIEW nm = (LPNMLISTVIEW)lParam;
+ if ((nm->uNewState & LVIS_SELECTED) == 0)
+ return FALSE;
+ ListViewItemAreChanged(hwndDlg, pGlobalData, nm->iItem);
+ break;
+ }
+
+ default:
+ break;
+ }
+ }
+ break;
+ }
+
+ return FALSE;
+}