🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Some HDC questions

#37
From: Remy Lebeau (TeamB)
Date: Tue, 05 Aug 2008 17:46
67 lines
2790 bytes
"UO" <uo@uott> wrote in message news:489877b5$1@newsgroups.borland.com...

> Here, does the word "CreateDC" include "CreateCompatibleDC?"

CreateDC() and CreateCompatibleDC() are unique and unrelated functions.  But 
in this particular context, you are being warned the same thing.  Do not 
hold on to any HDC that you do not explicitally create yourself.

> What about GetDC/GetWindowDC?

Do not hold on to those HDCs between messages.

> Until I started reading Petzold's book I had used SelectObject() as:

That is the correct way to use it.  Always re-select any previous GDI 
resources you replace when you are done using them.

> case WM_PAINT:
>    hdc = GetDC(hwnd);

You should be looking at the wParam value.  If not 0, it contains an HDC 
that you need to draw to instead.

>    SelectObject(hdc, hBrushOld); //1

> When do I have to save / restore old attributes, here the hBrushOld?

When you are done using them before exiting.

> Is the line marked with //1 necessary?

Yes.

> Another book gives the following code for BitBlt function as an example:
<snip>
> Is the line marked with //2 necessary?

Yes, for the same reason.

> This book restores all GDI objects, not just bitmaps.

That is the correct thing to do.  If you replace any GDI object with your 
own, restore the old one when you are done.

> Another material, a tutorial actually, gives the following code:
<snip>
> The default bitmap is restored again.

As it should be.

> So, when is it necessary to restore default attributes?

Always.

> Assume the following code:
<snip>
> Is it ok to delete hdcMem while hBitmap is selected into hdcMem

No.

> or should I use the following code?

Yes.


Gambit 
Technical Details
Message-ID: <489892df$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <489877b5$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,fa1b3304c969ec75
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <489877b5$1@newsgroups.borland.com>
Subject: Re: Some HDC questions
Date: Tue, 5 Aug 2008 10:46:43 -0700
Lines: 69
Organization: Lebeau Software
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
NNTP-Posting-Host: 207.178.157.90
Message-ID: <489892df$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1217958623 207.178.157.90 (5 Aug 2008 10:50:23 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail