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++)
+ for (index = 0; index < pGlobalData->CurrentDisplayDevice->ResolutionsCount; index++)
{
- if (CurrentDisplayDevice->Resolutions[index].dmPelsWidth == CurrentDisplayDevice->CurrentSettings->dmPelsWidth &&
- CurrentDisplayDevice->Resolutions[index].dmPelsHeight == CurrentDisplayDevice->CurrentSettings->dmPelsHeight)
+ 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);
}
}
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;
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:
}
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);
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
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);
{
if ((displayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0)
{
- if (AddDisplayDevice(displayDevice.DeviceString, displayDevice.DeviceName))
+ if (AddDisplayDevice(pGlobalData, displayDevice.DeviceString, displayDevice.DeviceName))
Result++;
}
iDevNum++;
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
{
/* FIXME: choose selected adapter being the primary one */
}
- hBitmap = LoadImage(hApplet, MAKEINTRESOURCE(IDC_MONITOR), IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
- if (hBitmap != NULL)
+ pGlobalData->hBitmap = LoadImage(hApplet, MAKEINTRESOURCE(IDC_MONITOR), IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
+ if (pGlobalData->hBitmap != NULL)
{
- GetObject(hBitmap, sizeof(BITMAP), &bitmap);
+ GetObject(pGlobalData->hBitmap, sizeof(BITMAP), &bitmap);
- cxSource = bitmap.bmWidth;
- cySource = bitmap.bmHeight;
+ 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
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 */
while (Current != NULL)
{
if (Current->dmBitsPerPel == dmNewBitsPerPel
- && Current->dmPelsHeight == CurrentDisplayDevice->CurrentSettings->dmPelsHeight
- && Current->dmPelsWidth == CurrentDisplayDevice->CurrentSettings->dmPelsWidth)
+ && Current->dmPelsHeight == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight
+ && Current->dmPelsWidth == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth)
{
- CurrentDisplayDevice->CurrentSettings = Current;
- UpdateDisplay(hwndDlg);
+ pGlobalData->CurrentDisplayDevice->CurrentSettings = Current;
+ UpdateDisplay(hwndDlg, pGlobalData);
return;
}
Current = Current->Blink;
while (Current != NULL)
{
if (Current->dmBitsPerPel == dmNewBitsPerPel
- && Current->dmPelsHeight == CurrentDisplayDevice->CurrentSettings->dmPelsHeight
- && Current->dmPelsWidth == CurrentDisplayDevice->CurrentSettings->dmPelsWidth)
+ && Current->dmPelsHeight == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight
+ && Current->dmPelsWidth == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth)
{
- CurrentDisplayDevice->CurrentSettings = Current;
- UpdateDisplay(hwndDlg);
+ pGlobalData->CurrentDisplayDevice->CurrentSettings = Current;
+ UpdateDisplay(hwndDlg, pGlobalData);
return;
}
Current = Current->Flink;
}
/* 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;
}
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 */
{
if (Current->dmPelsHeight == dmNewPelsHeight
&& Current->dmPelsWidth == dmNewPelsWidth
- && Current->dmBitsPerPel == CurrentDisplayDevice->CurrentSettings->dmBitsPerPel)
+ && Current->dmBitsPerPel == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel)
{
- CurrentDisplayDevice->CurrentSettings = Current;
- UpdateDisplay(hwndDlg);
+ pGlobalData->CurrentDisplayDevice->CurrentSettings = Current;
+ UpdateDisplay(hwndDlg, pGlobalData);
return;
}
Current = Current->Blink;
{
if (Current->dmPelsHeight == dmNewPelsHeight
&& Current->dmPelsWidth == dmNewPelsWidth
- && Current->dmBitsPerPel == CurrentDisplayDevice->CurrentSettings->dmBitsPerPel)
+ && Current->dmBitsPerPel == pGlobalData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel)
{
- CurrentDisplayDevice->CurrentSettings = Current;
- UpdateDisplay(hwndDlg);
+ pGlobalData->CurrentDisplayDevice->CurrentSettings = Current;
+ UpdateDisplay(hwndDlg, pGlobalData);
return;
}
Current = Current->Flink;
}
/* 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;
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:
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:
case TB_ENDTRACK:
{
DWORD newPosition = (DWORD) SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION, TBM_GETPOS, 0, 0);
- OnResolutionChanged(hwndDlg, newPosition);
+ OnResolutionChanged(hwndDlg, pGlobalData, newPosition);
}
}
break;
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 */
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,
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);
hdc = BeginPaint(hwndDlg, &ps);
hdcMem = CreateCompatibleDC(hdc);
- SelectObject(hdcMem, hBitmap);
+ SelectObject(hdcMem, pGlobalData->hBitmap);
- TransparentBlt(hdc, 98, 0, cxSource, cySource, hdcMem, 0, 0, cxSource, cySource, 0xFF80FF);
+ TransparentBlt(hdc, 98, 0,
+ pGlobalData->cxSource,
+ pGlobalData->cySource, hdcMem, 0, 0,
+ pGlobalData->cxSource,
+ pGlobalData->cySource, 0xFF80FF);
DeleteDC(hdcMem);
EndPaint(hwndDlg, &ps);
case WM_DESTROY:
{
- PDISPLAY_DEVICE_ENTRY Current = DisplayDeviceList;
+ PDISPLAY_DEVICE_ENTRY Current = pGlobalData->DisplayDeviceList;
while (Current != NULL)
{
PDISPLAY_DEVICE_ENTRY Next = Current->Flink;
Current = Next;
}
- DeleteObject(hBitmap);
+ DeleteObject(pGlobalData->hBitmap);
+
+ HeapFree(GetProcessHeap(), 0, pGlobalData);
}
}
return FALSE;