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
* PROJECT: ReactOS Display Control Panel
* FILE: lib/cpl/desk/settings.c
* PURPOSE: Settings property page
*
* PROGRAMMERS: Trevor McCort (lycan359@gmail.com)
* Hervé Poussineau (poussine@freesurf.fr)
* Hervé Poussineau (hpoussin@reactos.org)
*/
#include "desk.h"
@ -59,7 +58,6 @@ UpdateDisplay(IN HWND hwndDlg)
_stprintf(Buffer, Pixel, CurrentDisplayDevice->CurrentSettings->dmPelsWidth, CurrentDisplayDevice->CurrentSettings->dmPelsHeight, Pixel);
SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION_TEXT, WM_SETTEXT, 0, (LPARAM)Buffer);
for (index = 0; index < CurrentDisplayDevice->ResolutionsCount; index++)
{
@ -100,15 +98,14 @@ GetPossibleSettings(IN LPTSTR DeviceName, OUT DWORD* pSettingsCount, OUT PSETTIN
devmode.dmDriverExtra = 0;
while (EnumDisplaySettingsEx(DeviceName, iMode, &devmode, dwFlags))
{
if (devmode.dmBitsPerPel==8 || devmode.dmBitsPerPel==16 || devmode.dmBitsPerPel==24 || devmode.dmBitsPerPel==32) checkbpp=1;
else checkbpp=0;
if (devmode.dmPelsWidth < 640 ||
devmode.dmPelsHeight < 480 || checkbpp == 0)
{
iMode++;
continue;
iMode++;
continue;
}
Current = HeapAlloc(GetProcessHeap(), 0, sizeof(SETTINGS_ENTRY));
@ -151,7 +148,7 @@ GetPossibleSettings(IN LPTSTR DeviceName, OUT DWORD* pSettingsCount, OUT PSETTIN
return Settings;
}
static VOID
static BOOL
AddDisplayDevice(IN LPTSTR Description, IN LPTSTR DeviceName)
{
PDISPLAY_DEVICE_ENTRY newEntry = NULL;
@ -164,6 +161,7 @@ AddDisplayDevice(IN LPTSTR Description, IN LPTSTR DeviceName)
DWORD i;
newEntry = HeapAlloc(GetProcessHeap(), 0, sizeof(DISPLAY_DEVICE_ENTRY));
memset(newEntry, 0, sizeof(DISPLAY_DEVICE_ENTRY));
if (!newEntry) goto ByeBye;
newEntry->Settings = GetPossibleSettings(DeviceName, &newEntry->SettingsCount, &newEntry->CurrentSettings);
@ -205,7 +203,7 @@ AddDisplayDevice(IN LPTSTR Description, IN LPTSTR DeviceName)
newEntry->DeviceName = name;
newEntry->Flink = DisplayDeviceList;
DisplayDeviceList = newEntry;
return;
return TRUE;
ByeBye:
if (newEntry != NULL)
@ -228,6 +226,7 @@ ByeBye:
HeapFree(GetProcessHeap(), 0, description);
if (name != NULL)
HeapFree(GetProcessHeap(), 0, name);
return FALSE;
}
static VOID
@ -267,7 +266,7 @@ OnInitDialog(IN HWND hwndDlg)
DWORD Result = 0;
DWORD iDevNum = 0;
DISPLAY_DEVICE displayDevice;
BITMAP bitmap;
BITMAP bitmap;
/* Get video cards list */
displayDevice.cb = (DWORD)sizeof(DISPLAY_DEVICE);
@ -275,8 +274,8 @@ OnInitDialog(IN HWND hwndDlg)
{
if ((displayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0)
{
AddDisplayDevice(displayDevice.DeviceString, displayDevice.DeviceName);
Result++;
if (AddDisplayDevice(displayDevice.DeviceString, displayDevice.DeviceName))
Result++;
}
iDevNum++;
}
@ -300,14 +299,14 @@ OnInitDialog(IN HWND hwndDlg)
/* FIXME: choose selected adapter being the primary one */
}
hBitmap = LoadImage(hApplet, MAKEINTRESOURCE(IDC_MONITOR), IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
if (hBitmap != NULL)
{
GetObject(hBitmap, sizeof(BITMAP), &bitmap);
hBitmap = LoadImage(hApplet, MAKEINTRESOURCE(IDC_MONITOR), IMAGE_BITMAP, 0, 0, LR_LOADTRANSPARENT);
if (hBitmap != NULL)
{
GetObject(hBitmap, sizeof(BITMAP), &bitmap);
cxSource = bitmap.bmWidth;
cySource = bitmap.bmHeight;
}
cxSource = bitmap.bmWidth;
cySource = bitmap.bmHeight;
}
}
static VOID
@ -572,22 +571,23 @@ SettingsPageProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lPar
break;
}
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc, hdcMem;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc, hdcMem;
hdc = BeginPaint(hwndDlg, &ps);
hdc = BeginPaint(hwndDlg, &ps);
hdcMem = CreateCompatibleDC(hdc);
SelectObject(hdcMem, hBitmap);
hdcMem = CreateCompatibleDC(hdc);
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);
EndPaint(hwndDlg, &ps);
DeleteDC(hdcMem);
EndPaint(hwndDlg, &ps);
} break;
break;
}
case WM_DESTROY:
{
@ -606,7 +606,7 @@ SettingsPageProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lPar
Current = Next;
}
DeleteObject(hBitmap);
DeleteObject(hBitmap);
}
}
return FALSE;