Don't crash when no working display adapter is present

svn path=/trunk/; revision=22206
This commit is contained in:
Hervé Poussineau 2006-06-04 14:09:29 +00:00
parent cc12e88784
commit c373b8ba66

View file

@ -1,12 +1,11 @@
/* $Id$ /*
*
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS Display Control Panel * PROJECT: ReactOS Display Control Panel
* FILE: lib/cpl/desk/settings.c * FILE: lib/cpl/desk/settings.c
* PURPOSE: Settings property page * PURPOSE: Settings property page
* *
* PROGRAMMERS: Trevor McCort (lycan359@gmail.com) * PROGRAMMERS: Trevor McCort (lycan359@gmail.com)
* Hervé Poussineau (poussine@freesurf.fr) * Hervé Poussineau (hpoussin@reactos.org)
*/ */
#include "desk.h" #include "desk.h"
@ -59,7 +58,6 @@ UpdateDisplay(IN HWND hwndDlg)
_stprintf(Buffer, Pixel, CurrentDisplayDevice->CurrentSettings->dmPelsWidth, CurrentDisplayDevice->CurrentSettings->dmPelsHeight, Pixel); _stprintf(Buffer, Pixel, CurrentDisplayDevice->CurrentSettings->dmPelsWidth, CurrentDisplayDevice->CurrentSettings->dmPelsHeight, Pixel);
SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION_TEXT, WM_SETTEXT, 0, (LPARAM)Buffer); SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION_TEXT, WM_SETTEXT, 0, (LPARAM)Buffer);
for (index = 0; index < CurrentDisplayDevice->ResolutionsCount; index++) for (index = 0; index < CurrentDisplayDevice->ResolutionsCount; index++)
{ {
@ -100,7 +98,6 @@ GetPossibleSettings(IN LPTSTR DeviceName, OUT DWORD* pSettingsCount, OUT PSETTIN
devmode.dmDriverExtra = 0; devmode.dmDriverExtra = 0;
while (EnumDisplaySettingsEx(DeviceName, iMode, &devmode, dwFlags)) while (EnumDisplaySettingsEx(DeviceName, iMode, &devmode, dwFlags))
{ {
if (devmode.dmBitsPerPel==8 || devmode.dmBitsPerPel==16 || devmode.dmBitsPerPel==24 || devmode.dmBitsPerPel==32) checkbpp=1; if (devmode.dmBitsPerPel==8 || devmode.dmBitsPerPel==16 || devmode.dmBitsPerPel==24 || devmode.dmBitsPerPel==32) checkbpp=1;
else checkbpp=0; else checkbpp=0;
@ -151,7 +148,7 @@ GetPossibleSettings(IN LPTSTR DeviceName, OUT DWORD* pSettingsCount, OUT PSETTIN
return Settings; return Settings;
} }
static VOID static BOOL
AddDisplayDevice(IN LPTSTR Description, IN LPTSTR DeviceName) AddDisplayDevice(IN LPTSTR Description, IN LPTSTR DeviceName)
{ {
PDISPLAY_DEVICE_ENTRY newEntry = NULL; PDISPLAY_DEVICE_ENTRY newEntry = NULL;
@ -164,6 +161,7 @@ AddDisplayDevice(IN LPTSTR Description, IN LPTSTR DeviceName)
DWORD i; DWORD i;
newEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(DISPLAY_DEVICE_ENTRY)); newEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(DISPLAY_DEVICE_ENTRY));
memset(newEntry, 0, sizeof(DISPLAY_DEVICE_ENTRY));
if (!newEntry) goto ByeBye; if (!newEntry) goto ByeBye;
newEntry->Settings = GetPossibleSettings(DeviceName, &newEntry->SettingsCount, &newEntry->CurrentSettings); newEntry->Settings = GetPossibleSettings(DeviceName, &newEntry->SettingsCount, &newEntry->CurrentSettings);
@ -205,7 +203,7 @@ AddDisplayDevice(IN LPTSTR Description, IN LPTSTR DeviceName)
newEntry->DeviceName = name; newEntry->DeviceName = name;
newEntry->Flink = DisplayDeviceList; newEntry->Flink = DisplayDeviceList;
DisplayDeviceList = newEntry; DisplayDeviceList = newEntry;
return; return TRUE;
ByeBye: ByeBye:
if (newEntry != NULL) if (newEntry != NULL)
@ -228,6 +226,7 @@ ByeBye:
HeapFree(GetProcessHeap(), 0, description); HeapFree(GetProcessHeap(), 0, description);
if (name != NULL) if (name != NULL)
HeapFree(GetProcessHeap(), 0, name); HeapFree(GetProcessHeap(), 0, name);
return FALSE;
} }
static VOID static VOID
@ -275,7 +274,7 @@ OnInitDialog(IN HWND hwndDlg)
{ {
if ((displayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0) if ((displayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0)
{ {
AddDisplayDevice(displayDevice.DeviceString, displayDevice.DeviceName); if (AddDisplayDevice(displayDevice.DeviceString, displayDevice.DeviceName))
Result++; Result++;
} }
iDevNum++; iDevNum++;
@ -587,7 +586,8 @@ SettingsPageProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lPar
DeleteDC(hdcMem); DeleteDC(hdcMem);
EndPaint(hwndDlg, &ps); EndPaint(hwndDlg, &ps);
} break; break;
}
case WM_DESTROY: case WM_DESTROY:
{ {