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 } GLOBAL_DATA
, *PGLOBAL_DATA
;
21 UpdateDisplay(IN HWND hwndDlg
, PGLOBAL_DATA pGlobalData
, IN BOOL bUpdateThumb
)
27 LoadString(hApplet
, IDS_PIXEL
, Pixel
, sizeof(Pixel
) / sizeof(TCHAR
));
28 _stprintf(Buffer
, Pixel
, pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
, pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
, Pixel
);
29 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION_TEXT
, WM_SETTEXT
, 0, (LPARAM
)Buffer
);
31 for (index
= 0; index
< pGlobalData
->CurrentDisplayDevice
->ResolutionsCount
; index
++)
33 if (pGlobalData
->CurrentDisplayDevice
->Resolutions
[index
].dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
&&
34 pGlobalData
->CurrentDisplayDevice
->Resolutions
[index
].dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
)
37 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_SETPOS
, TRUE
, index
);
41 if (LoadString(hApplet
, (2900 + pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
), Buffer
, sizeof(Buffer
) / sizeof(TCHAR
)))
42 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_SELECTSTRING
, (WPARAM
)-1, (LPARAM
)Buffer
);
45 static PSETTINGS_ENTRY
46 GetPossibleSettings(IN LPCTSTR DeviceName
, OUT DWORD
* pSettingsCount
, OUT PSETTINGS_ENTRY
* CurrentSettings
)
52 PSETTINGS_ENTRY Settings
= NULL
;
54 PSETTINGS_ENTRY Current
;
55 DWORD bpp
, xres
, yres
, checkbpp
;
59 /* Get current settings */
60 *CurrentSettings
= NULL
;
61 hDC
= CreateIC(NULL
, DeviceName
, NULL
, NULL
);
62 bpp
= GetDeviceCaps(hDC
, PLANES
);
63 bpp
*= GetDeviceCaps(hDC
, BITSPIXEL
);
64 xres
= GetDeviceCaps(hDC
, HORZRES
);
65 yres
= GetDeviceCaps(hDC
, VERTRES
);
68 /* List all settings */
69 devmode
.dmSize
= (WORD
)sizeof(DEVMODE
);
70 devmode
.dmDriverExtra
= 0;
72 if (!EnumDisplaySettingsEx(DeviceName
, ENUM_CURRENT_SETTINGS
, &devmode
, dwFlags
))
75 curDispFreq
= devmode
.dmDisplayFrequency
;
77 while (EnumDisplaySettingsEx(DeviceName
, iMode
, &devmode
, dwFlags
))
79 if ((devmode
.dmBitsPerPel
==8 ||
80 devmode
.dmBitsPerPel
==16 ||
81 devmode
.dmBitsPerPel
==24 ||
82 devmode
.dmBitsPerPel
==32) &&
83 devmode
.dmDisplayFrequency
==curDispFreq
)
90 if (devmode
.dmPelsWidth
< 640 ||
91 devmode
.dmPelsHeight
< 480 || checkbpp
== 0)
97 Current
= HeapAlloc(GetProcessHeap(), 0, sizeof(SETTINGS_ENTRY
));
100 /* Sort resolutions by increasing height, and BPP */
101 PSETTINGS_ENTRY Previous
= NULL
;
102 PSETTINGS_ENTRY Next
= Settings
;
103 Current
->dmPelsWidth
= devmode
.dmPelsWidth
;
104 Current
->dmPelsHeight
= devmode
.dmPelsHeight
;
105 Current
->dmBitsPerPel
= devmode
.dmBitsPerPel
;
106 while (Next
!= NULL
&& (
107 Next
->dmPelsWidth
< Current
->dmPelsWidth
||
108 (Next
->dmPelsWidth
== Current
->dmPelsWidth
&& Next
->dmPelsHeight
< Current
->dmPelsHeight
) ||
109 (Next
->dmPelsHeight
== Current
->dmPelsHeight
&&
110 Next
->dmPelsWidth
== Current
->dmPelsWidth
&&
111 Next
->dmBitsPerPel
< Current
->dmBitsPerPel
)))
116 Current
->Blink
= Previous
;
117 Current
->Flink
= Next
;
118 if (Previous
== NULL
)
121 Previous
->Flink
= Current
;
123 Next
->Blink
= Current
;
124 if (devmode
.dmPelsWidth
== xres
&& devmode
.dmPelsHeight
== yres
&& devmode
.dmBitsPerPel
== bpp
)
126 *CurrentSettings
= Current
;
133 *pSettingsCount
= NbSettings
;
138 AddDisplayDevice(IN PGLOBAL_DATA pGlobalData
, IN
const DISPLAY_DEVICE
*DisplayDevice
)
140 PDISPLAY_DEVICE_ENTRY newEntry
= NULL
;
141 LPTSTR description
= NULL
;
145 DWORD descriptionSize
, nameSize
, keySize
, devidSize
;
146 PSETTINGS_ENTRY Current
;
147 DWORD ResolutionsCount
= 1;
150 newEntry
= HeapAlloc(GetProcessHeap(), 0, sizeof(DISPLAY_DEVICE_ENTRY
));
151 memset(newEntry
, 0, sizeof(DISPLAY_DEVICE_ENTRY
));
152 if (!newEntry
) goto ByeBye
;
154 newEntry
->Settings
= GetPossibleSettings(DisplayDevice
->DeviceName
, &newEntry
->SettingsCount
, &newEntry
->CurrentSettings
);
155 if (!newEntry
->Settings
) goto ByeBye
;
157 newEntry
->InitialSettings
.dmPelsWidth
= newEntry
->CurrentSettings
->dmPelsWidth
;
158 newEntry
->InitialSettings
.dmPelsHeight
= newEntry
->CurrentSettings
->dmPelsHeight
;
159 newEntry
->InitialSettings
.dmBitsPerPel
= newEntry
->CurrentSettings
->dmBitsPerPel
;
161 /* Count different resolutions */
162 for (Current
= newEntry
->Settings
; Current
!= NULL
; Current
= Current
->Flink
)
164 if (Current
->Flink
!= NULL
&&
165 ((Current
->dmPelsWidth
!= Current
->Flink
->dmPelsWidth
) &&
166 (Current
->dmPelsHeight
!= Current
->Flink
->dmPelsHeight
)))
172 newEntry
->Resolutions
= HeapAlloc(GetProcessHeap(), 0, ResolutionsCount
* sizeof(RESOLUTION_INFO
));
173 if (!newEntry
->Resolutions
) goto ByeBye
;
175 newEntry
->ResolutionsCount
= ResolutionsCount
;
177 /* Fill resolutions infos */
178 for (Current
= newEntry
->Settings
, i
= 0; Current
!= NULL
; Current
= Current
->Flink
)
180 if (Current
->Flink
== NULL
||
181 (Current
->Flink
!= NULL
&&
182 ((Current
->dmPelsWidth
!= Current
->Flink
->dmPelsWidth
) &&
183 (Current
->dmPelsHeight
!= Current
->Flink
->dmPelsHeight
))))
185 newEntry
->Resolutions
[i
].dmPelsWidth
= Current
->dmPelsWidth
;
186 newEntry
->Resolutions
[i
].dmPelsHeight
= Current
->dmPelsHeight
;
190 descriptionSize
= (_tcslen(DisplayDevice
->DeviceString
) + 1) * sizeof(TCHAR
);
191 description
= HeapAlloc(GetProcessHeap(), 0, descriptionSize
);
192 if (!description
) goto ByeBye
;
194 nameSize
= (_tcslen(DisplayDevice
->DeviceName
) + 1) * sizeof(TCHAR
);
195 name
= HeapAlloc(GetProcessHeap(), 0, nameSize
);
196 if (!name
) goto ByeBye
;
198 keySize
= (_tcslen(DisplayDevice
->DeviceKey
) + 1) * sizeof(TCHAR
);
199 key
= HeapAlloc(GetProcessHeap(), 0, keySize
);
200 if (!key
) goto ByeBye
;
202 devidSize
= (_tcslen(DisplayDevice
->DeviceID
) + 1) * sizeof(TCHAR
);
203 devid
= HeapAlloc(GetProcessHeap(), 0, devidSize
);
204 if (!devid
) goto ByeBye
;
206 memcpy(description
, DisplayDevice
->DeviceString
, descriptionSize
);
207 memcpy(name
, DisplayDevice
->DeviceName
, nameSize
);
208 memcpy(key
, DisplayDevice
->DeviceKey
, keySize
);
209 memcpy(devid
, DisplayDevice
->DeviceID
, devidSize
);
210 newEntry
->DeviceDescription
= description
;
211 newEntry
->DeviceName
= name
;
212 newEntry
->DeviceKey
= key
;
213 newEntry
->DeviceID
= devid
;
214 newEntry
->DeviceStateFlags
= DisplayDevice
->StateFlags
;
215 newEntry
->Flink
= pGlobalData
->DisplayDeviceList
;
216 pGlobalData
->DisplayDeviceList
= newEntry
;
220 if (newEntry
!= NULL
)
222 if (newEntry
->Settings
!= NULL
)
224 Current
= newEntry
->Settings
;
225 while (Current
!= NULL
)
227 PSETTINGS_ENTRY Next
= Current
->Flink
;
228 HeapFree(GetProcessHeap(), 0, Current
);
232 if (newEntry
->Resolutions
!= NULL
)
233 HeapFree(GetProcessHeap(), 0, newEntry
->Resolutions
);
234 HeapFree(GetProcessHeap(), 0, newEntry
);
236 if (description
!= NULL
)
237 HeapFree(GetProcessHeap(), 0, description
);
239 HeapFree(GetProcessHeap(), 0, name
);
241 HeapFree(GetProcessHeap(), 0, key
);
243 HeapFree(GetProcessHeap(), 0, devid
);
248 OnDisplayDeviceChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
, IN PDISPLAY_DEVICE_ENTRY pDeviceEntry
)
250 PSETTINGS_ENTRY Current
;
253 pGlobalData
->CurrentDisplayDevice
= pDeviceEntry
; /* Update global variable */
255 /* Fill color depths combo box */
256 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_RESETCONTENT
, 0, 0);
257 for (Current
= pDeviceEntry
->Settings
; Current
!= NULL
; Current
= Current
->Flink
)
260 if (LoadString(hApplet
, (2900 + Current
->dmBitsPerPel
), Buffer
, sizeof(Buffer
) / sizeof(TCHAR
)))
262 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_FINDSTRINGEXACT
, (WPARAM
)-1, (LPARAM
)Buffer
);
263 if (index
== (DWORD
)CB_ERR
)
265 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_ADDSTRING
, 0, (LPARAM
)Buffer
);
266 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_SETITEMDATA
, index
, Current
->dmBitsPerPel
);
271 /* Fill resolutions slider */
272 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_CLEARTICS
, TRUE
, 0);
273 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_SETRANGE
, TRUE
, MAKELONG(0, pDeviceEntry
->ResolutionsCount
- 1));
275 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
279 OnInitDialog(IN HWND hwndDlg
)
283 DISPLAY_DEVICE displayDevice
;
284 PGLOBAL_DATA pGlobalData
;
286 pGlobalData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(GLOBAL_DATA
));
287 if (pGlobalData
== NULL
)
290 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pGlobalData
);
292 /* Get video cards list */
293 displayDevice
.cb
= (DWORD
)sizeof(DISPLAY_DEVICE
);
294 while (EnumDisplayDevices(NULL
, iDevNum
, &displayDevice
, 0x1))
296 if ((displayDevice
.StateFlags
& DISPLAY_DEVICE_ATTACHED_TO_DESKTOP
) != 0)
298 if (AddDisplayDevice(pGlobalData
, &displayDevice
))
305 /* No adapter found */
306 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_BPP
), FALSE
);
307 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION
), FALSE
);
308 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION_TEXT
), FALSE
);
309 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_ADVANCED
), FALSE
);
311 else if (Result
== 1)
313 MONSL_MONINFO monitors
;
315 /* Single video adapter */
316 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pGlobalData
->DisplayDeviceList
->DeviceDescription
);
317 OnDisplayDeviceChanged(hwndDlg
, pGlobalData
, pGlobalData
->DisplayDeviceList
);
319 monitors
.Position
.x
= monitors
.Position
.y
= 0;
320 monitors
.Size
.cx
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
321 monitors
.Size
.cy
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
323 SendDlgItemMessage(hwndDlg
,
325 MSLM_SETMONITORSINFO
,
329 else /* FIXME: incomplete! */
331 PMONSL_MONINFO pMonitors
;
334 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pGlobalData
->DisplayDeviceList
->DeviceDescription
);
335 OnDisplayDeviceChanged(hwndDlg
, pGlobalData
, pGlobalData
->DisplayDeviceList
);
337 pMonitors
= (PMONSL_MONINFO
)HeapAlloc(GetProcessHeap(), 0, sizeof(MONSL_MONINFO
) * Result
);
341 for (i
= 0; i
< Result
; i
++)
343 pMonitors
[i
].Position
.x
= hack
* i
;
344 pMonitors
[i
].Position
.y
= 0;
345 pMonitors
[i
].Size
.cx
= pGlobalData
->DisplayDeviceList
->CurrentSettings
->dmPelsWidth
;
346 pMonitors
[i
].Size
.cy
= pGlobalData
->DisplayDeviceList
->CurrentSettings
->dmPelsHeight
;
347 pMonitors
[i
].Flags
= 0;
350 SendDlgItemMessage(hwndDlg
,
352 MSLM_SETMONITORSINFO
,
356 HeapFree(GetProcessHeap(), 0, pMonitors
);
362 OnBPPChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
)
364 /* if new BPP is not compatible with resolution:
365 * 1) try to find the nearest smaller matching resolution
366 * 2) otherwise, get the nearest bigger resolution
368 PSETTINGS_ENTRY Current
;
369 DWORD dmNewBitsPerPel
;
373 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, WM_GETTEXT
, (WPARAM
)(sizeof(Buffer
) / sizeof(TCHAR
)), (LPARAM
)Buffer
);
374 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_FINDSTRINGEXACT
, (WPARAM
)-1, (LPARAM
)Buffer
);
375 dmNewBitsPerPel
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETITEMDATA
, index
, 0);
377 /* find if new parameters are valid */
378 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
;
379 if (dmNewBitsPerPel
== Current
->dmBitsPerPel
)
385 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
387 if (dmNewBitsPerPel
< Current
->dmBitsPerPel
)
389 Current
= Current
->Blink
;
390 while (Current
!= NULL
)
392 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
393 && Current
->dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
394 && Current
->dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
396 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
397 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
400 Current
= Current
->Blink
;
405 Current
= Current
->Flink
;
406 while (Current
!= NULL
)
408 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
409 && Current
->dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
410 && Current
->dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
412 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
413 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
416 Current
= Current
->Flink
;
420 /* search smaller resolution compatible with current color depth */
421 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
422 while (Current
!= NULL
)
424 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
426 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
427 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
430 Current
= Current
->Blink
;
433 /* search bigger resolution compatible with current color depth */
434 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
435 while (Current
!= NULL
)
437 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
439 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
440 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
443 Current
= Current
->Flink
;
446 /* we shouldn't go there */
450 OnResolutionChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
, IN DWORD NewPosition
,
451 IN BOOL bUpdateThumb
)
453 /* if new resolution is not compatible with color depth:
454 * 1) try to find the nearest bigger matching color depth
455 * 2) otherwise, get the nearest smaller color depth
457 PSETTINGS_ENTRY Current
;
458 DWORD dmNewPelsHeight
= pGlobalData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsHeight
;
459 DWORD dmNewPelsWidth
= pGlobalData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsWidth
;
461 /* find if new parameters are valid */
462 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
;
463 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
469 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
471 if (dmNewPelsHeight
< Current
->dmPelsHeight
)
473 Current
= Current
->Blink
;
474 while (Current
!= NULL
)
476 if (Current
->dmPelsHeight
== dmNewPelsHeight
477 && Current
->dmPelsWidth
== dmNewPelsWidth
478 && Current
->dmBitsPerPel
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
480 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
481 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
484 Current
= Current
->Blink
;
489 Current
= Current
->Flink
;
490 while (Current
!= NULL
)
492 if (Current
->dmPelsHeight
== dmNewPelsHeight
493 && Current
->dmPelsWidth
== dmNewPelsWidth
494 && Current
->dmBitsPerPel
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
496 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
497 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
500 Current
= Current
->Flink
;
504 /* search bigger color depth compatible with current resolution */
505 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
506 while (Current
!= NULL
)
508 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
510 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
511 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
514 Current
= Current
->Flink
;
517 /* search smaller color depth compatible with current resolution */
518 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
519 while (Current
!= NULL
)
521 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
523 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
524 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
527 Current
= Current
->Blink
;
530 /* we shouldn't go there */
533 /* Property sheet page callback */
535 SettingsPageCallbackProc(HWND hwnd
, UINT uMsg
, LPPROPSHEETPAGE ppsp
)
542 Ret
= RegisterMonitorSelectionControl(hApplet
);
546 UnregisterMonitorSelectionControl(hApplet
);
553 /* Property page dialog callback */
555 SettingsPageProc(IN HWND hwndDlg
, IN UINT uMsg
, IN WPARAM wParam
, IN LPARAM lParam
)
557 PGLOBAL_DATA pGlobalData
;
559 pGlobalData
= (PGLOBAL_DATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
564 OnInitDialog(hwndDlg
);
568 DWORD controlId
= LOWORD(wParam
);
569 DWORD command
= HIWORD(wParam
);
571 if (controlId
== IDC_SETTINGS_ADVANCED
&& command
== BN_CLICKED
)
572 DisplayAdvancedSettings(hwndDlg
, pGlobalData
->CurrentDisplayDevice
);
573 else if (controlId
== IDC_SETTINGS_BPP
&& command
== CBN_SELCHANGE
)
574 OnBPPChanged(hwndDlg
, pGlobalData
);
579 switch (LOWORD(wParam
))
589 DWORD newPosition
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_GETPOS
, 0, 0);
590 OnResolutionChanged(hwndDlg
, pGlobalData
, newPosition
, TRUE
);
595 OnResolutionChanged(hwndDlg
, pGlobalData
, HIWORD(wParam
), FALSE
);
602 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
603 if (lpnm
->code
== (UINT
)PSN_APPLY
)
605 if (pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
606 || pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
607 || pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
)
609 /* FIXME: Need to test changes */
610 /* Apply new settings */
613 RtlZeroMemory(&devmode
, sizeof(DEVMODE
));
614 devmode
.dmSize
= (WORD
)sizeof(DEVMODE
);
615 devmode
.dmPelsWidth
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
616 devmode
.dmPelsHeight
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
617 devmode
.dmBitsPerPel
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
618 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
| DM_BITSPERPEL
;
619 rc
= ChangeDisplaySettingsEx(
620 pGlobalData
->CurrentDisplayDevice
->DeviceName
,
627 case DISP_CHANGE_SUCCESSFUL
:
628 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
629 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
630 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
632 case DISP_CHANGE_FAILED
:
633 MessageBox(NULL
, TEXT("Failed to apply new settings..."), TEXT("Display settings"), MB_OK
| MB_ICONSTOP
);
635 case DISP_CHANGE_RESTART
:
636 MessageBox(NULL
, TEXT("You need to restart your computer to apply changes."), TEXT("Display settings"), MB_OK
| MB_ICONINFORMATION
);
639 MessageBox(NULL
, TEXT("Unknown error when applying new settings..."), TEXT("Display settings"), MB_OK
| MB_ICONSTOP
);
655 pt
.x
= (SHORT
)LOWORD(lParam
);
656 pt
.y
= (SHORT
)HIWORD(lParam
);
658 hwndMonSel
= GetDlgItem(hwndDlg
,
659 IDC_SETTINGS_MONSEL
);
660 if ((HWND
)wParam
== hwndMonSel
)
662 if (pt
.x
== -1 && pt
.y
== -1)
666 Index
= (INT
)SendMessage(hwndMonSel
,
672 (INT
)SendMessage(hwndMonSel
,
677 pt
.x
= rcMon
.left
+ ((rcMon
.right
- rcMon
.left
) / 2);
678 pt
.y
= rcMon
.top
+ ((rcMon
.bottom
- rcMon
.top
) / 2);
683 MapWindowPoints(hwndMonSel
,
691 MapWindowPoints(NULL
,
696 Index
= (INT
)SendMessage(hwndMonSel
,
704 hPopup
= LoadPopupMenu(hApplet
,
705 MAKEINTRESOURCE(IDM_MONITOR_MENU
));
708 /* FIXME: Enable/Disable menu items */
709 EnableMenuItem(hPopup
,
711 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
712 EnableMenuItem(hPopup
,
714 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
715 EnableMenuItem(hPopup
,
717 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
718 EnableMenuItem(hPopup
,
720 MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
722 uiCmd
= (UINT
)TrackPopupMenu(hPopup
,
723 TPM_RETURNCMD
| TPM_RIGHTBUTTON
,
732 case ID_MENU_ATTACHED
:
733 case ID_MENU_PRIMARY
:
734 case ID_MENU_IDENTIFY
:
735 case ID_MENU_PROPERTIES
:
736 /* FIXME: Implement */
749 PDISPLAY_DEVICE_ENTRY Current
= pGlobalData
->DisplayDeviceList
;
750 while (Current
!= NULL
)
752 PDISPLAY_DEVICE_ENTRY Next
= Current
->Flink
;
753 PSETTINGS_ENTRY CurrentSettings
= Current
->Settings
;
754 while (CurrentSettings
!= NULL
)
756 PSETTINGS_ENTRY NextSettings
= CurrentSettings
->Flink
;
757 HeapFree(GetProcessHeap(), 0, CurrentSettings
);
758 CurrentSettings
= NextSettings
;
760 HeapFree(GetProcessHeap(), 0, Current
);
764 HeapFree(GetProcessHeap(), 0, pGlobalData
);