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,15 +98,14 @@ 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;
if (devmode.dmPelsWidth < 640 || if (devmode.dmPelsWidth < 640 ||
devmode.dmPelsHeight < 480 || checkbpp == 0) devmode.dmPelsHeight < 480 || checkbpp == 0)
{ {
iMode++; iMode++;
continue; continue;
} }
Current = HeapAlloc(GetProcessHeap(), 0, sizeof(SETTINGS_ENTRY)); Current = HeapAlloc(GetProcessHeap(), 0, sizeof(SETTINGS_ENTRY));
@ -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
@ -267,7 +266,7 @@ OnInitDialog(IN HWND hwndDlg)
DWORD Result = 0; DWORD Result = 0;
DWORD iDevNum = 0; DWORD iDevNum = 0;
DISPLAY_DEVICE displayDevice; DISPLAY_DEVICE displayDevice;
BITMAP bitmap; BITMAP bitmap;
/* Get video cards list */ /* Get video cards list */
displayDevice.cb = (DWORD)sizeof(DISPLAY_DEVICE); displayDevice.cb = (DWORD)sizeof(DISPLAY_DEVICE);
@ -275,8 +274,8 @@ 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++;
} }
@ -300,14 +299,14 @@ OnInitDialog(IN HWND hwndDlg)
/* FIXME: choose selected adapter being the primary one */ /* FIXME: choose selected adapter being the primary one */
} }
hBitmap = LoadImage(hApplet, MAKEINTRESOURCE(IDC_MONITOR), IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT); hBitmap = LoadImage(hApplet, MAKEINTRESOURCE(IDC_MONITOR), IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
if (hBitmap != NULL) if (hBitmap != NULL)
{ {
GetObject(hBitmap, sizeof(BITMAP), &bitmap); GetObject(hBitmap, sizeof(BITMAP), &bitmap);
cxSource = bitmap.bmWidth; cxSource = bitmap.bmWidth;
cySource = bitmap.bmHeight; cySource = bitmap.bmHeight;
} }
} }
static VOID static VOID
@ -572,22 +571,23 @@ SettingsPageProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lPar
break; break;
} }
case WM_PAINT: case WM_PAINT:
{ {
PAINTSTRUCT ps; PAINTSTRUCT ps;
HDC hdc, hdcMem; HDC hdc, hdcMem;
hdc = BeginPaint(hwndDlg, &ps); hdc = BeginPaint(hwndDlg, &ps);
hdcMem = CreateCompatibleDC(hdc); hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem, hBitmap); SelectObject(hdcMem, hBitmap);
TransparentBlt(hdc, 98, 0, cxSource, cySource, hdcMem, 0, 0, cxSource, cySource, 0xFF80FF); TransparentBlt(hdc, 98, 0, cxSource, cySource, hdcMem, 0, 0, cxSource, cySource, 0xFF80FF);
DeleteDC(hdcMem); DeleteDC(hdcMem);
EndPaint(hwndDlg, &ps); EndPaint(hwndDlg, &ps);
} break; break;
}
case WM_DESTROY: case WM_DESTROY:
{ {
@ -606,7 +606,7 @@ SettingsPageProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lPar
Current = Next; Current = Next;
} }
DeleteObject(hBitmap); DeleteObject(hBitmap);
} }
} }
return FALSE; return FALSE;