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
);
247 HeapFree(GetProcessHeap(), 0, devid
);
252 OnDisplayDeviceChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
, IN PDISPLAY_DEVICE_ENTRY pDeviceEntry
)
254 PSETTINGS_ENTRY Current
;
257 pGlobalData
->CurrentDisplayDevice
= pDeviceEntry
; /* Update global variable */
259 /* Fill color depths combo box */
260 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_RESETCONTENT
, 0, 0);
261 for (Current
= pDeviceEntry
->Settings
; Current
!= NULL
; Current
= Current
->Flink
)
264 if (LoadString(hApplet
, (2900 + Current
->dmBitsPerPel
), Buffer
, sizeof(Buffer
) / sizeof(TCHAR
)))
266 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_FINDSTRINGEXACT
, (WPARAM
)-1, (LPARAM
)Buffer
);
267 if (index
== (DWORD
)CB_ERR
)
269 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_ADDSTRING
, 0, (LPARAM
)Buffer
);
270 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_SETITEMDATA
, index
, Current
->dmBitsPerPel
);
275 /* Fill resolutions slider */
276 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_CLEARTICS
, TRUE
, 0);
277 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_SETRANGE
, TRUE
, MAKELONG(0, pDeviceEntry
->ResolutionsCount
- 1));
279 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
283 OnInitDialog(IN HWND hwndDlg
)
289 DISPLAY_DEVICE displayDevice
;
290 PGLOBAL_DATA pGlobalData
;
292 pGlobalData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(GLOBAL_DATA
));
293 if (pGlobalData
== NULL
)
296 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pGlobalData
);
298 /* Get video cards list */
299 displayDevice
.cb
= (DWORD
)sizeof(DISPLAY_DEVICE
);
300 while (EnumDisplayDevices(NULL
, iDevNum
, &displayDevice
, 0x1))
302 if ((displayDevice
.StateFlags
& DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
) != 0)
304 if (AddDisplayDevice(pGlobalData
, &displayDevice
))
311 /* No adapter found */
312 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_BPP
), FALSE
);
313 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION
), FALSE
);
314 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION_TEXT
), FALSE
);
315 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_ADVANCED
), FALSE
);
317 else if (Result
== 1)
319 MONSL_MONINFO monitors
;
321 /* Single video adapter */
322 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pGlobalData
->DisplayDeviceList
->DeviceDescription
);
323 OnDisplayDeviceChanged(hwndDlg
, pGlobalData
, pGlobalData
->DisplayDeviceList
);
325 monitors
.Position
.x
= monitors
.Position
.y
= 0;
326 monitors
.Size
.cx
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
327 monitors
.Size
.cy
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
329 SendDlgItemMessage(hwndDlg
,
331 MSLM_SETMONITORSINFO
,
335 else /* FIXME: incomplete! */
337 PMONSL_MONINFO pMonitors
;
340 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pGlobalData
->DisplayDeviceList
->DeviceDescription
);
341 OnDisplayDeviceChanged(hwndDlg
, pGlobalData
, pGlobalData
->DisplayDeviceList
);
343 pMonitors
= (PMONSL_MONINFO
)HeapAlloc(GetProcessHeap(), 0, sizeof(MONSL_MONINFO
) * Result
);
347 for (i
= 0; i
< Result
; i
++)
349 pMonitors
[i
].Position
.x
= hack
* i
;
350 pMonitors
[i
].Position
.y
= 0;
351 pMonitors
[i
].Size
.cx
= pGlobalData
->DisplayDeviceList
->CurrentSettings
->dmPelsWidth
;
352 pMonitors
[i
].Size
.cy
= pGlobalData
->DisplayDeviceList
->CurrentSettings
->dmPelsHeight
;
353 pMonitors
[i
].Flags
= 0;
356 SendDlgItemMessage(hwndDlg
,
358 MSLM_SETMONITORSINFO
,
362 HeapFree(GetProcessHeap(), 0, pMonitors
);
366 /* Initialize the color spectrum bitmaps */
367 for(i
= 0; i
< NUM_SPECTRUM_BITMAPS
; i
++)
369 pGlobalData
->hSpectrumBitmaps
[i
] = LoadImageW(hApplet
, MAKEINTRESOURCEW(IDB_SPECTRUM_4
+ i
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
371 if (pGlobalData
->hSpectrumBitmaps
[i
] != NULL
)
373 if (GetObjectW(pGlobalData
->hSpectrumBitmaps
[i
], sizeof(BITMAP
), &bitmap
) != 0)
375 pGlobalData
->cxSource
[i
] = bitmap
.bmWidth
;
376 pGlobalData
->cySource
[i
] = bitmap
.bmHeight
;
380 pGlobalData
->cxSource
[i
] = 0;
381 pGlobalData
->cySource
[i
] = 0;
387 /* Get the ID for GLOBAL_DATA::hSpectrumBitmaps */
389 ShowColorSpectrum(IN HDC hDC
, IN LPRECT client
, IN DWORD BitsPerPel
, IN PGLOBAL_DATA pGlobalData
)
394 hdcMem
= CreateCompatibleDC(hDC
);
401 case 4: iBitmap
= 0; break;
402 case 8: iBitmap
= 1; break;
403 default: iBitmap
= 2;
406 SelectObject(hdcMem
, pGlobalData
->hSpectrumBitmaps
[iBitmap
]);
408 client
->left
, client
->top
, client
->right
- client
->left
, client
->bottom
- client
->top
,
410 pGlobalData
->cxSource
[iBitmap
],
411 pGlobalData
->cySource
[iBitmap
], SRCCOPY
);
416 OnBPPChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
)
418 /* if new BPP is not compatible with resolution:
419 * 1) try to find the nearest smaller matching resolution
420 * 2) otherwise, get the nearest bigger resolution
422 PSETTINGS_ENTRY Current
;
423 DWORD dmNewBitsPerPel
;
426 HWND hSpectrumControl
;
429 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETCURSEL
, 0, 0);
430 dmNewBitsPerPel
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETITEMDATA
, index
, 0);
432 /* Show a new spectrum bitmap */
433 hSpectrumControl
= GetDlgItem(hwndDlg
, IDC_SETTINGS_SPECTRUM
);
434 hSpectrumDC
= GetDC(hSpectrumControl
);
435 GetClientRect(hSpectrumControl
, &client
);
436 ShowColorSpectrum(hSpectrumDC
, &client
, dmNewBitsPerPel
, pGlobalData
);
438 /* find if new parameters are valid */
439 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
;
440 if (dmNewBitsPerPel
== Current
->dmBitsPerPel
)
446 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
448 if (dmNewBitsPerPel
< Current
->dmBitsPerPel
)
450 Current
= Current
->Blink
;
451 while (Current
!= NULL
)
453 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
454 && Current
->dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
455 && Current
->dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
457 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
458 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
461 Current
= Current
->Blink
;
466 Current
= Current
->Flink
;
467 while (Current
!= NULL
)
469 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
470 && Current
->dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
471 && Current
->dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
473 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
474 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
477 Current
= Current
->Flink
;
481 /* search smaller resolution compatible with current color depth */
482 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
483 while (Current
!= NULL
)
485 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
487 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
488 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
491 Current
= Current
->Blink
;
494 /* search bigger resolution compatible with current color depth */
495 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
496 while (Current
!= NULL
)
498 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
500 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
501 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
504 Current
= Current
->Flink
;
507 /* we shouldn't go there */
511 OnResolutionChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
, IN DWORD NewPosition
,
512 IN BOOL bUpdateThumb
)
514 /* if new resolution is not compatible with color depth:
515 * 1) try to find the nearest bigger matching color depth
516 * 2) otherwise, get the nearest smaller color depth
518 PSETTINGS_ENTRY Current
;
519 DWORD dmNewPelsHeight
= pGlobalData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsHeight
;
520 DWORD dmNewPelsWidth
= pGlobalData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsWidth
;
522 /* find if new parameters are valid */
523 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
;
524 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
530 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
532 if (dmNewPelsHeight
< Current
->dmPelsHeight
)
534 Current
= Current
->Blink
;
535 while (Current
!= NULL
)
537 if (Current
->dmPelsHeight
== dmNewPelsHeight
538 && Current
->dmPelsWidth
== dmNewPelsWidth
539 && Current
->dmBitsPerPel
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
541 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
542 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
545 Current
= Current
->Blink
;
550 Current
= Current
->Flink
;
551 while (Current
!= NULL
)
553 if (Current
->dmPelsHeight
== dmNewPelsHeight
554 && Current
->dmPelsWidth
== dmNewPelsWidth
555 && Current
->dmBitsPerPel
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
557 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
558 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
561 Current
= Current
->Flink
;
565 /* search bigger color depth compatible with current resolution */
566 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
567 while (Current
!= NULL
)
569 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
571 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
572 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
575 Current
= Current
->Flink
;
578 /* search smaller color depth compatible with current resolution */
579 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
580 while (Current
!= NULL
)
582 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
584 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
585 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
588 Current
= Current
->Blink
;
591 /* we shouldn't go there */
594 /* Property sheet page callback */
596 SettingsPageCallbackProc(HWND hwnd
, UINT uMsg
, LPPROPSHEETPAGE ppsp
)
603 Ret
= RegisterMonitorSelectionControl(hApplet
);
607 UnregisterMonitorSelectionControl(hApplet
);
614 /* Property page dialog callback */
616 SettingsPageProc(IN HWND hwndDlg
, IN UINT uMsg
, IN WPARAM wParam
, IN LPARAM lParam
)
618 PGLOBAL_DATA pGlobalData
;
620 pGlobalData
= (PGLOBAL_DATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
626 OnInitDialog(hwndDlg
);
631 LPDRAWITEMSTRUCT lpDrawItem
;
632 lpDrawItem
= (LPDRAWITEMSTRUCT
) lParam
;
634 if (lpDrawItem
->CtlID
== IDC_SETTINGS_SPECTRUM
)
635 ShowColorSpectrum(lpDrawItem
->hDC
, &lpDrawItem
->rcItem
, pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
, pGlobalData
);
641 DWORD controlId
= LOWORD(wParam
);
642 DWORD command
= HIWORD(wParam
);
644 if (controlId
== IDC_SETTINGS_ADVANCED
&& command
== BN_CLICKED
)
645 DisplayAdvancedSettings(hwndDlg
, pGlobalData
->CurrentDisplayDevice
);
646 else if (controlId
== IDC_SETTINGS_BPP
&& command
== CBN_SELCHANGE
)
647 OnBPPChanged(hwndDlg
, pGlobalData
);
652 switch (LOWORD(wParam
))
662 DWORD newPosition
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_GETPOS
, 0, 0);
663 OnResolutionChanged(hwndDlg
, pGlobalData
, newPosition
, TRUE
);
668 OnResolutionChanged(hwndDlg
, pGlobalData
, HIWORD(wParam
), FALSE
);
675 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
676 if (lpnm
->code
== (UINT
)PSN_APPLY
)
678 if (pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
679 || pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
680 || pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
)
682 /* FIXME: Need to test changes */
683 /* Apply new settings */
686 RtlZeroMemory(&devmode
, sizeof(DEVMODE
));
687 devmode
.dmSize
= (WORD
)sizeof(DEVMODE
);
688 devmode
.dmPelsWidth
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
689 devmode
.dmPelsHeight
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
690 devmode
.dmBitsPerPel
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
691 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
| DM_BITSPERPEL
;
692 rc
= ChangeDisplaySettingsEx(
693 pGlobalData
->CurrentDisplayDevice
->DeviceName
,
700 case DISP_CHANGE_SUCCESSFUL
:
701 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
702 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
703 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
705 case DISP_CHANGE_FAILED
:
706 MessageBox(NULL
, TEXT("Failed to apply new settings..."), TEXT("Display settings"), MB_OK
| MB_ICONSTOP
);
708 case DISP_CHANGE_RESTART
:
709 MessageBox(NULL
, TEXT("You need to restart your computer to apply changes."), TEXT("Display settings"), MB_OK
| MB_ICONINFORMATION
);
712 MessageBox(NULL
, TEXT("Unknown error when applying new settings..."), TEXT("Display settings"), MB_OK
| MB_ICONSTOP
);
728 pt
.x
= (SHORT
)LOWORD(lParam
);
729 pt
.y
= (SHORT
)HIWORD(lParam
);
731 hwndMonSel
= GetDlgItem(hwndDlg
,
732 IDC_SETTINGS_MONSEL
);
733 if ((HWND
)wParam
== hwndMonSel
)
735 if (pt
.x
== -1 && pt
.y
== -1)
739 Index
= (INT
)SendMessage(hwndMonSel
,
745 (INT
)SendMessage(hwndMonSel
,
750 pt
.x
= rcMon
.left
+ ((rcMon
.right
- rcMon
.left
) / 2);
751 pt
.y
= rcMon
.top
+ ((rcMon
.bottom
- rcMon
.top
) / 2);
756 MapWindowPoints(hwndMonSel
,
764 MapWindowPoints(NULL
,
769 Index
= (INT
)SendMessage(hwndMonSel
,
777 hPopup
= LoadPopupMenu(hApplet
,
778 MAKEINTRESOURCE(IDM_MONITOR_MENU
));
781 /* FIXME: Enable/Disable menu items */
782 EnableMenuItem(hPopup
,
784 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
785 EnableMenuItem(hPopup
,
787 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
788 EnableMenuItem(hPopup
,
790 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
791 EnableMenuItem(hPopup
,
793 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
795 uiCmd
= (UINT
)TrackPopupMenu(hPopup
,
796 TPM_RETURNCMD
| TPM_RIGHTBUTTON
,
805 case ID_MENU_ATTACHED
:
806 case ID_MENU_PRIMARY
:
807 case ID_MENU_IDENTIFY
:
808 case ID_MENU_PROPERTIES
:
809 /* FIXME: Implement */
823 PDISPLAY_DEVICE_ENTRY Current
= pGlobalData
->DisplayDeviceList
;
825 while (Current
!= NULL
)
827 PDISPLAY_DEVICE_ENTRY Next
= Current
->Flink
;
828 PSETTINGS_ENTRY CurrentSettings
= Current
->Settings
;
829 while (CurrentSettings
!= NULL
)
831 PSETTINGS_ENTRY NextSettings
= CurrentSettings
->Flink
;
832 HeapFree(GetProcessHeap(), 0, CurrentSettings
);
833 CurrentSettings
= NextSettings
;
835 HeapFree(GetProcessHeap(), 0, Current
);
839 HeapFree(GetProcessHeap(), 0, pGlobalData
);
841 for (i
= 0; i
< NUM_SPECTRUM_BITMAPS
; i
++)
843 if (pGlobalData
->hSpectrumBitmaps
[i
])
844 DeleteObject(pGlobalData
->hSpectrumBitmaps
[i
]);