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
;
63 /* Get current settings */
64 *CurrentSettings
= NULL
;
65 hDC
= CreateIC(NULL
, DeviceName
, NULL
, NULL
);
66 bpp
= GetDeviceCaps(hDC
, PLANES
);
67 bpp
*= GetDeviceCaps(hDC
, BITSPIXEL
);
68 xres
= GetDeviceCaps(hDC
, HORZRES
);
69 yres
= GetDeviceCaps(hDC
, VERTRES
);
72 /* List all settings */
73 devmode
.dmSize
= (WORD
)sizeof(DEVMODE
);
74 devmode
.dmDriverExtra
= 0;
76 if (!EnumDisplaySettingsEx(DeviceName
, ENUM_CURRENT_SETTINGS
, &devmode
, dwFlags
))
79 curDispFreq
= devmode
.dmDisplayFrequency
;
81 while (EnumDisplaySettingsEx(DeviceName
, iMode
, &devmode
, dwFlags
))
83 if ((devmode
.dmBitsPerPel
==4 ||
84 devmode
.dmBitsPerPel
==8 ||
85 devmode
.dmBitsPerPel
==16 ||
86 devmode
.dmBitsPerPel
==24 ||
87 devmode
.dmBitsPerPel
==32) &&
88 devmode
.dmDisplayFrequency
==curDispFreq
)
95 if (devmode
.dmPelsWidth
< 640 ||
96 devmode
.dmPelsHeight
< 480 || checkbpp
== 0)
102 Current
= HeapAlloc(GetProcessHeap(), 0, sizeof(SETTINGS_ENTRY
));
105 /* Sort resolutions by increasing height, and BPP */
106 PSETTINGS_ENTRY Previous
= NULL
;
107 PSETTINGS_ENTRY Next
= Settings
;
108 Current
->dmPelsWidth
= devmode
.dmPelsWidth
;
109 Current
->dmPelsHeight
= devmode
.dmPelsHeight
;
110 Current
->dmBitsPerPel
= devmode
.dmBitsPerPel
;
111 while (Next
!= NULL
&& (
112 Next
->dmPelsWidth
< Current
->dmPelsWidth
||
113 (Next
->dmPelsWidth
== Current
->dmPelsWidth
&& Next
->dmPelsHeight
< Current
->dmPelsHeight
) ||
114 (Next
->dmPelsHeight
== Current
->dmPelsHeight
&&
115 Next
->dmPelsWidth
== Current
->dmPelsWidth
&&
116 Next
->dmBitsPerPel
< Current
->dmBitsPerPel
)))
121 Current
->Blink
= Previous
;
122 Current
->Flink
= Next
;
123 if (Previous
== NULL
)
126 Previous
->Flink
= Current
;
128 Next
->Blink
= Current
;
129 if (devmode
.dmPelsWidth
== xres
&& devmode
.dmPelsHeight
== yres
&& devmode
.dmBitsPerPel
== bpp
)
131 *CurrentSettings
= Current
;
138 *pSettingsCount
= NbSettings
;
143 AddDisplayDevice(IN PGLOBAL_DATA pGlobalData
, IN
const DISPLAY_DEVICE
*DisplayDevice
)
145 PDISPLAY_DEVICE_ENTRY newEntry
= NULL
;
146 LPTSTR description
= NULL
;
150 DWORD descriptionSize
, nameSize
, keySize
, devidSize
;
151 PSETTINGS_ENTRY Current
;
152 DWORD ResolutionsCount
= 1;
155 newEntry
= HeapAlloc(GetProcessHeap(), 0, sizeof(DISPLAY_DEVICE_ENTRY
));
156 memset(newEntry
, 0, sizeof(DISPLAY_DEVICE_ENTRY
));
157 if (!newEntry
) goto ByeBye
;
159 newEntry
->Settings
= GetPossibleSettings(DisplayDevice
->DeviceName
, &newEntry
->SettingsCount
, &newEntry
->CurrentSettings
);
160 if (!newEntry
->Settings
) goto ByeBye
;
162 newEntry
->InitialSettings
.dmPelsWidth
= newEntry
->CurrentSettings
->dmPelsWidth
;
163 newEntry
->InitialSettings
.dmPelsHeight
= newEntry
->CurrentSettings
->dmPelsHeight
;
164 newEntry
->InitialSettings
.dmBitsPerPel
= newEntry
->CurrentSettings
->dmBitsPerPel
;
166 /* Count different resolutions */
167 for (Current
= newEntry
->Settings
; Current
!= NULL
; Current
= Current
->Flink
)
169 if (Current
->Flink
!= NULL
&&
170 ((Current
->dmPelsWidth
!= Current
->Flink
->dmPelsWidth
) &&
171 (Current
->dmPelsHeight
!= Current
->Flink
->dmPelsHeight
)))
177 newEntry
->Resolutions
= HeapAlloc(GetProcessHeap(), 0, ResolutionsCount
* sizeof(RESOLUTION_INFO
));
178 if (!newEntry
->Resolutions
) goto ByeBye
;
180 newEntry
->ResolutionsCount
= ResolutionsCount
;
182 /* Fill resolutions infos */
183 for (Current
= newEntry
->Settings
, i
= 0; Current
!= NULL
; Current
= Current
->Flink
)
185 if (Current
->Flink
== NULL
||
186 (Current
->Flink
!= NULL
&&
187 ((Current
->dmPelsWidth
!= Current
->Flink
->dmPelsWidth
) &&
188 (Current
->dmPelsHeight
!= Current
->Flink
->dmPelsHeight
))))
190 newEntry
->Resolutions
[i
].dmPelsWidth
= Current
->dmPelsWidth
;
191 newEntry
->Resolutions
[i
].dmPelsHeight
= Current
->dmPelsHeight
;
195 descriptionSize
= (_tcslen(DisplayDevice
->DeviceString
) + 1) * sizeof(TCHAR
);
196 description
= HeapAlloc(GetProcessHeap(), 0, descriptionSize
);
197 if (!description
) goto ByeBye
;
199 nameSize
= (_tcslen(DisplayDevice
->DeviceName
) + 1) * sizeof(TCHAR
);
200 name
= HeapAlloc(GetProcessHeap(), 0, nameSize
);
201 if (!name
) goto ByeBye
;
203 keySize
= (_tcslen(DisplayDevice
->DeviceKey
) + 1) * sizeof(TCHAR
);
204 key
= HeapAlloc(GetProcessHeap(), 0, keySize
);
205 if (!key
) goto ByeBye
;
207 devidSize
= (_tcslen(DisplayDevice
->DeviceID
) + 1) * sizeof(TCHAR
);
208 devid
= HeapAlloc(GetProcessHeap(), 0, devidSize
);
209 if (!devid
) goto ByeBye
;
211 memcpy(description
, DisplayDevice
->DeviceString
, descriptionSize
);
212 memcpy(name
, DisplayDevice
->DeviceName
, nameSize
);
213 memcpy(key
, DisplayDevice
->DeviceKey
, keySize
);
214 memcpy(devid
, DisplayDevice
->DeviceID
, devidSize
);
215 newEntry
->DeviceDescription
= description
;
216 newEntry
->DeviceName
= name
;
217 newEntry
->DeviceKey
= key
;
218 newEntry
->DeviceID
= devid
;
219 newEntry
->DeviceStateFlags
= DisplayDevice
->StateFlags
;
220 newEntry
->Flink
= pGlobalData
->DisplayDeviceList
;
221 pGlobalData
->DisplayDeviceList
= newEntry
;
225 if (newEntry
!= NULL
)
227 if (newEntry
->Settings
!= NULL
)
229 Current
= newEntry
->Settings
;
230 while (Current
!= NULL
)
232 PSETTINGS_ENTRY Next
= Current
->Flink
;
233 HeapFree(GetProcessHeap(), 0, Current
);
237 if (newEntry
->Resolutions
!= NULL
)
238 HeapFree(GetProcessHeap(), 0, newEntry
->Resolutions
);
239 HeapFree(GetProcessHeap(), 0, newEntry
);
241 if (description
!= NULL
)
242 HeapFree(GetProcessHeap(), 0, description
);
244 HeapFree(GetProcessHeap(), 0, name
);
246 HeapFree(GetProcessHeap(), 0, key
);
248 HeapFree(GetProcessHeap(), 0, devid
);
253 OnDisplayDeviceChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
, IN PDISPLAY_DEVICE_ENTRY pDeviceEntry
)
255 PSETTINGS_ENTRY Current
;
258 pGlobalData
->CurrentDisplayDevice
= pDeviceEntry
; /* Update global variable */
260 /* Fill color depths combo box */
261 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_RESETCONTENT
, 0, 0);
262 for (Current
= pDeviceEntry
->Settings
; Current
!= NULL
; Current
= Current
->Flink
)
265 if (LoadString(hApplet
, (2900 + Current
->dmBitsPerPel
), Buffer
, sizeof(Buffer
) / sizeof(TCHAR
)))
267 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_FINDSTRINGEXACT
, (WPARAM
)-1, (LPARAM
)Buffer
);
268 if (index
== (DWORD
)CB_ERR
)
270 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_ADDSTRING
, 0, (LPARAM
)Buffer
);
271 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_SETITEMDATA
, index
, Current
->dmBitsPerPel
);
276 /* Fill resolutions slider */
277 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_CLEARTICS
, TRUE
, 0);
278 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_SETRANGE
, TRUE
, MAKELONG(0, pDeviceEntry
->ResolutionsCount
- 1));
280 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
284 OnInitDialog(IN HWND hwndDlg
)
290 DISPLAY_DEVICE displayDevice
;
291 PGLOBAL_DATA pGlobalData
;
293 pGlobalData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(GLOBAL_DATA
));
294 if (pGlobalData
== NULL
)
297 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pGlobalData
);
299 /* Get video cards list */
300 displayDevice
.cb
= (DWORD
)sizeof(DISPLAY_DEVICE
);
301 while (EnumDisplayDevices(NULL
, iDevNum
, &displayDevice
, 0x1))
303 if ((displayDevice
.StateFlags
& DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
) != 0)
305 if (AddDisplayDevice(pGlobalData
, &displayDevice
))
312 /* No adapter found */
313 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_BPP
), FALSE
);
314 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION
), FALSE
);
315 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION_TEXT
), FALSE
);
316 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_ADVANCED
), FALSE
);
318 else if (Result
== 1)
320 MONSL_MONINFO monitors
;
322 /* Single video adapter */
323 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pGlobalData
->DisplayDeviceList
->DeviceDescription
);
324 OnDisplayDeviceChanged(hwndDlg
, pGlobalData
, pGlobalData
->DisplayDeviceList
);
326 monitors
.Position
.x
= monitors
.Position
.y
= 0;
327 monitors
.Size
.cx
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
328 monitors
.Size
.cy
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
330 SendDlgItemMessage(hwndDlg
,
332 MSLM_SETMONITORSINFO
,
336 else /* FIXME: incomplete! */
338 PMONSL_MONINFO pMonitors
;
341 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pGlobalData
->DisplayDeviceList
->DeviceDescription
);
342 OnDisplayDeviceChanged(hwndDlg
, pGlobalData
, pGlobalData
->DisplayDeviceList
);
344 pMonitors
= (PMONSL_MONINFO
)HeapAlloc(GetProcessHeap(), 0, sizeof(MONSL_MONINFO
) * Result
);
348 for (i
= 0; i
< Result
; i
++)
350 pMonitors
[i
].Position
.x
= hack
* i
;
351 pMonitors
[i
].Position
.y
= 0;
352 pMonitors
[i
].Size
.cx
= pGlobalData
->DisplayDeviceList
->CurrentSettings
->dmPelsWidth
;
353 pMonitors
[i
].Size
.cy
= pGlobalData
->DisplayDeviceList
->CurrentSettings
->dmPelsHeight
;
354 pMonitors
[i
].Flags
= 0;
357 SendDlgItemMessage(hwndDlg
,
359 MSLM_SETMONITORSINFO
,
363 HeapFree(GetProcessHeap(), 0, pMonitors
);
367 /* Initialize the color spectrum bitmaps */
368 for(i
= 0; i
< NUM_SPECTRUM_BITMAPS
; i
++)
370 pGlobalData
->hSpectrumBitmaps
[i
] = LoadImageW(hApplet
, MAKEINTRESOURCEW(IDB_SPECTRUM_4
+ i
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
372 if (pGlobalData
->hSpectrumBitmaps
[i
] != NULL
)
374 GetObjectW(pGlobalData
->hSpectrumBitmaps
[i
], sizeof(BITMAP
), &bitmap
);
376 pGlobalData
->cxSource
[i
] = bitmap
.bmWidth
;
377 pGlobalData
->cySource
[i
] = bitmap
.bmHeight
;
382 /* Get the ID for GLOBAL_DATA::hSpectrumBitmaps */
384 ShowColorSpectrum(IN HDC hDC
, IN LPRECT client
, IN DWORD BitsPerPel
, IN PGLOBAL_DATA pGlobalData
)
387 hdcMem
= CreateCompatibleDC(hDC
);
395 case 4: iBitmap
= 0; break;
396 case 8: iBitmap
= 1; break;
397 default: iBitmap
= 2;
400 SelectObject(hdcMem
, pGlobalData
->hSpectrumBitmaps
[iBitmap
]);
401 StretchBlt(hDC
, client
->left
, client
->top
, client
->right
- client
->left
,
402 client
->bottom
- client
->top
, hdcMem
, 0, 0,
403 pGlobalData
->cxSource
[iBitmap
], pGlobalData
->cySource
[iBitmap
], SRCCOPY
);
409 OnBPPChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
)
411 /* if new BPP is not compatible with resolution:
412 * 1) try to find the nearest smaller matching resolution
413 * 2) otherwise, get the nearest bigger resolution
415 PSETTINGS_ENTRY Current
;
416 DWORD dmNewBitsPerPel
;
419 HWND hSpectrumControl
;
422 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETCURSEL
, 0, 0);
423 dmNewBitsPerPel
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETITEMDATA
, index
, 0);
425 /* Show a new spectrum bitmap */
426 hSpectrumControl
= GetDlgItem(hwndDlg
, IDC_SETTINGS_SPECTRUM
);
427 hSpectrumDC
= GetDC(hSpectrumControl
);
428 GetClientRect(hSpectrumControl
, &client
);
429 ShowColorSpectrum(hSpectrumDC
, &client
, dmNewBitsPerPel
, pGlobalData
);
431 /* find if new parameters are valid */
432 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
;
433 if (dmNewBitsPerPel
== Current
->dmBitsPerPel
)
439 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
441 if (dmNewBitsPerPel
< Current
->dmBitsPerPel
)
443 Current
= Current
->Blink
;
444 while (Current
!= NULL
)
446 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
447 && Current
->dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
448 && Current
->dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
450 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
451 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
454 Current
= Current
->Blink
;
459 Current
= Current
->Flink
;
460 while (Current
!= NULL
)
462 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
463 && Current
->dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
464 && Current
->dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
466 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
467 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
470 Current
= Current
->Flink
;
474 /* search smaller resolution compatible with current color depth */
475 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
476 while (Current
!= NULL
)
478 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
480 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
481 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
484 Current
= Current
->Blink
;
487 /* search bigger resolution compatible with current color depth */
488 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
489 while (Current
!= NULL
)
491 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
493 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
494 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
497 Current
= Current
->Flink
;
500 /* we shouldn't go there */
504 OnResolutionChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
, IN DWORD NewPosition
,
505 IN BOOL bUpdateThumb
)
507 /* if new resolution is not compatible with color depth:
508 * 1) try to find the nearest bigger matching color depth
509 * 2) otherwise, get the nearest smaller color depth
511 PSETTINGS_ENTRY Current
;
512 DWORD dmNewPelsHeight
= pGlobalData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsHeight
;
513 DWORD dmNewPelsWidth
= pGlobalData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsWidth
;
515 /* find if new parameters are valid */
516 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
;
517 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
523 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
525 if (dmNewPelsHeight
< Current
->dmPelsHeight
)
527 Current
= Current
->Blink
;
528 while (Current
!= NULL
)
530 if (Current
->dmPelsHeight
== dmNewPelsHeight
531 && Current
->dmPelsWidth
== dmNewPelsWidth
532 && Current
->dmBitsPerPel
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
534 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
535 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
538 Current
= Current
->Blink
;
543 Current
= Current
->Flink
;
544 while (Current
!= NULL
)
546 if (Current
->dmPelsHeight
== dmNewPelsHeight
547 && Current
->dmPelsWidth
== dmNewPelsWidth
548 && Current
->dmBitsPerPel
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
550 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
551 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
554 Current
= Current
->Flink
;
558 /* search bigger color depth compatible with current resolution */
559 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
560 while (Current
!= NULL
)
562 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
564 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
565 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
568 Current
= Current
->Flink
;
571 /* search smaller color depth compatible with current resolution */
572 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
573 while (Current
!= NULL
)
575 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
577 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
578 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
581 Current
= Current
->Blink
;
584 /* we shouldn't go there */
587 /* Property sheet page callback */
589 SettingsPageCallbackProc(HWND hwnd
, UINT uMsg
, LPPROPSHEETPAGE ppsp
)
596 Ret
= RegisterMonitorSelectionControl(hApplet
);
600 UnregisterMonitorSelectionControl(hApplet
);
607 /* Property page dialog callback */
609 SettingsPageProc(IN HWND hwndDlg
, IN UINT uMsg
, IN WPARAM wParam
, IN LPARAM lParam
)
611 PGLOBAL_DATA pGlobalData
;
613 pGlobalData
= (PGLOBAL_DATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
620 OnInitDialog(hwndDlg
);
625 LPDRAWITEMSTRUCT lpDrawItem
;
626 lpDrawItem
= (LPDRAWITEMSTRUCT
) lParam
;
628 if(lpDrawItem
->CtlID
== IDC_SETTINGS_SPECTRUM
)
629 ShowColorSpectrum(lpDrawItem
->hDC
, &lpDrawItem
->rcItem
, pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
, pGlobalData
);
635 DWORD controlId
= LOWORD(wParam
);
636 DWORD command
= HIWORD(wParam
);
638 if (controlId
== IDC_SETTINGS_ADVANCED
&& command
== BN_CLICKED
)
639 DisplayAdvancedSettings(hwndDlg
, pGlobalData
->CurrentDisplayDevice
);
640 else if (controlId
== IDC_SETTINGS_BPP
&& command
== CBN_SELCHANGE
)
641 OnBPPChanged(hwndDlg
, pGlobalData
);
646 switch (LOWORD(wParam
))
656 DWORD newPosition
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_GETPOS
, 0, 0);
657 OnResolutionChanged(hwndDlg
, pGlobalData
, newPosition
, TRUE
);
662 OnResolutionChanged(hwndDlg
, pGlobalData
, HIWORD(wParam
), FALSE
);
669 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
670 if (lpnm
->code
== (UINT
)PSN_APPLY
)
672 if (pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
673 || pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
674 || pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
)
676 /* FIXME: Need to test changes */
677 /* Apply new settings */
680 RtlZeroMemory(&devmode
, sizeof(DEVMODE
));
681 devmode
.dmSize
= (WORD
)sizeof(DEVMODE
);
682 devmode
.dmPelsWidth
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
683 devmode
.dmPelsHeight
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
684 devmode
.dmBitsPerPel
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
685 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
| DM_BITSPERPEL
;
686 rc
= ChangeDisplaySettingsEx(
687 pGlobalData
->CurrentDisplayDevice
->DeviceName
,
694 case DISP_CHANGE_SUCCESSFUL
:
695 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
696 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
697 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
699 case DISP_CHANGE_FAILED
:
700 MessageBox(NULL
, TEXT("Failed to apply new settings..."), TEXT("Display settings"), MB_OK
| MB_ICONSTOP
);
702 case DISP_CHANGE_RESTART
:
703 MessageBox(NULL
, TEXT("You need to restart your computer to apply changes."), TEXT("Display settings"), MB_OK
| MB_ICONINFORMATION
);
706 MessageBox(NULL
, TEXT("Unknown error when applying new settings..."), TEXT("Display settings"), MB_OK
| MB_ICONSTOP
);
722 pt
.x
= (SHORT
)LOWORD(lParam
);
723 pt
.y
= (SHORT
)HIWORD(lParam
);
725 hwndMonSel
= GetDlgItem(hwndDlg
,
726 IDC_SETTINGS_MONSEL
);
727 if ((HWND
)wParam
== hwndMonSel
)
729 if (pt
.x
== -1 && pt
.y
== -1)
733 Index
= (INT
)SendMessage(hwndMonSel
,
739 (INT
)SendMessage(hwndMonSel
,
744 pt
.x
= rcMon
.left
+ ((rcMon
.right
- rcMon
.left
) / 2);
745 pt
.y
= rcMon
.top
+ ((rcMon
.bottom
- rcMon
.top
) / 2);
750 MapWindowPoints(hwndMonSel
,
758 MapWindowPoints(NULL
,
763 Index
= (INT
)SendMessage(hwndMonSel
,
771 hPopup
= LoadPopupMenu(hApplet
,
772 MAKEINTRESOURCE(IDM_MONITOR_MENU
));
775 /* FIXME: Enable/Disable menu items */
776 EnableMenuItem(hPopup
,
778 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
779 EnableMenuItem(hPopup
,
781 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
782 EnableMenuItem(hPopup
,
784 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
785 EnableMenuItem(hPopup
,
787 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
789 uiCmd
= (UINT
)TrackPopupMenu(hPopup
,
790 TPM_RETURNCMD
| TPM_RIGHTBUTTON
,
799 case ID_MENU_ATTACHED
:
800 case ID_MENU_PRIMARY
:
801 case ID_MENU_IDENTIFY
:
802 case ID_MENU_PROPERTIES
:
803 /* FIXME: Implement */
818 PDISPLAY_DEVICE_ENTRY Current
= pGlobalData
->DisplayDeviceList
;
819 while (Current
!= NULL
)
821 PDISPLAY_DEVICE_ENTRY Next
= Current
->Flink
;
822 PSETTINGS_ENTRY CurrentSettings
= Current
->Settings
;
823 while (CurrentSettings
!= NULL
)
825 PSETTINGS_ENTRY NextSettings
= CurrentSettings
->Flink
;
826 HeapFree(GetProcessHeap(), 0, CurrentSettings
);
827 CurrentSettings
= NextSettings
;
829 HeapFree(GetProcessHeap(), 0, Current
);
833 HeapFree(GetProcessHeap(), 0, pGlobalData
);
835 for(i
= 0; i
< NUM_SPECTRUM_BITMAPS
; i
++)
837 if(pGlobalData
->hSpectrumBitmaps
[i
])
838 DeleteObject(pGlobalData
->hSpectrumBitmaps
[i
]);