2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Display Control Panel
4 * FILE: dll/cpl/desk/settings.c
5 * PURPOSE: Settings property page
7 * PROGRAMMERS: Trevor McCort (lycan359@gmail.com)
8 * Hervé Poussineau (hpoussin@reactos.org)
15 PDISPLAY_DEVICE_ENTRY DisplayDeviceList
;
16 PDISPLAY_DEVICE_ENTRY CurrentDisplayDevice
;
17 HBITMAP hSpectrumBitmaps
[NUM_SPECTRUM_BITMAPS
];
18 int cxSource
[NUM_SPECTRUM_BITMAPS
];
19 int cySource
[NUM_SPECTRUM_BITMAPS
];
24 UpdateDisplay(IN HWND hwndDlg
, PDATA pData
, IN BOOL bUpdateThumb
)
30 LoadString(hApplet
, IDS_PIXEL
, Pixel
, sizeof(Pixel
) / sizeof(TCHAR
));
31 _stprintf(Buffer
, Pixel
, pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
, pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
, Pixel
);
32 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION_TEXT
, WM_SETTEXT
, 0, (LPARAM
)Buffer
);
34 for (index
= 0; index
< pData
->CurrentDisplayDevice
->ResolutionsCount
; index
++)
36 if (pData
->CurrentDisplayDevice
->Resolutions
[index
].dmPelsWidth
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
&&
37 pData
->CurrentDisplayDevice
->Resolutions
[index
].dmPelsHeight
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
)
40 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_SETPOS
, TRUE
, index
);
44 if (LoadString(hApplet
, (2900 + pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
), Buffer
, sizeof(Buffer
) / sizeof(TCHAR
)))
45 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_SELECTSTRING
, (WPARAM
)-1, (LPARAM
)Buffer
);
48 static PSETTINGS_ENTRY
49 GetPossibleSettings(IN LPCTSTR DeviceName
, OUT DWORD
* pSettingsCount
, OUT PSETTINGS_ENTRY
* CurrentSettings
)
55 PSETTINGS_ENTRY Settings
= NULL
;
57 PSETTINGS_ENTRY Current
;
58 DWORD bpp
, xres
, yres
, checkbpp
;
61 /* Get current settings */
62 *CurrentSettings
= NULL
;
63 hDC
= CreateIC(NULL
, DeviceName
, NULL
, NULL
);
64 bpp
= GetDeviceCaps(hDC
, PLANES
);
65 bpp
*= GetDeviceCaps(hDC
, BITSPIXEL
);
66 xres
= GetDeviceCaps(hDC
, HORZRES
);
67 yres
= GetDeviceCaps(hDC
, VERTRES
);
70 /* List all settings */
71 devmode
.dmSize
= (WORD
)sizeof(DEVMODE
);
72 devmode
.dmDriverExtra
= 0;
74 if (!EnumDisplaySettingsEx(DeviceName
, ENUM_CURRENT_SETTINGS
, &devmode
, dwFlags
))
77 curDispFreq
= devmode
.dmDisplayFrequency
;
79 while (EnumDisplaySettingsEx(DeviceName
, iMode
, &devmode
, dwFlags
))
81 if ((devmode
.dmBitsPerPel
== 4 ||
82 devmode
.dmBitsPerPel
== 8 ||
83 devmode
.dmBitsPerPel
== 16 ||
84 devmode
.dmBitsPerPel
== 24 ||
85 devmode
.dmBitsPerPel
== 32) &&
86 devmode
.dmDisplayFrequency
== curDispFreq
)
93 if (devmode
.dmPelsWidth
< 640 ||
94 devmode
.dmPelsHeight
< 480 || checkbpp
== 0)
100 Current
= HeapAlloc(GetProcessHeap(), 0, sizeof(SETTINGS_ENTRY
));
103 /* Sort resolutions by increasing height, and BPP */
104 PSETTINGS_ENTRY Previous
= NULL
;
105 PSETTINGS_ENTRY Next
= Settings
;
106 Current
->dmPelsWidth
= devmode
.dmPelsWidth
;
107 Current
->dmPelsHeight
= devmode
.dmPelsHeight
;
108 Current
->dmBitsPerPel
= devmode
.dmBitsPerPel
;
109 Current
->dmDisplayFrequency
= devmode
.dmDisplayFrequency
;
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 PDATA pData
, 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(), HEAP_ZERO_MEMORY
, sizeof(DISPLAY_DEVICE_ENTRY
));
155 if (!newEntry
) goto ByeBye
;
157 newEntry
->Settings
= GetPossibleSettings(DisplayDevice
->DeviceName
, &newEntry
->SettingsCount
, &newEntry
->CurrentSettings
);
158 if (!newEntry
->Settings
) goto ByeBye
;
160 newEntry
->InitialSettings
.dmPelsWidth
= newEntry
->CurrentSettings
->dmPelsWidth
;
161 newEntry
->InitialSettings
.dmPelsHeight
= newEntry
->CurrentSettings
->dmPelsHeight
;
162 newEntry
->InitialSettings
.dmBitsPerPel
= newEntry
->CurrentSettings
->dmBitsPerPel
;
164 /* Count different resolutions */
165 for (Current
= newEntry
->Settings
; Current
!= NULL
; Current
= Current
->Flink
)
167 if (Current
->Flink
!= NULL
&&
168 ((Current
->dmPelsWidth
!= Current
->Flink
->dmPelsWidth
) &&
169 (Current
->dmPelsHeight
!= Current
->Flink
->dmPelsHeight
)))
175 newEntry
->Resolutions
= HeapAlloc(GetProcessHeap(), 0, ResolutionsCount
* sizeof(RESOLUTION_INFO
));
176 if (!newEntry
->Resolutions
) goto ByeBye
;
178 newEntry
->ResolutionsCount
= ResolutionsCount
;
180 /* Fill resolutions infos */
181 for (Current
= newEntry
->Settings
, i
= 0; Current
!= NULL
; Current
= Current
->Flink
)
183 if (Current
->Flink
== NULL
||
184 (Current
->Flink
!= NULL
&&
185 ((Current
->dmPelsWidth
!= Current
->Flink
->dmPelsWidth
) &&
186 (Current
->dmPelsHeight
!= Current
->Flink
->dmPelsHeight
))))
188 newEntry
->Resolutions
[i
].dmPelsWidth
= Current
->dmPelsWidth
;
189 newEntry
->Resolutions
[i
].dmPelsHeight
= Current
->dmPelsHeight
;
193 descriptionSize
= (_tcslen(DisplayDevice
->DeviceString
) + 1) * sizeof(TCHAR
);
194 description
= HeapAlloc(GetProcessHeap(), 0, descriptionSize
);
195 if (!description
) goto ByeBye
;
197 nameSize
= (_tcslen(DisplayDevice
->DeviceName
) + 1) * sizeof(TCHAR
);
198 name
= HeapAlloc(GetProcessHeap(), 0, nameSize
);
199 if (!name
) goto ByeBye
;
201 keySize
= (_tcslen(DisplayDevice
->DeviceKey
) + 1) * sizeof(TCHAR
);
202 key
= HeapAlloc(GetProcessHeap(), 0, keySize
);
203 if (!key
) goto ByeBye
;
205 devidSize
= (_tcslen(DisplayDevice
->DeviceID
) + 1) * sizeof(TCHAR
);
206 devid
= HeapAlloc(GetProcessHeap(), 0, devidSize
);
207 if (!devid
) goto ByeBye
;
209 memcpy(description
, DisplayDevice
->DeviceString
, descriptionSize
);
210 memcpy(name
, DisplayDevice
->DeviceName
, nameSize
);
211 memcpy(key
, DisplayDevice
->DeviceKey
, keySize
);
212 memcpy(devid
, DisplayDevice
->DeviceID
, devidSize
);
213 newEntry
->DeviceDescription
= description
;
214 newEntry
->DeviceName
= name
;
215 newEntry
->DeviceKey
= key
;
216 newEntry
->DeviceID
= devid
;
217 newEntry
->DeviceStateFlags
= DisplayDevice
->StateFlags
;
218 newEntry
->Flink
= pData
->DisplayDeviceList
;
219 pData
->DisplayDeviceList
= newEntry
;
223 if (newEntry
!= NULL
)
225 if (newEntry
->Settings
!= NULL
)
227 Current
= newEntry
->Settings
;
228 while (Current
!= NULL
)
230 PSETTINGS_ENTRY Next
= Current
->Flink
;
231 HeapFree(GetProcessHeap(), 0, Current
);
235 if (newEntry
->Resolutions
!= NULL
)
236 HeapFree(GetProcessHeap(), 0, newEntry
->Resolutions
);
237 HeapFree(GetProcessHeap(), 0, newEntry
);
239 if (description
!= NULL
)
240 HeapFree(GetProcessHeap(), 0, description
);
242 HeapFree(GetProcessHeap(), 0, name
);
244 HeapFree(GetProcessHeap(), 0, key
);
249 OnDisplayDeviceChanged(IN HWND hwndDlg
, IN PDATA pData
, IN PDISPLAY_DEVICE_ENTRY pDeviceEntry
)
251 PSETTINGS_ENTRY Current
;
254 pData
->CurrentDisplayDevice
= pDeviceEntry
; /* Update variable */
256 /* Fill color depths combo box */
257 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_RESETCONTENT
, 0, 0);
258 for (Current
= pDeviceEntry
->Settings
; Current
!= NULL
; Current
= Current
->Flink
)
261 if (LoadString(hApplet
, (2900 + Current
->dmBitsPerPel
), Buffer
, sizeof(Buffer
) / sizeof(TCHAR
)))
263 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_FINDSTRINGEXACT
, (WPARAM
)-1, (LPARAM
)Buffer
);
264 if (index
== (DWORD
)CB_ERR
)
266 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_ADDSTRING
, 0, (LPARAM
)Buffer
);
267 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_SETITEMDATA
, index
, Current
->dmBitsPerPel
);
272 /* Fill resolutions slider */
273 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_CLEARTICS
, TRUE
, 0);
274 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_SETRANGE
, TRUE
, MAKELONG(0, pDeviceEntry
->ResolutionsCount
- 1));
276 UpdateDisplay(hwndDlg
, pData
, TRUE
);
280 OnInitDialog(IN HWND hwndDlg
)
286 DISPLAY_DEVICE displayDevice
;
289 pData
= HeapAlloc(GetProcessHeap(), 0, sizeof(DATA
));
293 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pData
);
295 /* Get video cards list */
296 pData
->DisplayDeviceList
= NULL
;
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(pData
, &displayDevice
))
310 /* No adapter found */
311 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_BPP
), FALSE
);
312 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION
), FALSE
);
313 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION_TEXT
), FALSE
);
314 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_ADVANCED
), FALSE
);
315 ShowWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_SPECTRUM
), SW_HIDE
);
317 /* Do not initialize the color spectrum bitmaps */
318 memset(pData
->hSpectrumBitmaps
, 0, sizeof(pData
->hSpectrumBitmaps
));
321 else if (Result
== 1)
323 MONSL_MONINFO monitors
;
325 /* Single video adapter */
326 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pData
->DisplayDeviceList
->DeviceDescription
);
327 OnDisplayDeviceChanged(hwndDlg
, pData
, pData
->DisplayDeviceList
);
329 monitors
.Position
.x
= monitors
.Position
.y
= 0;
330 monitors
.Size
.cx
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
331 monitors
.Size
.cy
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
333 SendDlgItemMessage(hwndDlg
,
335 MSLM_SETMONITORSINFO
,
339 else /* FIXME: Incomplete! */
341 PMONSL_MONINFO pMonitors
;
344 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pData
->DisplayDeviceList
->DeviceDescription
);
345 OnDisplayDeviceChanged(hwndDlg
, pData
, pData
->DisplayDeviceList
);
347 pMonitors
= (PMONSL_MONINFO
)HeapAlloc(GetProcessHeap(), 0, sizeof(MONSL_MONINFO
) * Result
);
351 for (i
= 0; i
< Result
; i
++)
353 pMonitors
[i
].Position
.x
= hack
* i
;
354 pMonitors
[i
].Position
.y
= 0;
355 pMonitors
[i
].Size
.cx
= pData
->DisplayDeviceList
->CurrentSettings
->dmPelsWidth
;
356 pMonitors
[i
].Size
.cy
= pData
->DisplayDeviceList
->CurrentSettings
->dmPelsHeight
;
357 pMonitors
[i
].Flags
= 0;
360 SendDlgItemMessage(hwndDlg
,
362 MSLM_SETMONITORSINFO
,
366 HeapFree(GetProcessHeap(), 0, pMonitors
);
370 /* Initialize the color spectrum bitmaps */
371 for(i
= 0; i
< NUM_SPECTRUM_BITMAPS
; i
++)
373 pData
->hSpectrumBitmaps
[i
] = LoadImageW(hApplet
, MAKEINTRESOURCEW(IDB_SPECTRUM_4
+ i
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
375 if (pData
->hSpectrumBitmaps
[i
] != NULL
)
377 if (GetObjectW(pData
->hSpectrumBitmaps
[i
], sizeof(BITMAP
), &bitmap
) != 0)
379 pData
->cxSource
[i
] = bitmap
.bmWidth
;
380 pData
->cySource
[i
] = bitmap
.bmHeight
;
384 pData
->cxSource
[i
] = 0;
385 pData
->cySource
[i
] = 0;
391 /* Get the ID for DATA::hSpectrumBitmaps */
393 ShowColorSpectrum(IN HDC hDC
, IN LPRECT client
, IN DWORD BitsPerPel
, IN PDATA pData
)
398 hdcMem
= CreateCompatibleDC(hDC
);
405 case 4: iBitmap
= 0; break;
406 case 8: iBitmap
= 1; break;
407 default: iBitmap
= 2;
410 if (SelectObject(hdcMem
, pData
->hSpectrumBitmaps
[iBitmap
]))
413 client
->left
, client
->top
,
414 client
->right
- client
->left
,
415 client
->bottom
- client
->top
,
417 pData
->cxSource
[iBitmap
],
418 pData
->cySource
[iBitmap
], SRCCOPY
);
425 OnBPPChanged(IN HWND hwndDlg
, IN PDATA pData
)
427 /* If new BPP is not compatible with resolution:
428 * 1) try to find the nearest smaller matching resolution
429 * 2) otherwise, get the nearest bigger resolution
431 PSETTINGS_ENTRY Current
;
432 DWORD dmNewBitsPerPel
;
435 HWND hSpectrumControl
;
438 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETCURSEL
, 0, 0);
439 dmNewBitsPerPel
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETITEMDATA
, index
, 0);
441 /* Show a new spectrum bitmap */
442 hSpectrumControl
= GetDlgItem(hwndDlg
, IDC_SETTINGS_SPECTRUM
);
443 hSpectrumDC
= GetDC(hSpectrumControl
);
444 GetClientRect(hSpectrumControl
, &client
);
445 ShowColorSpectrum(hSpectrumDC
, &client
, dmNewBitsPerPel
, pData
);
447 /* Find if new parameters are valid */
448 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
;
449 if (dmNewBitsPerPel
== Current
->dmBitsPerPel
)
455 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
457 if (dmNewBitsPerPel
< Current
->dmBitsPerPel
)
459 Current
= Current
->Blink
;
460 while (Current
!= NULL
)
462 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
463 && Current
->dmPelsHeight
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
464 && Current
->dmPelsWidth
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
466 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
467 UpdateDisplay(hwndDlg
, pData
, TRUE
);
470 Current
= Current
->Blink
;
475 Current
= Current
->Flink
;
476 while (Current
!= NULL
)
478 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
479 && Current
->dmPelsHeight
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
480 && Current
->dmPelsWidth
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
482 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
483 UpdateDisplay(hwndDlg
, pData
, TRUE
);
486 Current
= Current
->Flink
;
490 /* Search smaller resolution compatible with current color depth */
491 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
492 while (Current
!= NULL
)
494 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
496 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
497 UpdateDisplay(hwndDlg
, pData
, TRUE
);
500 Current
= Current
->Blink
;
503 /* Search bigger resolution compatible with current color depth */
504 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
505 while (Current
!= NULL
)
507 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
509 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
510 UpdateDisplay(hwndDlg
, pData
, TRUE
);
513 Current
= Current
->Flink
;
516 /* We shouldn't go there */
520 OnResolutionChanged(IN HWND hwndDlg
, IN PDATA pData
, IN DWORD NewPosition
,
521 IN BOOL bUpdateThumb
)
523 /* If new resolution is not compatible with color depth:
524 * 1) try to find the nearest bigger matching color depth
525 * 2) otherwise, get the nearest smaller color depth
527 PSETTINGS_ENTRY Current
;
528 DWORD dmNewPelsHeight
= pData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsHeight
;
529 DWORD dmNewPelsWidth
= pData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsWidth
;
531 /* Find if new parameters are valid */
532 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
;
533 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
539 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
541 if (dmNewPelsHeight
< Current
->dmPelsHeight
)
543 Current
= Current
->Blink
;
544 while (Current
!= NULL
)
546 if (Current
->dmPelsHeight
== dmNewPelsHeight
547 && Current
->dmPelsWidth
== dmNewPelsWidth
548 && Current
->dmBitsPerPel
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
550 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
551 UpdateDisplay(hwndDlg
, pData
, bUpdateThumb
);
554 Current
= Current
->Blink
;
559 Current
= Current
->Flink
;
560 while (Current
!= NULL
)
562 if (Current
->dmPelsHeight
== dmNewPelsHeight
563 && Current
->dmPelsWidth
== dmNewPelsWidth
564 && Current
->dmBitsPerPel
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
566 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
567 UpdateDisplay(hwndDlg
, pData
, bUpdateThumb
);
570 Current
= Current
->Flink
;
574 /* Search bigger color depth compatible with current resolution */
575 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
576 while (Current
!= NULL
)
578 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
580 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
581 UpdateDisplay(hwndDlg
, pData
, bUpdateThumb
);
584 Current
= Current
->Flink
;
587 /* Search smaller color depth compatible with current resolution */
588 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
589 while (Current
!= NULL
)
591 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
593 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
594 UpdateDisplay(hwndDlg
, pData
, bUpdateThumb
);
597 Current
= Current
->Blink
;
600 /* We shouldn't go there */
603 /* Property sheet page callback */
605 SettingsPageCallbackProc(HWND hwnd
, UINT uMsg
, LPPROPSHEETPAGE ppsp
)
612 Ret
= RegisterMonitorSelectionControl(hApplet
);
616 UnregisterMonitorSelectionControl(hApplet
);
623 /* Property page dialog callback */
625 SettingsPageProc(IN HWND hwndDlg
, IN UINT uMsg
, IN WPARAM wParam
, IN LPARAM lParam
)
628 TCHAR Message
[1024], Title
[256];
630 pData
= (PDATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
636 OnInitDialog(hwndDlg
);
641 LPDRAWITEMSTRUCT lpDrawItem
;
642 lpDrawItem
= (LPDRAWITEMSTRUCT
) lParam
;
644 if (lpDrawItem
->CtlID
== IDC_SETTINGS_SPECTRUM
)
645 ShowColorSpectrum(lpDrawItem
->hDC
, &lpDrawItem
->rcItem
, pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
, pData
);
650 DWORD controlId
= LOWORD(wParam
);
651 DWORD command
= HIWORD(wParam
);
653 if (controlId
== IDC_SETTINGS_ADVANCED
&& command
== BN_CLICKED
)
654 DisplayAdvancedSettings(hwndDlg
, pData
->CurrentDisplayDevice
);
655 else if (controlId
== IDC_SETTINGS_BPP
&& command
== CBN_SELCHANGE
)
656 OnBPPChanged(hwndDlg
, pData
);
661 switch (LOWORD(wParam
))
671 DWORD newPosition
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_GETPOS
, 0, 0);
672 OnResolutionChanged(hwndDlg
, pData
, newPosition
, TRUE
);
677 OnResolutionChanged(hwndDlg
, pData
, HIWORD(wParam
), FALSE
);
684 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
685 if (lpnm
->code
== (UINT
)PSN_APPLY
)
687 if (pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
!= pData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
688 || pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
!= pData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
689 || pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
!= pData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
)
691 /* FIXME: Need to test changes */
692 /* Apply new settings */
695 RtlZeroMemory(&devmode
, sizeof(DEVMODE
));
696 devmode
.dmSize
= (WORD
)sizeof(DEVMODE
);
697 devmode
.dmPelsWidth
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
698 devmode
.dmPelsHeight
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
699 devmode
.dmBitsPerPel
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
700 devmode
.dmDisplayFrequency
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmDisplayFrequency
;
701 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
| DM_BITSPERPEL
| DM_DISPLAYFREQUENCY
;
702 rc
= ChangeDisplaySettingsEx(
703 pData
->CurrentDisplayDevice
->DeviceName
,
710 case DISP_CHANGE_SUCCESSFUL
:
711 pData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
712 pData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
713 pData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
715 case DISP_CHANGE_RESTART
:
716 LoadString(hApplet
, IDS_DISPLAY_SETTINGS
, Title
, sizeof(Title
) / sizeof(TCHAR
));
717 LoadString(hApplet
, IDS_APPLY_NEEDS_RESTART
, Message
, sizeof(Message
) / sizeof (TCHAR
));
718 MessageBox(hwndDlg
, Message
, Title
, MB_OK
| MB_ICONINFORMATION
);
720 case DISP_CHANGE_FAILED
:
722 LoadString(hApplet
, IDS_DISPLAY_SETTINGS
, Title
, sizeof(Title
) / sizeof(TCHAR
));
723 LoadString(hApplet
, IDS_APPLY_FAILED
, Message
, sizeof(Message
) / sizeof (TCHAR
));
724 MessageBox(hwndDlg
, Message
, Title
, MB_OK
| MB_ICONSTOP
);
740 pt
.x
= (SHORT
)LOWORD(lParam
);
741 pt
.y
= (SHORT
)HIWORD(lParam
);
743 hwndMonSel
= GetDlgItem(hwndDlg
,
744 IDC_SETTINGS_MONSEL
);
745 if ((HWND
)wParam
== hwndMonSel
)
747 if (pt
.x
== -1 && pt
.y
== -1)
751 Index
= (INT
)SendMessage(hwndMonSel
,
757 (INT
)SendMessage(hwndMonSel
,
762 pt
.x
= rcMon
.left
+ ((rcMon
.right
- rcMon
.left
) / 2);
763 pt
.y
= rcMon
.top
+ ((rcMon
.bottom
- rcMon
.top
) / 2);
768 MapWindowPoints(hwndMonSel
,
776 MapWindowPoints(NULL
,
781 Index
= (INT
)SendMessage(hwndMonSel
,
789 hPopup
= LoadPopupMenu(hApplet
,
790 MAKEINTRESOURCE(IDM_MONITOR_MENU
));
793 /* FIXME: Enable/Disable menu items */
794 EnableMenuItem(hPopup
,
796 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
797 EnableMenuItem(hPopup
,
799 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
800 EnableMenuItem(hPopup
,
802 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
803 EnableMenuItem(hPopup
,
805 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
807 uiCmd
= (UINT
)TrackPopupMenu(hPopup
,
808 TPM_RETURNCMD
| TPM_RIGHTBUTTON
,
817 case ID_MENU_ATTACHED
:
818 case ID_MENU_PRIMARY
:
819 case ID_MENU_IDENTIFY
:
820 case ID_MENU_PROPERTIES
:
821 /* FIXME: Implement */
835 PDISPLAY_DEVICE_ENTRY Current
= pData
->DisplayDeviceList
;
837 while (Current
!= NULL
)
839 PDISPLAY_DEVICE_ENTRY Next
= Current
->Flink
;
840 PSETTINGS_ENTRY CurrentSettings
= Current
->Settings
;
841 while (CurrentSettings
!= NULL
)
843 PSETTINGS_ENTRY NextSettings
= CurrentSettings
->Flink
;
844 HeapFree(GetProcessHeap(), 0, CurrentSettings
);
845 CurrentSettings
= NextSettings
;
847 HeapFree(GetProcessHeap(), 0, Current
);
851 for (i
= 0; i
< NUM_SPECTRUM_BITMAPS
; i
++)
853 if (pData
->hSpectrumBitmaps
[i
])
854 DeleteObject(pData
->hSpectrumBitmaps
[i
]);
857 HeapFree(GetProcessHeap(), 0, pData
);