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
;
21 } GLOBAL_DATA
, *PGLOBAL_DATA
;
24 UpdateDisplay(IN HWND hwndDlg
, PGLOBAL_DATA pGlobalData
, IN BOOL bUpdateThumb
)
30 LoadString(hApplet
, IDS_PIXEL
, Pixel
, sizeof(Pixel
) / sizeof(TCHAR
));
31 _stprintf(Buffer
, Pixel
, pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
, pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
, Pixel
);
32 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION_TEXT
, WM_SETTEXT
, 0, (LPARAM
)Buffer
);
34 for (index
= 0; index
< pGlobalData
->CurrentDisplayDevice
->ResolutionsCount
; index
++)
36 if (pGlobalData
->CurrentDisplayDevice
->Resolutions
[index
].dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
&&
37 pGlobalData
->CurrentDisplayDevice
->Resolutions
[index
].dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
)
40 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_SETPOS
, TRUE
, index
);
44 if (LoadString(hApplet
, (2900 + pGlobalData
->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
;
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
==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 while (Next
!= NULL
&& (
110 Next
->dmPelsWidth
< Current
->dmPelsWidth
||
111 (Next
->dmPelsWidth
== Current
->dmPelsWidth
&& Next
->dmPelsHeight
< Current
->dmPelsHeight
) ||
112 (Next
->dmPelsHeight
== Current
->dmPelsHeight
&&
113 Next
->dmPelsWidth
== Current
->dmPelsWidth
&&
114 Next
->dmBitsPerPel
< Current
->dmBitsPerPel
)))
119 Current
->Blink
= Previous
;
120 Current
->Flink
= Next
;
121 if (Previous
== NULL
)
124 Previous
->Flink
= Current
;
126 Next
->Blink
= Current
;
127 if (devmode
.dmPelsWidth
== xres
&& devmode
.dmPelsHeight
== yres
&& devmode
.dmBitsPerPel
== bpp
)
129 *CurrentSettings
= Current
;
136 *pSettingsCount
= NbSettings
;
141 AddDisplayDevice(IN PGLOBAL_DATA pGlobalData
, IN
const DISPLAY_DEVICE
*DisplayDevice
)
143 PDISPLAY_DEVICE_ENTRY newEntry
= NULL
;
144 LPTSTR description
= NULL
;
148 DWORD descriptionSize
, nameSize
, keySize
, devidSize
;
149 PSETTINGS_ENTRY Current
;
150 DWORD ResolutionsCount
= 1;
153 newEntry
= HeapAlloc(GetProcessHeap(), 0, sizeof(DISPLAY_DEVICE_ENTRY
));
154 memset(newEntry
, 0, 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
= pGlobalData
->DisplayDeviceList
;
219 pGlobalData
->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
);
246 HeapFree(GetProcessHeap(), 0, devid
);
251 OnDisplayDeviceChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
, IN PDISPLAY_DEVICE_ENTRY pDeviceEntry
)
253 PSETTINGS_ENTRY Current
;
256 pGlobalData
->CurrentDisplayDevice
= pDeviceEntry
; /* Update global variable */
258 /* Fill color depths combo box */
259 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_RESETCONTENT
, 0, 0);
260 for (Current
= pDeviceEntry
->Settings
; Current
!= NULL
; Current
= Current
->Flink
)
263 if (LoadString(hApplet
, (2900 + Current
->dmBitsPerPel
), Buffer
, sizeof(Buffer
) / sizeof(TCHAR
)))
265 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_FINDSTRINGEXACT
, (WPARAM
)-1, (LPARAM
)Buffer
);
266 if (index
== (DWORD
)CB_ERR
)
268 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_ADDSTRING
, 0, (LPARAM
)Buffer
);
269 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_SETITEMDATA
, index
, Current
->dmBitsPerPel
);
274 /* Fill resolutions slider */
275 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_CLEARTICS
, TRUE
, 0);
276 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_SETRANGE
, TRUE
, MAKELONG(0, pDeviceEntry
->ResolutionsCount
- 1));
278 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
282 OnInitDialog(IN HWND hwndDlg
)
286 DISPLAY_DEVICE displayDevice
;
288 PGLOBAL_DATA pGlobalData
;
290 pGlobalData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(GLOBAL_DATA
));
291 if (pGlobalData
== NULL
)
294 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pGlobalData
);
296 /* Get video cards list */
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(pGlobalData
, &displayDevice
))
309 /* No adapter found */
310 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_BPP
), FALSE
);
311 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION
), FALSE
);
312 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_RESOLUTION_TEXT
), FALSE
);
313 EnableWindow(GetDlgItem(hwndDlg
, IDC_SETTINGS_ADVANCED
), FALSE
);
315 else if (Result
== 1)
317 /* Single video adapter */
318 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_DEVICE
, WM_SETTEXT
, 0, (LPARAM
)pGlobalData
->DisplayDeviceList
->DeviceDescription
);
319 OnDisplayDeviceChanged(hwndDlg
, pGlobalData
, pGlobalData
->DisplayDeviceList
);
323 /* FIXME: multi video adapter */
324 /* FIXME: choose selected adapter being the primary one */
327 pGlobalData
->hBitmap
= LoadImage(hApplet
, MAKEINTRESOURCE(IDC_MONITOR
), IMAGE_BITMAP
, 0, 0, LR_LOADTRANSPARENT
);
328 if (pGlobalData
->hBitmap
!= NULL
)
330 GetObject(pGlobalData
->hBitmap
, sizeof(BITMAP
), &bitmap
);
332 pGlobalData
->cxSource
= bitmap
.bmWidth
;
333 pGlobalData
->cySource
= bitmap
.bmHeight
;
338 OnBPPChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
)
340 /* if new BPP is not compatible with resolution:
341 * 1) try to find the nearest smaller matching resolution
342 * 2) otherwise, get the nearest bigger resolution
344 PSETTINGS_ENTRY Current
;
345 DWORD dmNewBitsPerPel
;
349 SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, WM_GETTEXT
, (WPARAM
)(sizeof(Buffer
) / sizeof(TCHAR
)), (LPARAM
)Buffer
);
350 index
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_FINDSTRINGEXACT
, (WPARAM
)-1, (LPARAM
)Buffer
);
351 dmNewBitsPerPel
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_BPP
, CB_GETITEMDATA
, index
, 0);
353 /* find if new parameters are valid */
354 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
;
355 if (dmNewBitsPerPel
== Current
->dmBitsPerPel
)
361 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
363 if (dmNewBitsPerPel
< Current
->dmBitsPerPel
)
365 Current
= Current
->Blink
;
366 while (Current
!= NULL
)
368 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
369 && Current
->dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
370 && Current
->dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
372 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
373 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
376 Current
= Current
->Blink
;
381 Current
= Current
->Flink
;
382 while (Current
!= NULL
)
384 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
385 && Current
->dmPelsHeight
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
386 && Current
->dmPelsWidth
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
)
388 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
389 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
392 Current
= Current
->Flink
;
396 /* search smaller resolution compatible with current color depth */
397 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
398 while (Current
!= NULL
)
400 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
402 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
403 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
406 Current
= Current
->Blink
;
409 /* search bigger resolution compatible with current color depth */
410 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
411 while (Current
!= NULL
)
413 if (Current
->dmBitsPerPel
== dmNewBitsPerPel
)
415 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
416 UpdateDisplay(hwndDlg
, pGlobalData
, TRUE
);
419 Current
= Current
->Flink
;
422 /* we shouldn't go there */
426 OnResolutionChanged(IN HWND hwndDlg
, IN PGLOBAL_DATA pGlobalData
, IN DWORD NewPosition
,
427 IN BOOL bUpdateThumb
)
429 /* if new resolution is not compatible with color depth:
430 * 1) try to find the nearest bigger matching color depth
431 * 2) otherwise, get the nearest smaller color depth
433 PSETTINGS_ENTRY Current
;
434 DWORD dmNewPelsHeight
= pGlobalData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsHeight
;
435 DWORD dmNewPelsWidth
= pGlobalData
->CurrentDisplayDevice
->Resolutions
[NewPosition
].dmPelsWidth
;
437 /* find if new parameters are valid */
438 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
;
439 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
445 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
447 if (dmNewPelsHeight
< Current
->dmPelsHeight
)
449 Current
= Current
->Blink
;
450 while (Current
!= NULL
)
452 if (Current
->dmPelsHeight
== dmNewPelsHeight
453 && Current
->dmPelsWidth
== dmNewPelsWidth
454 && Current
->dmBitsPerPel
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
456 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
457 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
460 Current
= Current
->Blink
;
465 Current
= Current
->Flink
;
466 while (Current
!= NULL
)
468 if (Current
->dmPelsHeight
== dmNewPelsHeight
469 && Current
->dmPelsWidth
== dmNewPelsWidth
470 && Current
->dmBitsPerPel
== pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
)
472 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
473 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
476 Current
= Current
->Flink
;
480 /* search bigger color depth compatible with current resolution */
481 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Flink
;
482 while (Current
!= NULL
)
484 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
486 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
487 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
490 Current
= Current
->Flink
;
493 /* search smaller color depth compatible with current resolution */
494 Current
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->Blink
;
495 while (Current
!= NULL
)
497 if (dmNewPelsHeight
== Current
->dmPelsHeight
&& dmNewPelsWidth
== Current
->dmPelsWidth
)
499 pGlobalData
->CurrentDisplayDevice
->CurrentSettings
= Current
;
500 UpdateDisplay(hwndDlg
, pGlobalData
, bUpdateThumb
);
503 Current
= Current
->Blink
;
506 /* we shouldn't go there */
509 /* Property sheet page callback */
511 SettingsPageCallbackProc(HWND hwnd
, UINT uMsg
, LPPROPSHEETPAGE ppsp
)
518 Ret
= RegisterMonitorSelectionControl(hApplet
);
522 UnregisterMonitorSelectionControl(hApplet
);
529 /* Property page dialog callback */
531 SettingsPageProc(IN HWND hwndDlg
, IN UINT uMsg
, IN WPARAM wParam
, IN LPARAM lParam
)
533 PGLOBAL_DATA pGlobalData
;
535 pGlobalData
= (PGLOBAL_DATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
540 OnInitDialog(hwndDlg
);
544 DWORD controlId
= LOWORD(wParam
);
545 DWORD command
= HIWORD(wParam
);
547 if (controlId
== IDC_SETTINGS_ADVANCED
&& command
== BN_CLICKED
)
548 DisplayAdvancedSettings(hwndDlg
, pGlobalData
->CurrentDisplayDevice
);
549 else if (controlId
== IDC_SETTINGS_BPP
&& command
== CBN_SELCHANGE
)
550 OnBPPChanged(hwndDlg
, pGlobalData
);
555 switch (LOWORD(wParam
))
565 DWORD newPosition
= (DWORD
) SendDlgItemMessage(hwndDlg
, IDC_SETTINGS_RESOLUTION
, TBM_GETPOS
, 0, 0);
566 OnResolutionChanged(hwndDlg
, pGlobalData
, newPosition
, TRUE
);
571 OnResolutionChanged(hwndDlg
, pGlobalData
, HIWORD(wParam
), FALSE
);
578 LPNMHDR lpnm
= (LPNMHDR
)lParam
;
579 if (lpnm
->code
== (UINT
)PSN_APPLY
)
581 if (pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
582 || pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
583 || pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
!= pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
)
585 /* FIXME: Need to test changes */
586 /* Apply new settings */
589 RtlZeroMemory(&devmode
, sizeof(DEVMODE
));
590 devmode
.dmSize
= (WORD
)sizeof(DEVMODE
);
591 devmode
.dmPelsWidth
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
592 devmode
.dmPelsHeight
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
593 devmode
.dmBitsPerPel
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
594 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
| DM_BITSPERPEL
;
595 rc
= ChangeDisplaySettingsEx(
596 pGlobalData
->CurrentDisplayDevice
->DeviceName
,
603 case DISP_CHANGE_SUCCESSFUL
:
604 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsWidth
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsWidth
;
605 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmPelsHeight
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmPelsHeight
;
606 pGlobalData
->CurrentDisplayDevice
->InitialSettings
.dmBitsPerPel
= pGlobalData
->CurrentDisplayDevice
->CurrentSettings
->dmBitsPerPel
;
608 case DISP_CHANGE_FAILED
:
609 MessageBox(NULL
, TEXT("Failed to apply new settings..."), TEXT("Display settings"), MB_OK
| MB_ICONSTOP
);
611 case DISP_CHANGE_RESTART
:
612 MessageBox(NULL
, TEXT("You need to restart your computer to apply changes."), TEXT("Display settings"), MB_OK
| MB_ICONINFORMATION
);
615 MessageBox(NULL
, TEXT("Unknown error when applying new settings..."), TEXT("Display settings"), MB_OK
| MB_ICONSTOP
);
628 hdc
= BeginPaint(hwndDlg
, &ps
);
630 hdcMem
= CreateCompatibleDC(hdc
);
631 SelectObject(hdcMem
, pGlobalData
->hBitmap
);
633 TransparentBlt(hdc, 98, 0,
634 pGlobalData->cxSource,
635 pGlobalData->cySource, hdcMem, 0, 0,
636 pGlobalData->cxSource,
637 pGlobalData->cySource, 0xFF80FF);
640 EndPaint(hwndDlg
, &ps
);
647 PDISPLAY_DEVICE_ENTRY Current
= pGlobalData
->DisplayDeviceList
;
648 while (Current
!= NULL
)
650 PDISPLAY_DEVICE_ENTRY Next
= Current
->Flink
;
651 PSETTINGS_ENTRY CurrentSettings
= Current
->Settings
;
652 while (CurrentSettings
!= NULL
)
654 PSETTINGS_ENTRY NextSettings
= CurrentSettings
->Flink
;
655 HeapFree(GetProcessHeap(), 0, CurrentSettings
);
656 CurrentSettings
= NextSettings
;
658 HeapFree(GetProcessHeap(), 0, Current
);
662 DeleteObject(pGlobalData
->hBitmap
);
664 HeapFree(GetProcessHeap(), 0, pGlobalData
);