2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: lib/cpl/desk/settings.c
5 * PURPOSE: Settings property page
7 * PROGRAMMERS: Trevor McCort (lycan359@gmail.com)
8 * Hervé Poussineau (hpoussin@reactos.org)
14 typedef struct _GLOBAL_DATA
16 PDISPLAY_DEVICE_ENTRY DisplayDeviceList
;
17 PDISPLAY_DEVICE_ENTRY CurrentDisplayDevice
;
18 HBITMAP hSpectrumBitmaps
[NUM_SPECTRUM_BITMAPS
];
19 int cxSource
[NUM_SPECTRUM_BITMAPS
];
20 int cySource
[NUM_SPECTRUM_BITMAPS
];
21 } GLOBAL_DATA
, *PGLOBAL_DATA
;
25 UpdateDisplay(IN HWND hwndDlg
, PGLOBAL_DATA pGlobalData
, IN BOOL bUpdateThumb
)
31 LoadString(hApplet
, IDS_PIXEL
, Pixel
, sizeof(Pixel
) / sizeof(TCHAR
));
32 _stprintf(Buffer
, Pixel
, pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
, pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
, Pixel
);
33 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION_TEXT
, WM_SETTEXT
, 0, (LPARAM
)Buffer
);
35 for (index
= 0; index
< pGlobalData
->CurrentDisplayDevice
->ResolutionsCount
; index
++)
37 if (pGlobalData
->CurrentDisplayDevice
->Resolutions
[index
].dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
&&
38 pGlobalData
->CurrentDisplayDevice
->Resolutions
[index
].dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
)
41 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_SETPOS
, TRUE
, index
);
45 if (LoadString(hApplet
, (2900 + pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
), Buffer
, sizeof(Buffer
) / sizeof(TCHAR
)))
46 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_SELECTSTRING
, (WPARAM
)-1, (LPARAM
)Buffer
);
49 static PSETTINGS_ENTRY
50 GetPossibleSettings(IN LPCTSTR DeviceName
, OUT DWORD
* pSettingsCount
, OUT PSETTINGS_ENTRY
* CurrentSettings
)
56 PSETTINGS_ENTRY Settings
= NULL
;
58 PSETTINGS_ENTRY Current
;
59 DWORD bpp
, xres
, yres
, checkbpp
;
62 /* Get current settings */
63 *CurrentSettings
= NULL
;
64 hDC
= CreateIC(NULL
, DeviceName
, NULL
, NULL
);
65 bpp
= GetDeviceCaps(hDC
, PLANES
);
66 bpp
*= GetDeviceCaps(hDC
, BITSPIXEL
);
67 xres
= GetDeviceCaps(hDC
, HORZRES
);
68 yres
= GetDeviceCaps(hDC
, VERTRES
);
71 /* List all settings */
72 devmode
.dmSize
= (WORD
)sizeof(DEVMODE
);
73 devmode
.dmDriverExtra
= 0;
75 if (!EnumDisplaySettingsEx(DeviceName
, ENUM_CURRENT_SETTINGS
, &devmode
, dwFlags
))
78 curDispFreq
= devmode
.dmDisplayFrequency
;
80 while (EnumDisplaySettingsEx(DeviceName
, iMode
, &devmode
, dwFlags
))
82 if ((devmode
.dmBitsPerPel
== 4 ||
83 devmode
.dmBitsPerPel
== 8 ||
84 devmode
.dmBitsPerPel
== 16 ||
85 devmode
.dmBitsPerPel
== 24 ||
86 devmode
.dmBitsPerPel
== 32) &&
87 devmode
.dmDisplayFrequency
== curDispFreq
)
94 if (devmode
.dmPelsWidth
< 640 ||
95 devmode
.dmPelsHeight
< 480 || checkbpp
== 0)
101 Current
= HeapAlloc(GetProcessHeap(), 0, sizeof(SETTINGS_ENTRY
));
104 /* Sort resolutions by increasing height, and BPP */
105 PSETTINGS_ENTRY Previous
= NULL
;
106 PSETTINGS_ENTRY Next
= Settings
;
107 Current
->dmPelsWidth
= devmode
.dmPelsWidth
;
108 Current
->dmPelsHeight
= devmode
.dmPelsHeight
;
109 Current
->dmBitsPerPel
= devmode
.dmBitsPerPel
;
110 while (Next
!= NULL
&& (
111 Next
->dmPelsWidth
< Current
->dmPelsWidth
||
112 (Next
->dmPelsWidth
== Current
->dmPelsWidth
&& Next
->dmPelsHeight
< Current
->dmPelsHeight
) ||
113 (Next
->dmPelsHeight
== Current
->dmPelsHeight
&&
114 Next
->dmPelsWidth
== Current
->dmPelsWidth
&&
115 Next
->dmBitsPerPel
< Current
->dmBitsPerPel
)))
120 Current
->Blink
= Previous
;
121 Current
->Flink
= Next
;
122 if (Previous
== NULL
)
125 Previous
->Flink
= Current
;
127 Next
->Blink
= Current
;
128 if (devmode
.dmPelsWidth
== xres
&& devmode
.dmPelsHeight
== yres
&& devmode
.dmBitsPerPel
== bpp
)
130 *CurrentSettings
= Current
;
137 *pSettingsCount
= NbSettings
;
142 AddDisplayDevice(IN PGLOBAL_DATA pGlobalData
, IN
const DISPLAY_DEVICE
*DisplayDevice
)
144 PDISPLAY_DEVICE_ENTRY newEntry
= NULL
;
145 LPTSTR description
= NULL
;
149 DWORD descriptionSize
, nameSize
, keySize
, devidSize
;
150 PSETTINGS_ENTRY Current
;
151 DWORD ResolutionsCount
= 1;
154 newEntry
= HeapAlloc(GetProcessHeap(), 0, sizeof(DISPLAY_DEVICE_ENTRY
));
155 memset(newEntry
, 0, sizeof(DISPLAY_DEVICE_ENTRY
));
156 if (!newEntry
) goto ByeBye
;
158 newEntry
->Settings
= GetPossibleSettings(DisplayDevice
->DeviceName
, &newEntry
->SettingsCount
, &newEntry
->CurrentSettings
);
159 if (!newEntry
->Settings
) goto ByeBye
;
161 newEntry
->InitialSettings
.dmPelsWidth
= newEntry
->CurrentSettings
->dmPelsWidth
;
162 newEntry
->InitialSettings
.dmPelsHeight
= newEntry
->CurrentSettings
->dmPelsHeight
;
163 newEntry
->InitialSettings
.dmBitsPerPel
= newEntry
->CurrentSettings
->dmBitsPerPel
;
165 /* Count different resolutions */
166 for (Current
= newEntry
->Settings
; Current
!= NULL
; Current
= Current
->Flink
)
168 if (Current
->Flink
!= NULL
&&
169 ((Current
->dmPelsWidth
!= Current
->Flink
->dmPelsWidth
) &&
170 (Current
->dmPelsHeight
!= Current
->Flink
->dmPelsHeight
)))
176 newEntry
->Resolutions
= HeapAlloc(GetProcessHeap(), 0, ResolutionsCount
* sizeof(RESOLUTION_INFO
));
177 if (!newEntry
->Resolutions
) goto ByeBye
;
179 newEntry
->ResolutionsCount
= ResolutionsCount
;
181 /* Fill resolutions infos */
182 for (Current
= newEntry
->Settings
, i
= 0; Current
!= NULL
; Current
= Current
->Flink
)
184 if (Current
->Flink
== NULL
||
185 (Current
->Flink
!= NULL
&&
186 ((Current
->dmPelsWidth
!= Current
->Flink
->dmPelsWidth
) &&
187 (Current
->dmPelsHeight
!= Current
->Flink
->dmPelsHeight
))))
189 newEntry
->Resolutions
[i
].dmPelsWidth
= Current
->dmPelsWidth
;
190 newEntry
->Resolutions
[i
].dmPelsHeight
= Current
->dmPelsHeight
;
194 descriptionSize
= (_tcslen(DisplayDevice
->DeviceString
) + 1) * sizeof(TCHAR
);
195 description
= HeapAlloc(GetProcessHeap(), 0, descriptionSize
);
196 if (!description
) goto ByeBye
;
198 nameSize
= (_tcslen(DisplayDevice
->DeviceName
) + 1) * sizeof(TCHAR
);
199 name
= HeapAlloc(GetProcessHeap(), 0, nameSize
);
200 if (!name
) goto ByeBye
;
202 keySize
= (_tcslen(DisplayDevice
->DeviceKey
) + 1) * sizeof(TCHAR
);
203 key
= HeapAlloc(GetProcessHeap(), 0, keySize
);
204 if (!key
) goto ByeBye
;
206 devidSize
= (_tcslen(DisplayDevice
->DeviceID
) + 1) * sizeof(TCHAR
);
207 devid
= HeapAlloc(GetProcessHeap(), 0, devidSize
);
208 if (!devid
) goto ByeBye
;
210 memcpy(description
, DisplayDevice
->DeviceString
, descriptionSize
);
211 memcpy(name
, DisplayDevice
->DeviceName
, nameSize
);
212 memcpy(key
, DisplayDevice
->DeviceKey
, keySize
);
213 memcpy(devid
, DisplayDevice
->DeviceID
, devidSize
);
214 newEntry
->DeviceDescription
= description
;
215 newEntry
->DeviceName
= name
;
216 newEntry
->DeviceKey
= key
;
217 newEntry
->DeviceID
= devid
;
218 newEntry
->DeviceStateFlags
= DisplayDevice
->StateFlags
;
219 newEntry
->Flink
= pGlobalData
->DisplayDeviceList
;
220 pGlobalData
->DisplayDeviceList
= newEntry
;
224 if (newEntry
!= NULL
)
226 if (newEntry
->Settings
!= NULL
)
228 Current
= newEntry
->Settings
;
229 while (Current
!= NULL
)
231 PSETTINGS_ENTRY Next
= Current
->Flink
;
232 HeapFree(GetProcessHeap(), 0, Current
);
236 if (newEntry
->Resolutions
!= NULL
)
237 HeapFree(GetProcessHeap(), 0, newEntry
->Resolutions
);
238 HeapFree(GetProcessHeap(), 0, newEntry
);
240 if (description
!= NULL
)
241 HeapFree(GetProcessHeap(), 0, description
);
243 HeapFree(GetProcessHeap(), 0, name
);
245 HeapFree(GetProcessHeap(), 0, key
);
250 OnDisplayDeviceChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
, IN PDISPLAY_DEVICE_ENTRY pDeviceEntry
)
252 PSETTINGS_ENTRY Current
;
255 pGlobalData
->CurrentDisplayDevice
= pDeviceEntry
; /* Update global variable */
257 /* Fill color depths combo box */
258 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_RESETCONTENT
, 0, 0);
259 for (Current
= pDeviceEntry
->Settings
; Current
!= NULL
; Current
= Current
->Flink
)
262 if (LoadString(hApplet
, (2900 + Current
->dmBitsPerPel
), Buffer
, sizeof(Buffer
) / sizeof(TCHAR
)))
264 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_FINDSTRINGEXACT
, (WPARAM
)-1, (LPARAM
)Buffer
);
265 if (index
== (DWORD
)CB_ERR
)
267 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_ADDSTRING
, 0, (LPARAM
)Buffer
);
268 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_SETITEMDATA
, index
, Current
->dmBitsPerPel
);
273 /* Fill resolutions slider */
274 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_CLEARTICS
, TRUE
, 0);
275 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_SETRANGE
, TRUE
, MAKELONG(0, pDeviceEntry
->ResolutionsCount
- 1));
277 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
281 OnInitDialog(IN HWND hwndDlg
)
287 DISPLAY_DEVICE displayDevice
;
288 PGLOBAL_DATA pGlobalData
;
290 pGlobalData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(GLOBAL_DATA
));
291 if (pGlobalData
== NULL
)
294 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pGlobalData
);
296 /* Get video cards list */
297 displayDevice
.cb
= (DWORD
)sizeof(DISPLAY_DEVICE
);
298 while (EnumDisplayDevices(NULL
, iDevNum
, &displayDevice
, 0x1))
300 if ((displayDevice
.StateFlags
& DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
) != 0)
302 if (AddDisplayDevice(pGlobalData
, &displayDevice
))
309 /* No adapter found */
310 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_BPP
), FALSE
);
311 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION
), FALSE
);
312 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION_TEXT
), FALSE
);
313 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_ADVANCED
), FALSE
);
315 else if (Result
== 1)
317 MONSL_MONINFO monitors
;
319 /* Single video adapter */
320 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pGlobalData
->DisplayDeviceList
->DeviceDescription
);
321 OnDisplayDeviceChanged(hwndDlg
, pGlobalData
, pGlobalData
->DisplayDeviceList
);
323 monitors
.Position
.x
= monitors
.Position
.y
= 0;
324 monitors
.Size
.cx
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
325 monitors
.Size
.cy
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
327 SendDlgItemMessage(hwndDlg
,
329 MSLM_SETMONITORSINFO
,
333 else /* FIXME: incomplete! */
335 PMONSL_MONINFO pMonitors
;
338 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pGlobalData
->DisplayDeviceList
->DeviceDescription
);
339 OnDisplayDeviceChanged(hwndDlg
, pGlobalData
, pGlobalData
->DisplayDeviceList
);
341 pMonitors
= (PMONSL_MONINFO
)HeapAlloc(GetProcessHeap(), 0, sizeof(MONSL_MONINFO
) * Result
);
345 for (i
= 0; i
< Result
; i
++)
347 pMonitors
[i
].Position
.x
= hack
* i
;
348 pMonitors
[i
].Position
.y
= 0;
349 pMonitors
[i
].Size
.cx
= pGlobalData
->DisplayDeviceList
->CurrentSettings
->dmPelsWidth
;
350 pMonitors
[i
].Size
.cy
= pGlobalData
->DisplayDeviceList
->CurrentSettings
->dmPelsHeight
;
351 pMonitors
[i
].Flags
= 0;
354 SendDlgItemMessage(hwndDlg
,
356 MSLM_SETMONITORSINFO
,
360 HeapFree(GetProcessHeap(), 0, pMonitors
);
364 /* Initialize the color spectrum bitmaps */
365 for(i
= 0; i
< NUM_SPECTRUM_BITMAPS
; i
++)
367 pGlobalData
->hSpectrumBitmaps
[i
] = LoadImageW(hApplet
, MAKEINTRESOURCEW(IDB_SPECTRUM_4
+ i
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
369 if (pGlobalData
->hSpectrumBitmaps
[i
] != NULL
)
371 if (GetObjectW(pGlobalData
->hSpectrumBitmaps
[i
], sizeof(BITMAP
), &bitmap
) != 0)
373 pGlobalData
->cxSource
[i
] = bitmap
.bmWidth
;
374 pGlobalData
->cySource
[i
] = bitmap
.bmHeight
;
378 pGlobalData
->cxSource
[i
] = 0;
379 pGlobalData
->cySource
[i
] = 0;
385 /* Get the ID for GLOBAL_DATA::hSpectrumBitmaps */
387 ShowColorSpectrum(IN HDC hDC
, IN LPRECT client
, IN DWORD BitsPerPel
, IN PGLOBAL_DATA pGlobalData
)
392 hdcMem
= CreateCompatibleDC(hDC
);
399 case 4: iBitmap
= 0; break;
400 case 8: iBitmap
= 1; break;
401 default: iBitmap
= 2;
404 SelectObject(hdcMem
, pGlobalData
->hSpectrumBitmaps
[iBitmap
]);
406 client
->left
, client
->top
, client
->right
- client
->left
, client
->bottom
- client
->top
,
408 pGlobalData
->cxSource
[iBitmap
],
409 pGlobalData
->cySource
[iBitmap
], SRCCOPY
);
414 OnBPPChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
)
416 /* if new BPP is not compatible with resolution:
417 * 1) try to find the nearest smaller matching resolution
418 * 2) otherwise, get the nearest bigger resolution
420 PSETTINGS_ENTRY Current
;
421 DWORD dmNewBitsPerPel
;
424 HWND hSpectrumControl
;
427 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETCURSEL
, 0, 0);
428 dmNewBitsPerPel
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETITEMDATA
, index
, 0);
430 /* Show a new spectrum bitmap */
431 hSpectrumControl
= GetDlgItem(hwndDlg
, IDC_SETTINGS_SPECTRUM
);
432 hSpectrumDC
= GetDC(hSpectrumControl
);
433 GetClientRect(hSpectrumControl
, &client
);
434 ShowColorSpectrum(hSpectrumDC
, &client
, dmNewBitsPerPel
, pGlobalData
);
436 /* find if new parameters are valid */
437 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
;
438 if (dmNewBitsPerPel
== Current
->dmBitsPerPel
)
444 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
446 if (dmNewBitsPerPel
< Current
->dmBitsPerPel
)
448 Current
= Current
->Blink
;
449 while (Current
!= NULL
)
451 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
452 && Current
->dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
453 && Current
->dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
455 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
456 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
459 Current
= Current
->Blink
;
464 Current
= Current
->Flink
;
465 while (Current
!= NULL
)
467 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
468 && Current
->dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
469 && Current
->dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
471 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
472 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
475 Current
= Current
->Flink
;
479 /* search smaller resolution compatible with current color depth */
480 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
481 while (Current
!= NULL
)
483 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
485 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
486 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
489 Current
= Current
->Blink
;
492 /* search bigger resolution compatible with current color depth */
493 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
494 while (Current
!= NULL
)
496 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
498 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
499 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
502 Current
= Current
->Flink
;
505 /* we shouldn't go there */
509 OnResolutionChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
, IN DWORD NewPosition
,
510 IN BOOL bUpdateThumb
)
512 /* if new resolution is not compatible with color depth:
513 * 1) try to find the nearest bigger matching color depth
514 * 2) otherwise, get the nearest smaller color depth
516 PSETTINGS_ENTRY Current
;
517 DWORD dmNewPelsHeight
= pGlobalData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsHeight
;
518 DWORD dmNewPelsWidth
= pGlobalData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsWidth
;
520 /* find if new parameters are valid */
521 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
;
522 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
528 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
530 if (dmNewPelsHeight
< Current
->dmPelsHeight
)
532 Current
= Current
->Blink
;
533 while (Current
!= NULL
)
535 if (Current
->dmPelsHeight
== dmNewPelsHeight
536 && Current
->dmPelsWidth
== dmNewPelsWidth
537 && Current
->dmBitsPerPel
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
539 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
540 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
543 Current
= Current
->Blink
;
548 Current
= Current
->Flink
;
549 while (Current
!= NULL
)
551 if (Current
->dmPelsHeight
== dmNewPelsHeight
552 && Current
->dmPelsWidth
== dmNewPelsWidth
553 && Current
->dmBitsPerPel
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
555 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
556 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
559 Current
= Current
->Flink
;
563 /* search bigger color depth compatible with current resolution */
564 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
565 while (Current
!= NULL
)
567 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
569 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
570 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
573 Current
= Current
->Flink
;
576 /* search smaller color depth compatible with current resolution */
577 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
578 while (Current
!= NULL
)
580 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
582 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
583 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
586 Current
= Current
->Blink
;
589 /* we shouldn't go there */
592 /* Property sheet page callback */
594 SettingsPageCallbackProc(HWND hwnd
, UINT uMsg
, LPPROPSHEETPAGE ppsp
)
601 Ret
= RegisterMonitorSelectionControl(hApplet
);
605 UnregisterMonitorSelectionControl(hApplet
);
612 /* Property page dialog callback */
614 SettingsPageProc(IN HWND hwndDlg
, IN UINT uMsg
, IN WPARAM wParam
, IN LPARAM lParam
)
616 PGLOBAL_DATA pGlobalData
;
618 pGlobalData
= (PGLOBAL_DATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
624 OnInitDialog(hwndDlg
);
629 LPDRAWITEMSTRUCT lpDrawItem
;
630 lpDrawItem
= (LPDRAWITEMSTRUCT
) lParam
;
632 if (lpDrawItem
->CtlID
== IDC_SETTINGS_SPECTRUM
)
633 ShowColorSpectrum(lpDrawItem
->hDC
, &lpDrawItem
->rcItem
, pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
, pGlobalData
);
639 DWORD controlId
= LOWORD(wParam
);
640 DWORD command
= HIWORD(wParam
);
642 if (controlId
== IDC_SETTINGS_ADVANCED
&& command
== BN_CLICKED
)
643 DisplayAdvancedSettings(hwndDlg
, pGlobalData
->CurrentDisplayDevice
);
644 else if (controlId
== IDC_SETTINGS_BPP
&& command
== CBN_SELCHANGE
)
645 OnBPPChanged(hwndDlg
, pGlobalData
);
650 switch (LOWORD(wParam
))
660 DWORD newPosition
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_GETPOS
, 0, 0);
661 OnResolutionChanged(hwndDlg
, pGlobalData
, newPosition
, TRUE
);
666 OnResolutionChanged(hwndDlg
, pGlobalData
, HIWORD(wParam
), FALSE
);
673 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
674 if (lpnm
->code
== (UINT
)PSN_APPLY
)
676 if (pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
677 || pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
678 || pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
)
680 /* FIXME: Need to test changes */
681 /* Apply new settings */
684 RtlZeroMemory(&devmode
, sizeof(DEVMODE
));
685 devmode
.dmSize
= (WORD
)sizeof(DEVMODE
);
686 devmode
.dmPelsWidth
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
687 devmode
.dmPelsHeight
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
688 devmode
.dmBitsPerPel
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
689 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
| DM_BITSPERPEL
;
690 rc
= ChangeDisplaySettingsEx(
691 pGlobalData
->CurrentDisplayDevice
->DeviceName
,
698 case DISP_CHANGE_SUCCESSFUL
:
699 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
700 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
701 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
703 case DISP_CHANGE_FAILED
:
704 MessageBox(NULL
, TEXT("Failed to apply new settings..."), TEXT("Display settings"), MB_OK
| MB_ICONSTOP
);
706 case DISP_CHANGE_RESTART
:
707 MessageBox(NULL
, TEXT("You need to restart your computer to apply changes."), TEXT("Display settings"), MB_OK
| MB_ICONINFORMATION
);
710 MessageBox(NULL
, TEXT("Unknown error when applying new settings..."), TEXT("Display settings"), MB_OK
| MB_ICONSTOP
);
726 pt
.x
= (SHORT
)LOWORD(lParam
);
727 pt
.y
= (SHORT
)HIWORD(lParam
);
729 hwndMonSel
= GetDlgItem(hwndDlg
,
730 IDC_SETTINGS_MONSEL
);
731 if ((HWND
)wParam
== hwndMonSel
)
733 if (pt
.x
== -1 && pt
.y
== -1)
737 Index
= (INT
)SendMessage(hwndMonSel
,
743 (INT
)SendMessage(hwndMonSel
,
748 pt
.x
= rcMon
.left
+ ((rcMon
.right
- rcMon
.left
) / 2);
749 pt
.y
= rcMon
.top
+ ((rcMon
.bottom
- rcMon
.top
) / 2);
754 MapWindowPoints(hwndMonSel
,
762 MapWindowPoints(NULL
,
767 Index
= (INT
)SendMessage(hwndMonSel
,
775 hPopup
= LoadPopupMenu(hApplet
,
776 MAKEINTRESOURCE(IDM_MONITOR_MENU
));
779 /* FIXME: Enable/Disable menu items */
780 EnableMenuItem(hPopup
,
782 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
783 EnableMenuItem(hPopup
,
785 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
786 EnableMenuItem(hPopup
,
788 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
789 EnableMenuItem(hPopup
,
791 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
793 uiCmd
= (UINT
)TrackPopupMenu(hPopup
,
794 TPM_RETURNCMD
| TPM_RIGHTBUTTON
,
803 case ID_MENU_ATTACHED
:
804 case ID_MENU_PRIMARY
:
805 case ID_MENU_IDENTIFY
:
806 case ID_MENU_PROPERTIES
:
807 /* FIXME: Implement */
821 PDISPLAY_DEVICE_ENTRY Current
= pGlobalData
->DisplayDeviceList
;
823 while (Current
!= NULL
)
825 PDISPLAY_DEVICE_ENTRY Next
= Current
->Flink
;
826 PSETTINGS_ENTRY CurrentSettings
= Current
->Settings
;
827 while (CurrentSettings
!= NULL
)
829 PSETTINGS_ENTRY NextSettings
= CurrentSettings
->Flink
;
830 HeapFree(GetProcessHeap(), 0, CurrentSettings
);
831 CurrentSettings
= NextSettings
;
833 HeapFree(GetProcessHeap(), 0, Current
);
837 HeapFree(GetProcessHeap(), 0, pGlobalData
);
839 for (i
= 0; i
< NUM_SPECTRUM_BITMAPS
; i
++)
841 if (pGlobalData
->hSpectrumBitmaps
[i
])
842 DeleteObject(pGlobalData
->hSpectrumBitmaps
[i
]);