From 23259ce5c9364e344547435dbeb5ddf239d3f1de Mon Sep 17 00:00:00 2001 From: Stephane Lussier Date: Tue, 11 Jul 2000 22:04:44 +0000 Subject: [PATCH] In CreateDIBSection function, if hdc is NULL it now uses the desktop DC instead of failing. --- objects/dib.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/objects/dib.c b/objects/dib.c index 4a01138d05a..ff655214ed1 100644 --- a/objects/dib.c +++ b/objects/dib.c @@ -866,7 +866,17 @@ HBITMAP16 WINAPI CreateDIBSection16 (HDC16 hdc, BITMAPINFO *bmi, UINT16 usage, DWORD offset) { HBITMAP16 hbitmap; - DC *dc = (DC *) GDI_GetObjPtr(hdc, DC_MAGIC); + DC *dc; + BOOL bDesktopDC = FALSE; + + /* If the reference hdc is null, take the desktop dc */ + if (hdc == 0) + { + hdc = CreateCompatibleDC(0); + bDesktopDC = TRUE; + } + + dc = (DC *) GDI_GetObjPtr(hdc, DC_MAGIC); if(!dc) dc = (DC *) GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC); if(!dc) return (HBITMAP16) NULL; @@ -874,6 +884,9 @@ HBITMAP16 WINAPI CreateDIBSection16 (HDC16 hdc, BITMAPINFO *bmi, UINT16 usage, GDI_HEAP_UNLOCK(hdc); + if (bDesktopDC) + DeleteDC(hdc); + return hbitmap; } @@ -885,7 +898,17 @@ HBITMAP DIB_CreateDIBSection(HDC hdc, BITMAPINFO *bmi, UINT usage, DWORD offset, DWORD ovr_pitch) { HBITMAP hbitmap; - DC *dc = (DC *) GDI_GetObjPtr(hdc, DC_MAGIC); + DC *dc; + BOOL bDesktopDC = FALSE; + + /* If the reference hdc is null, take the desktop dc */ + if (hdc == 0) + { + hdc = CreateCompatibleDC(0); + bDesktopDC = TRUE; + } + + dc = (DC *) GDI_GetObjPtr(hdc, DC_MAGIC); if(!dc) dc = (DC *) GDI_GetObjPtr(hdc, METAFILE_DC_MAGIC); if(!dc) return (HBITMAP) NULL; @@ -893,6 +916,9 @@ HBITMAP DIB_CreateDIBSection(HDC hdc, BITMAPINFO *bmi, UINT usage, GDI_HEAP_UNLOCK(hdc); + if (bDesktopDC) + DeleteDC(hdc); + return hbitmap; }