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)
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
];
25 UpdateDisplay(IN HWND hwndDlg
, PDATA pData
, IN BOOL bUpdateThumb
)
31 LoadString(hApplet
, IDS_PIXEL
, Pixel
, sizeof(Pixel
) / sizeof(TCHAR
));
32 _stprintf(Buffer
, Pixel
, pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
, pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
, Pixel
);
33 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION_TEXT
, WM_SETTEXT
, 0, (LPARAM
)Buffer
);
35 for (index
= 0; index
< pData
->CurrentDisplayDevice
->ResolutionsCount
; index
++)
37 if (pData
->CurrentDisplayDevice
->Resolutions
[index
].dmPelsWidth
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
&&
38 pData
->CurrentDisplayDevice
->Resolutions
[index
].dmPelsHeight
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
)
41 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_SETPOS
, TRUE
, index
);
45 if (LoadString(hApplet
, (2900 + pData
->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 Current
->dmDisplayFrequency
= devmode
.dmDisplayFrequency
;
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 PDATA pData
, 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(), HEAP_ZERO_MEMORY
, 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
= pData
->DisplayDeviceList
;
220 pData
->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 PDATA pData
, IN PDISPLAY_DEVICE_ENTRY pDeviceEntry
)
252 PSETTINGS_ENTRY Current
;
255 pData
->CurrentDisplayDevice
= pDeviceEntry
; /* Update 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
, pData
, TRUE
);
281 OnInitDialog(IN HWND hwndDlg
)
287 DISPLAY_DEVICE displayDevice
;
290 pData
= HeapAlloc(GetProcessHeap(), 0, sizeof(DATA
));
294 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pData
);
296 /* Get video cards list */
297 pData
->DisplayDeviceList
= NULL
;
298 displayDevice
.cb
= (DWORD
)sizeof(DISPLAY_DEVICE
);
299 while (EnumDisplayDevices(NULL
, iDevNum
, &displayDevice
, 0x1))
301 if ((displayDevice
.StateFlags
& DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
) != 0)
303 if (AddDisplayDevice(pData
, &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
);
316 ShowWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_SPECTRUM
), SW_HIDE
);
318 /* Do not initialize the color spectrum bitmaps */
319 memset(pData
->hSpectrumBitmaps
, 0, sizeof(pData
->hSpectrumBitmaps
));
322 else if (Result
== 1)
324 MONSL_MONINFO monitors
;
326 /* Single video adapter */
327 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pData
->DisplayDeviceList
->DeviceDescription
);
328 OnDisplayDeviceChanged(hwndDlg
, pData
, pData
->DisplayDeviceList
);
330 monitors
.Position
.x
= monitors
.Position
.y
= 0;
331 monitors
.Size
.cx
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
332 monitors
.Size
.cy
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
334 SendDlgItemMessage(hwndDlg
,
336 MSLM_SETMONITORSINFO
,
340 else /* FIXME: incomplete! */
342 PMONSL_MONINFO pMonitors
;
345 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pData
->DisplayDeviceList
->DeviceDescription
);
346 OnDisplayDeviceChanged(hwndDlg
, pData
, pData
->DisplayDeviceList
);
348 pMonitors
= (PMONSL_MONINFO
)HeapAlloc(GetProcessHeap(), 0, sizeof(MONSL_MONINFO
) * Result
);
352 for (i
= 0; i
< Result
; i
++)
354 pMonitors
[i
].Position
.x
= hack
* i
;
355 pMonitors
[i
].Position
.y
= 0;
356 pMonitors
[i
].Size
.cx
= pData
->DisplayDeviceList
->CurrentSettings
->dmPelsWidth
;
357 pMonitors
[i
].Size
.cy
= pData
->DisplayDeviceList
->CurrentSettings
->dmPelsHeight
;
358 pMonitors
[i
].Flags
= 0;
361 SendDlgItemMessage(hwndDlg
,
363 MSLM_SETMONITORSINFO
,
367 HeapFree(GetProcessHeap(), 0, pMonitors
);
371 /* Initialize the color spectrum bitmaps */
372 for(i
= 0; i
< NUM_SPECTRUM_BITMAPS
; i
++)
374 pData
->hSpectrumBitmaps
[i
] = LoadImageW(hApplet
, MAKEINTRESOURCEW(IDB_SPECTRUM_4
+ i
), IMAGE_BITMAP
, 0, 0, LR_DEFAULTCOLOR
);
376 if (pData
->hSpectrumBitmaps
[i
] != NULL
)
378 if (GetObjectW(pData
->hSpectrumBitmaps
[i
], sizeof(BITMAP
), &bitmap
) != 0)
380 pData
->cxSource
[i
] = bitmap
.bmWidth
;
381 pData
->cySource
[i
] = bitmap
.bmHeight
;
385 pData
->cxSource
[i
] = 0;
386 pData
->cySource
[i
] = 0;
392 /* Get the ID for DATA::hSpectrumBitmaps */
394 ShowColorSpectrum(IN HDC hDC
, IN LPRECT client
, IN DWORD BitsPerPel
, IN PDATA pData
)
399 hdcMem
= CreateCompatibleDC(hDC
);
406 case 4: iBitmap
= 0; break;
407 case 8: iBitmap
= 1; break;
408 default: iBitmap
= 2;
411 if (SelectObject(hdcMem
, pData
->hSpectrumBitmaps
[iBitmap
]))
414 client
->left
, client
->top
,
415 client
->right
- client
->left
,
416 client
->bottom
- client
->top
,
418 pData
->cxSource
[iBitmap
],
419 pData
->cySource
[iBitmap
], SRCCOPY
);
426 OnBPPChanged(IN HWND hwndDlg
, IN PDATA pData
)
428 /* if new BPP is not compatible with resolution:
429 * 1) try to find the nearest smaller matching resolution
430 * 2) otherwise, get the nearest bigger resolution
432 PSETTINGS_ENTRY Current
;
433 DWORD dmNewBitsPerPel
;
436 HWND hSpectrumControl
;
439 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETCURSEL
, 0, 0);
440 dmNewBitsPerPel
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETITEMDATA
, index
, 0);
442 /* Show a new spectrum bitmap */
443 hSpectrumControl
= GetDlgItem(hwndDlg
, IDC_SETTINGS_SPECTRUM
);
444 hSpectrumDC
= GetDC(hSpectrumControl
);
445 GetClientRect(hSpectrumControl
, &client
);
446 ShowColorSpectrum(hSpectrumDC
, &client
, dmNewBitsPerPel
, pData
);
448 /* find if new parameters are valid */
449 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
;
450 if (dmNewBitsPerPel
== Current
->dmBitsPerPel
)
456 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
458 if (dmNewBitsPerPel
< Current
->dmBitsPerPel
)
460 Current
= Current
->Blink
;
461 while (Current
!= NULL
)
463 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
464 && Current
->dmPelsHeight
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
465 && Current
->dmPelsWidth
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
467 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
468 UpdateDisplay(hwndDlg
, pData
, TRUE
);
471 Current
= Current
->Blink
;
476 Current
= Current
->Flink
;
477 while (Current
!= NULL
)
479 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
480 && Current
->dmPelsHeight
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
481 && Current
->dmPelsWidth
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
483 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
484 UpdateDisplay(hwndDlg
, pData
, TRUE
);
487 Current
= Current
->Flink
;
491 /* search smaller resolution compatible with current color depth */
492 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
493 while (Current
!= NULL
)
495 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
497 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
498 UpdateDisplay(hwndDlg
, pData
, TRUE
);
501 Current
= Current
->Blink
;
504 /* search bigger resolution compatible with current color depth */
505 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
506 while (Current
!= NULL
)
508 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
510 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
511 UpdateDisplay(hwndDlg
, pData
, TRUE
);
514 Current
= Current
->Flink
;
517 /* we shouldn't go there */
521 OnResolutionChanged(IN HWND hwndDlg
, IN PDATA pData
, IN DWORD NewPosition
,
522 IN BOOL bUpdateThumb
)
524 /* if new resolution is not compatible with color depth:
525 * 1) try to find the nearest bigger matching color depth
526 * 2) otherwise, get the nearest smaller color depth
528 PSETTINGS_ENTRY Current
;
529 DWORD dmNewPelsHeight
= pData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsHeight
;
530 DWORD dmNewPelsWidth
= pData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsWidth
;
532 /* find if new parameters are valid */
533 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
;
534 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
540 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
542 if (dmNewPelsHeight
< Current
->dmPelsHeight
)
544 Current
= Current
->Blink
;
545 while (Current
!= NULL
)
547 if (Current
->dmPelsHeight
== dmNewPelsHeight
548 && Current
->dmPelsWidth
== dmNewPelsWidth
549 && Current
->dmBitsPerPel
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
551 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
552 UpdateDisplay(hwndDlg
, pData
, bUpdateThumb
);
555 Current
= Current
->Blink
;
560 Current
= Current
->Flink
;
561 while (Current
!= NULL
)
563 if (Current
->dmPelsHeight
== dmNewPelsHeight
564 && Current
->dmPelsWidth
== dmNewPelsWidth
565 && Current
->dmBitsPerPel
== pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
567 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
568 UpdateDisplay(hwndDlg
, pData
, bUpdateThumb
);
571 Current
= Current
->Flink
;
575 /* search bigger color depth compatible with current resolution */
576 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
577 while (Current
!= NULL
)
579 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
581 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
582 UpdateDisplay(hwndDlg
, pData
, bUpdateThumb
);
585 Current
= Current
->Flink
;
588 /* search smaller color depth compatible with current resolution */
589 Current
= pData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
590 while (Current
!= NULL
)
592 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
594 pData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
595 UpdateDisplay(hwndDlg
, pData
, bUpdateThumb
);
598 Current
= Current
->Blink
;
601 /* we shouldn't go there */
604 /* Property sheet page callback */
606 SettingsPageCallbackProc(HWND hwnd
, UINT uMsg
, LPPROPSHEETPAGE ppsp
)
613 Ret
= RegisterMonitorSelectionControl(hApplet
);
617 UnregisterMonitorSelectionControl(hApplet
);
624 /* Property page dialog callback */
626 SettingsPageProc(IN HWND hwndDlg
, IN UINT uMsg
, IN WPARAM wParam
, IN LPARAM lParam
)
629 TCHAR Message
[1024], Title
[256];
631 pData
= (PDATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
637 OnInitDialog(hwndDlg
);
642 LPDRAWITEMSTRUCT lpDrawItem
;
643 lpDrawItem
= (LPDRAWITEMSTRUCT
) lParam
;
645 if (lpDrawItem
->CtlID
== IDC_SETTINGS_SPECTRUM
)
646 ShowColorSpectrum(lpDrawItem
->hDC
, &lpDrawItem
->rcItem
, pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
, pData
);
651 DWORD controlId
= LOWORD(wParam
);
652 DWORD command
= HIWORD(wParam
);
654 if (controlId
== IDC_SETTINGS_ADVANCED
&& command
== BN_CLICKED
)
655 DisplayAdvancedSettings(hwndDlg
, pData
->CurrentDisplayDevice
);
656 else if (controlId
== IDC_SETTINGS_BPP
&& command
== CBN_SELCHANGE
)
657 OnBPPChanged(hwndDlg
, pData
);
662 switch (LOWORD(wParam
))
672 DWORD newPosition
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_GETPOS
, 0, 0);
673 OnResolutionChanged(hwndDlg
, pData
, newPosition
, TRUE
);
678 OnResolutionChanged(hwndDlg
, pData
, HIWORD(wParam
), FALSE
);
685 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
686 if (lpnm
->code
== (UINT
)PSN_APPLY
)
688 if (pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
!= pData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
689 || pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
!= pData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
690 || pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
!= pData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
)
692 /* FIXME: Need to test changes */
693 /* Apply new settings */
696 RtlZeroMemory(&devmode
, sizeof(DEVMODE
));
697 devmode
.dmSize
= (WORD
)sizeof(DEVMODE
);
698 devmode
.dmPelsWidth
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
699 devmode
.dmPelsHeight
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
700 devmode
.dmBitsPerPel
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
701 devmode
.dmDisplayFrequency
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmDisplayFrequency
;
702 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
| DM_BITSPERPEL
| DM_DISPLAYFREQUENCY
;
703 rc
= ChangeDisplaySettingsEx(
704 pData
->CurrentDisplayDevice
->DeviceName
,
711 case DISP_CHANGE_SUCCESSFUL
:
712 pData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
713 pData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
714 pData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
= pData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
716 case DISP_CHANGE_RESTART
:
717 LoadString(hApplet
, IDS_DISPLAY_SETTINGS
, Title
, sizeof(Title
) / sizeof(TCHAR
));
718 LoadString(hApplet
, IDS_APPLY_NEEDS_RESTART
, Message
, sizeof(Message
) / sizeof (TCHAR
));
719 MessageBox(hwndDlg
, Message
, Title
, MB_OK
| MB_ICONINFORMATION
);
721 case DISP_CHANGE_FAILED
:
723 LoadString(hApplet
, IDS_DISPLAY_SETTINGS
, Title
, sizeof(Title
) / sizeof(TCHAR
));
724 LoadString(hApplet
, IDS_APPLY_FAILED
, Message
, sizeof(Message
) / sizeof (TCHAR
));
725 MessageBox(hwndDlg
, Message
, Title
, MB_OK
| MB_ICONSTOP
);
741 pt
.x
= (SHORT
)LOWORD(lParam
);
742 pt
.y
= (SHORT
)HIWORD(lParam
);
744 hwndMonSel
= GetDlgItem(hwndDlg
,
745 IDC_SETTINGS_MONSEL
);
746 if ((HWND
)wParam
== hwndMonSel
)
748 if (pt
.x
== -1 && pt
.y
== -1)
752 Index
= (INT
)SendMessage(hwndMonSel
,
758 (INT
)SendMessage(hwndMonSel
,
763 pt
.x
= rcMon
.left
+ ((rcMon
.right
- rcMon
.left
) / 2);
764 pt
.y
= rcMon
.top
+ ((rcMon
.bottom
- rcMon
.top
) / 2);
769 MapWindowPoints(hwndMonSel
,
777 MapWindowPoints(NULL
,
782 Index
= (INT
)SendMessage(hwndMonSel
,
790 hPopup
= LoadPopupMenu(hApplet
,
791 MAKEINTRESOURCE(IDM_MONITOR_MENU
));
794 /* FIXME: Enable/Disable menu items */
795 EnableMenuItem(hPopup
,
797 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
798 EnableMenuItem(hPopup
,
800 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
801 EnableMenuItem(hPopup
,
803 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
804 EnableMenuItem(hPopup
,
806 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
808 uiCmd
= (UINT
)TrackPopupMenu(hPopup
,
809 TPM_RETURNCMD
| TPM_RIGHTBUTTON
,
818 case ID_MENU_ATTACHED
:
819 case ID_MENU_PRIMARY
:
820 case ID_MENU_IDENTIFY
:
821 case ID_MENU_PROPERTIES
:
822 /* FIXME: Implement */
836 PDISPLAY_DEVICE_ENTRY Current
= pData
->DisplayDeviceList
;
838 while (Current
!= NULL
)
840 PDISPLAY_DEVICE_ENTRY Next
= Current
->Flink
;
841 PSETTINGS_ENTRY CurrentSettings
= Current
->Settings
;
842 while (CurrentSettings
!= NULL
)
844 PSETTINGS_ENTRY NextSettings
= CurrentSettings
->Flink
;
845 HeapFree(GetProcessHeap(), 0, CurrentSettings
);
846 CurrentSettings
= NextSettings
;
848 HeapFree(GetProcessHeap(), 0, Current
);
852 for (i
= 0; i
< NUM_SPECTRUM_BITMAPS
; i
++)
854 if (pData
->hSpectrumBitmaps
[i
])
855 DeleteObject(pData
->hSpectrumBitmaps
[i
]);
858 HeapFree(GetProcessHeap(), 0, pData
);