Author: ekohl Date: Thu Nov 30 02:03:18 2006 New Revision: 24979
URL: http://svn.reactos.org/svn/reactos?rev=24979&view=rev Log: Move global variables into a struct that is attached to the property sheet page dialog.
Modified: trunk/reactos/dll/cpl/desk/settings.c
Modified: trunk/reactos/dll/cpl/desk/settings.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/desk/settings.c?rev... ============================================================================== --- trunk/reactos/dll/cpl/desk/settings.c (original) +++ trunk/reactos/dll/cpl/desk/settings.c Thu Nov 30 02:03:18 2006 @@ -41,34 +41,37 @@ SETTINGS_ENTRY InitialSettings; } DISPLAY_DEVICE_ENTRY, *PDISPLAY_DEVICE_ENTRY;
-static PDISPLAY_DEVICE_ENTRY DisplayDeviceList = NULL; -static PDISPLAY_DEVICE_ENTRY CurrentDisplayDevice = NULL; - -HBITMAP hBitmap = NULL; -int cxSource, cySource; +typedef struct _GLOBAL_DATA +{ + PDISPLAY_DEVICE_ENTRY DisplayDeviceList; + PDISPLAY_DEVICE_ENTRY CurrentDisplayDevice; + HBITMAP hBitmap; + int cxSource; + int cySource; +} GLOBAL_DATA, *PGLOBAL_DATA;
static VOID -UpdateDisplay(IN HWND hwndDlg) +UpdateDisplay(IN HWND hwndDlg, PGLOBAL_DATA pGlobalData) { TCHAR Buffer[64]; TCHAR Pixel[64]; DWORD index;
LoadString(hApplet, IDS_PIXEL, Pixel, sizeof(Pixel) / sizeof(TCHAR)); - _stprintf(Buffer, Pixel, CurrentDisplayDevice->CurrentSettings->dmPelsWidth, CurrentDisplayDevice->CurrentSettings->dmPelsHeight, Pixel); + _stprintf(Buffer, Pixel, pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth, pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight, Pixel); SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION_TEXT, WM_SETTEXT, 0, (LPARAM)Buffer);
- for (index = 0; index < CurrentDisplayDevice->ResolutionsCount; index++) - { - - if (CurrentDisplayDevice->Resolutions[index].dmPelsWidth == CurrentDisplayDevice->CurrentSettings->dmPelsWidth && - CurrentDisplayDevice->Resolutions[index].dmPelsHeight == CurrentDisplayDevice->CurrentSettings->dmPelsHeight) + for (index = 0; index < pGlobalData->CurrentDisplayDevice->ResolutionsCount; index++) + { + + if (pGlobalData->CurrentDisplayDevice->Resolutions[index].dmPelsWidth == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth && + pGlobalData->CurrentDisplayDevice->Resolutions[index].dmPelsHeight == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight) { SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION, TBM_SETPOS, TRUE, index); break; } } - if (LoadString(hApplet, (2900 + CurrentDisplayDevice->CurrentSettings->dmBitsPerPel), Buffer, sizeof(Buffer) / sizeof(TCHAR))) + if (LoadString(hApplet, (2900 + pGlobalData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel), Buffer, sizeof(Buffer) / sizeof(TCHAR))) SendDlgItemMessage(hwndDlg, IDC_SETTINGS_BPP, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)Buffer); }
@@ -149,7 +152,7 @@ }
static BOOL -AddDisplayDevice(IN LPTSTR Description, IN LPTSTR DeviceName) +AddDisplayDevice(IN PGLOBAL_DATA pGlobalData, IN LPTSTR Description, IN LPTSTR DeviceName) { PDISPLAY_DEVICE_ENTRY newEntry = NULL; LPTSTR description = NULL; @@ -201,8 +204,8 @@ memcpy(name, DeviceName, nameSize); newEntry->DeviceDescription = description; newEntry->DeviceName = name; - newEntry->Flink = DisplayDeviceList; - DisplayDeviceList = newEntry; + newEntry->Flink = pGlobalData->DisplayDeviceList; + pGlobalData->DisplayDeviceList = newEntry; return TRUE;
ByeBye: @@ -230,12 +233,12 @@ }
static VOID -OnDisplayDeviceChanged(IN HWND hwndDlg, IN PDISPLAY_DEVICE_ENTRY pDeviceEntry) +OnDisplayDeviceChanged(IN HWND hwndDlg, IN PGLOBAL_DATA pGlobalData, IN PDISPLAY_DEVICE_ENTRY pDeviceEntry) { PSETTINGS_ENTRY Current; DWORD index;
- CurrentDisplayDevice = pDeviceEntry; /* Update global variable */ + pGlobalData->CurrentDisplayDevice = pDeviceEntry; /* Update global variable */
/* Fill color depths combo box */ SendDlgItemMessage(hwndDlg, IDC_SETTINGS_BPP, CB_RESETCONTENT, 0, 0); @@ -257,7 +260,7 @@ SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION, TBM_CLEARTICS, TRUE, 0); SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION, TBM_SETRANGE, TRUE, MAKELONG(0, pDeviceEntry->ResolutionsCount - 1));
- UpdateDisplay(hwndDlg); + UpdateDisplay(hwndDlg, pGlobalData); }
static VOID @@ -267,6 +270,13 @@ DWORD iDevNum = 0; DISPLAY_DEVICE displayDevice; BITMAP bitmap; + PGLOBAL_DATA pGlobalData; + + pGlobalData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(GLOBAL_DATA)); + if (pGlobalData == NULL) + return; + + SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pGlobalData);
/* Get video cards list */ displayDevice.cb = (DWORD)sizeof(DISPLAY_DEVICE); @@ -274,7 +284,7 @@ { if ((displayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0) { - if (AddDisplayDevice(displayDevice.DeviceString, displayDevice.DeviceName)) + if (AddDisplayDevice(pGlobalData, displayDevice.DeviceString, displayDevice.DeviceName)) Result++; } iDevNum++; @@ -290,8 +300,8 @@ else if (Result == 1) { /* Single video adapter */ - SendDlgItemMessage(hwndDlg, IDC_SETTINGS_DEVICE, WM_SETTEXT, 0, (LPARAM)DisplayDeviceList->DeviceDescription); - OnDisplayDeviceChanged(hwndDlg, DisplayDeviceList); + SendDlgItemMessage(hwndDlg, IDC_SETTINGS_DEVICE, WM_SETTEXT, 0, (LPARAM)pGlobalData->DisplayDeviceList->DeviceDescription); + OnDisplayDeviceChanged(hwndDlg, pGlobalData, pGlobalData->DisplayDeviceList); } else { @@ -299,18 +309,18 @@ /* FIXME: choose selected adapter being the primary one */ }
- 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; + 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 -OnBPPChanged(IN HWND hwndDlg) +OnBPPChanged(IN HWND hwndDlg, IN PGLOBAL_DATA pGlobalData) { /* if new BPP is not compatible with resolution: * 1) try to find the nearest smaller matching resolution @@ -326,7 +336,7 @@ dmNewBitsPerPel = (DWORD) SendDlgItemMessage(hwndDlg, IDC_SETTINGS_BPP, CB_GETITEMDATA, index, 0);
/* find if new parameters are valid */ - Current = CurrentDisplayDevice->CurrentSettings; + Current = pGlobalData->CurrentDisplayDevice->CurrentSettings; if (dmNewBitsPerPel == Current->dmBitsPerPel) { /* no change */ @@ -341,11 +351,11 @@ while (Current != NULL) { if (Current->dmBitsPerPel == dmNewBitsPerPel - && Current->dmPelsHeight == CurrentDisplayDevice->CurrentSettings->dmPelsHeight - && Current->dmPelsWidth == CurrentDisplayDevice->CurrentSettings->dmPelsWidth) - { - CurrentDisplayDevice->CurrentSettings = Current; - UpdateDisplay(hwndDlg); + && Current->dmPelsHeight == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight + && Current->dmPelsWidth == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth) + { + pGlobalData->CurrentDisplayDevice->CurrentSettings = Current; + UpdateDisplay(hwndDlg, pGlobalData); return; } Current = Current->Blink; @@ -357,11 +367,11 @@ while (Current != NULL) { if (Current->dmBitsPerPel == dmNewBitsPerPel - && Current->dmPelsHeight == CurrentDisplayDevice->CurrentSettings->dmPelsHeight - && Current->dmPelsWidth == CurrentDisplayDevice->CurrentSettings->dmPelsWidth) - { - CurrentDisplayDevice->CurrentSettings = Current; - UpdateDisplay(hwndDlg); + && Current->dmPelsHeight == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight + && Current->dmPelsWidth == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth) + { + pGlobalData->CurrentDisplayDevice->CurrentSettings = Current; + UpdateDisplay(hwndDlg, pGlobalData); return; } Current = Current->Flink; @@ -369,26 +379,26 @@ }
/* search smaller resolution compatible with current color depth */ - Current = CurrentDisplayDevice->CurrentSettings->Blink; + Current = pGlobalData->CurrentDisplayDevice->CurrentSettings->Blink; while (Current != NULL) { if (Current->dmBitsPerPel == dmNewBitsPerPel) { - CurrentDisplayDevice->CurrentSettings = Current; - UpdateDisplay(hwndDlg); + pGlobalData->CurrentDisplayDevice->CurrentSettings = Current; + UpdateDisplay(hwndDlg, pGlobalData); return; } Current = Current->Blink; }
/* search bigger resolution compatible with current color depth */ - Current = CurrentDisplayDevice->CurrentSettings->Flink; + Current = pGlobalData->CurrentDisplayDevice->CurrentSettings->Flink; while (Current != NULL) { if (Current->dmBitsPerPel == dmNewBitsPerPel) { - CurrentDisplayDevice->CurrentSettings = Current; - UpdateDisplay(hwndDlg); + pGlobalData->CurrentDisplayDevice->CurrentSettings = Current; + UpdateDisplay(hwndDlg, pGlobalData); return; } Current = Current->Flink; @@ -398,18 +408,18 @@ }
static VOID -OnResolutionChanged(IN HWND hwndDlg, IN DWORD NewPosition) +OnResolutionChanged(IN HWND hwndDlg, IN PGLOBAL_DATA pGlobalData, IN DWORD NewPosition) { /* if new resolution is not compatible with color depth: * 1) try to find the nearest bigger matching color depth * 2) otherwise, get the nearest smaller color depth */ PSETTINGS_ENTRY Current; - DWORD dmNewPelsHeight = CurrentDisplayDevice->Resolutions[NewPosition].dmPelsHeight; - DWORD dmNewPelsWidth = CurrentDisplayDevice->Resolutions[NewPosition].dmPelsWidth; + DWORD dmNewPelsHeight = pGlobalData->CurrentDisplayDevice->Resolutions[NewPosition].dmPelsHeight; + DWORD dmNewPelsWidth = pGlobalData->CurrentDisplayDevice->Resolutions[NewPosition].dmPelsWidth;
/* find if new parameters are valid */ - Current = CurrentDisplayDevice->CurrentSettings; + Current = pGlobalData->CurrentDisplayDevice->CurrentSettings; if (dmNewPelsHeight == Current->dmPelsHeight && dmNewPelsWidth == Current->dmPelsWidth) { /* no change */ @@ -425,10 +435,10 @@ { if (Current->dmPelsHeight == dmNewPelsHeight && Current->dmPelsWidth == dmNewPelsWidth - && Current->dmBitsPerPel == CurrentDisplayDevice->CurrentSettings->dmBitsPerPel) - { - CurrentDisplayDevice->CurrentSettings = Current; - UpdateDisplay(hwndDlg); + && Current->dmBitsPerPel == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel) + { + pGlobalData->CurrentDisplayDevice->CurrentSettings = Current; + UpdateDisplay(hwndDlg, pGlobalData); return; } Current = Current->Blink; @@ -441,10 +451,10 @@ { if (Current->dmPelsHeight == dmNewPelsHeight && Current->dmPelsWidth == dmNewPelsWidth - && Current->dmBitsPerPel == CurrentDisplayDevice->CurrentSettings->dmBitsPerPel) - { - CurrentDisplayDevice->CurrentSettings = Current; - UpdateDisplay(hwndDlg); + && Current->dmBitsPerPel == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel) + { + pGlobalData->CurrentDisplayDevice->CurrentSettings = Current; + UpdateDisplay(hwndDlg, pGlobalData); return; } Current = Current->Flink; @@ -452,26 +462,26 @@ }
/* search bigger color depth compatible with current resolution */ - Current = CurrentDisplayDevice->CurrentSettings->Flink; + Current = pGlobalData->CurrentDisplayDevice->CurrentSettings->Flink; while (Current != NULL) { if (dmNewPelsHeight == Current->dmPelsHeight && dmNewPelsWidth == Current->dmPelsWidth) { - CurrentDisplayDevice->CurrentSettings = Current; - UpdateDisplay(hwndDlg); + pGlobalData->CurrentDisplayDevice->CurrentSettings = Current; + UpdateDisplay(hwndDlg, pGlobalData); return; } Current = Current->Flink; }
/* search smaller color depth compatible with current resolution */ - Current = CurrentDisplayDevice->CurrentSettings->Blink; + Current = pGlobalData->CurrentDisplayDevice->CurrentSettings->Blink; while (Current != NULL) { if (dmNewPelsHeight == Current->dmPelsHeight && dmNewPelsWidth == Current->dmPelsWidth) { - CurrentDisplayDevice->CurrentSettings = Current; - UpdateDisplay(hwndDlg); + pGlobalData->CurrentDisplayDevice->CurrentSettings = Current; + UpdateDisplay(hwndDlg, pGlobalData); return; } Current = Current->Blink; @@ -490,6 +500,10 @@ INT_PTR CALLBACK SettingsPageProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam) { + PGLOBAL_DATA pGlobalData; + + pGlobalData = (PGLOBAL_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER); + switch(uMsg) { case WM_INITDIALOG: @@ -503,7 +517,7 @@ if (controlId == IDC_SETTINGS_ADVANCED && command == BN_CLICKED) OnAdvancedButton(); else if (controlId == IDC_SETTINGS_BPP && command == CBN_SELCHANGE) - OnBPPChanged(hwndDlg); + OnBPPChanged(hwndDlg, pGlobalData); break; } case WM_HSCROLL: @@ -519,7 +533,7 @@ case TB_ENDTRACK: { DWORD newPosition = (DWORD) SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION, TBM_GETPOS, 0, 0); - OnResolutionChanged(hwndDlg, newPosition); + OnResolutionChanged(hwndDlg, pGlobalData, newPosition); } } break; @@ -529,9 +543,9 @@ LPNMHDR lpnm = (LPNMHDR)lParam; if (lpnm->code == (UINT)PSN_APPLY) { - if (CurrentDisplayDevice->CurrentSettings->dmPelsWidth != CurrentDisplayDevice->InitialSettings.dmPelsWidth - || CurrentDisplayDevice->CurrentSettings->dmPelsHeight != CurrentDisplayDevice->InitialSettings.dmPelsHeight - || CurrentDisplayDevice->CurrentSettings->dmBitsPerPel != CurrentDisplayDevice->InitialSettings.dmBitsPerPel) + if (pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth != pGlobalData->CurrentDisplayDevice->InitialSettings.dmPelsWidth + || pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight != pGlobalData->CurrentDisplayDevice->InitialSettings.dmPelsHeight + || pGlobalData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel != pGlobalData->CurrentDisplayDevice->InitialSettings.dmBitsPerPel) { /* FIXME: Need to test changes */ /* Apply new settings */ @@ -539,12 +553,12 @@ DEVMODE devmode; RtlZeroMemory(&devmode, sizeof(DEVMODE)); devmode.dmSize = (WORD)sizeof(DEVMODE); - devmode.dmPelsWidth = CurrentDisplayDevice->CurrentSettings->dmPelsWidth; - devmode.dmPelsHeight = CurrentDisplayDevice->CurrentSettings->dmPelsHeight; - devmode.dmBitsPerPel = CurrentDisplayDevice->CurrentSettings->dmBitsPerPel; + devmode.dmPelsWidth = pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth; + devmode.dmPelsHeight = pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight; + devmode.dmBitsPerPel = pGlobalData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel; devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; rc = ChangeDisplaySettingsEx( - CurrentDisplayDevice->DeviceName, + pGlobalData->CurrentDisplayDevice->DeviceName, &devmode, NULL, CDS_UPDATEREGISTRY, @@ -552,9 +566,9 @@ switch (rc) { case DISP_CHANGE_SUCCESSFUL: - CurrentDisplayDevice->InitialSettings.dmPelsWidth = CurrentDisplayDevice->CurrentSettings->dmPelsWidth; - CurrentDisplayDevice->InitialSettings.dmPelsHeight = CurrentDisplayDevice->CurrentSettings->dmPelsHeight; - CurrentDisplayDevice->InitialSettings.dmBitsPerPel = CurrentDisplayDevice->CurrentSettings->dmBitsPerPel; + pGlobalData->CurrentDisplayDevice->InitialSettings.dmPelsWidth = pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth; + pGlobalData->CurrentDisplayDevice->InitialSettings.dmPelsHeight = pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight; + pGlobalData->CurrentDisplayDevice->InitialSettings.dmBitsPerPel = pGlobalData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel; break; case DISP_CHANGE_FAILED: MessageBox(NULL, TEXT("Failed to apply new settings..."), TEXT("Display settings"), MB_OK | MB_ICONSTOP); @@ -579,9 +593,13 @@ 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); @@ -591,7 +609,7 @@
case WM_DESTROY: { - PDISPLAY_DEVICE_ENTRY Current = DisplayDeviceList; + PDISPLAY_DEVICE_ENTRY Current = pGlobalData->DisplayDeviceList; while (Current != NULL) { PDISPLAY_DEVICE_ENTRY Next = Current->Flink; @@ -606,7 +624,9 @@ Current = Next; }
- DeleteObject(hBitmap); + DeleteObject(pGlobalData->hBitmap); + + HeapFree(GetProcessHeap(), 0, pGlobalData); } } return FALSE;