[CONSOLE.CPL] Use fallback brushes for text preview in case CreateSolidBrush() fails (e.g. low memory scenario).

This commit is contained in:
Hermès Bélusca-Maïto
2022-01-29 02:20:26 +01:00
parent 0e5496d082
commit 13b3425369
2 changed files with 10 additions and 15 deletions

View File

@@ -26,10 +26,8 @@ PaintStaticControls(
ARRAYSIZE(pConInfo->ColorTable) - 1);
hBrush = CreateSolidBrush(pConInfo->ColorTable[index]);
if (!hBrush) return;
FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
DeleteObject(hBrush);
FillRect(drawItem->hDC, &drawItem->rcItem, hBrush ? hBrush : GetStockObject(BLACK_BRUSH));
if (hBrush) DeleteObject(hBrush);
if (ActiveStaticControl == index)
DrawFocusRect(drawItem->hDC, &drawItem->rcItem);

View File

@@ -390,8 +390,8 @@ WinPrev_OnDraw(
/* Draw the console background */
hBrush = CreateSolidBrush(pConInfo->ColorTable[BkgdAttribFromAttrib(pConInfo->ScreenAttributes)]);
FillRect(hDC, &rcWin, hBrush);
DeleteObject(hBrush);
FillRect(hDC, &rcWin, hBrush ? hBrush : GetStockObject(BLACK_BRUSH));
if (hBrush) DeleteObject(hBrush);
}
static LRESULT CALLBACK
@@ -489,20 +489,18 @@ PaintText(
nbkColor = pConInfo->ColorTable[BkgdAttribFromAttrib(CurrentAttrib)];
ntColor = pConInfo->ColorTable[TextAttribFromAttrib(CurrentAttrib)];
/* Draw the console background */
hBrush = CreateSolidBrush(nbkColor);
if (!hBrush) return;
FillRect(drawItem->hDC, &drawItem->rcItem, hBrush ? hBrush : GetStockObject(BLACK_BRUSH));
if (hBrush) DeleteObject(hBrush);
/* Refresh the font preview, getting a new font if necessary */
if (FontPreview.hFont == NULL)
RefreshFontPreview(&FontPreview, pConInfo);
/* Draw the preview text using the current font */
hOldFont = SelectObject(drawItem->hDC, FontPreview.hFont);
//if (hOldFont == NULL)
//{
// DeleteObject(hBrush);
// return;
//}
FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
// if (!hOldFont) return;
/* Add a few space between the preview window border and the text sample */
InflateRect(&drawItem->rcItem, -2, -2);
@@ -514,7 +512,6 @@ PaintText(
SetBkColor(drawItem->hDC, pbkColor);
SelectObject(drawItem->hDC, hOldFont);
DeleteObject(hBrush);
}