🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #334

Re: Draw Transparent Bitmap

#334
From: Bob Gonder
Date: Thu, 01 May 2008 16:47
57 lines
2216 bytes
Renald Yazmir wrote:

>This function causing a software crash when I resize a window or move a 
>dialog box over the picture.
>LoadBitmap returns NULL.
>
>What is wrong with this function?

Not sure, could be a problem with the caller,
but will highlight some points...

>void draw_transparent_picture(
>     HWND hwnd,
>     int pictid,
>     RECT *rct,
>     COLORREF transparent_color
>     )
>{
> BITMAP bitmap;
> COLORREF crOldBack   = 0;

0 is never used.

> HDC dcImage     = NULL;
> HDC dcTrans     = NULL;
> HBITMAP pOldBitmapImage  = NULL;
> HBITMAP bitmapTrans   = NULL;
> HBITMAP pOldBitmapTrans  = NULL;
> HBITMAP hBitmap    = NULL;
> HDC hDC      = NULL;
> HDC hMemDC     = NULL;

All those NULLs are never used.

> hDC = GetDC(hwnd);
>
> if ((hMemDC = CreateCompatibleDC(hDC)) == (HDC) NULL)
>  return;

You didn't release the hDC.

> hBitmap = LoadBitmap(res_lib, MAKEINTRESOURCE(pictid));// load from 
>resource dll
>
> if (hBitmap == NULL)
>  return;

You didn't delete the hMemDC
You didn't release the hDC.

> crOldBack = SetBkColor(hDC, RGB(255, 255, 255));
>
> // Create two memory dcs for the image and the mask
> dcImage=CreateCompatibleDC(hDC);
> dcTrans=CreateCompatibleDC(hDC);

You don't check those HDCs.
Technical Details
Message-ID: <34sj149loee74tvthetr5gfcfk4tjmv9pu@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!eweka.nl!lightspeed.eweka.nl!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mail
References: <4819ce0a$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,c8bc454d19975d6f
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Draw Transparent Bitmap 
Date: Thu, 01 May 2008 09:47:43 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <34sj149loee74tvthetr5gfcfk4tjmv9pu@4ax.com>
References: <4819ce0a$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.77.144.65
X-Trace: newsgroups.borland.com 1209660462 67.77.144.65 (1 May 2008 09:47:42 -0700)
Lines: 59
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!eweka.nl!lightspeed.eweka.nl!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mail