Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: HDC and windows Bitmaps



Permlink Replies: 3 - Last Post: Oct 26, 2016 2:02 PM Last Post By: Remy Lebeau (Te...
Lex Dean

Posts: 132
Registered: 3/26/07
HDC and windows Bitmaps
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 26, 2016 1:31 AM
Hi All
I want to create a bitmap to StretchBlt to another windows canvas for the screen

FNewBitmap := CreateCompatibleBitmap(FCCanvas.Handle, Width, Height);
FNewDC := CreateCompatibleDC(FCCanvas.Handle);
FaBitmap := SelectObject(FNewDC, FNewBitmap);

I believe creates the new canvas with FNewDC being the new HDC to the canvas. Please correct me.
What is the new BitMap - FNewBitmap or FaBitmap and what is the other bitmap for as its not used.
2nd question is what is the point of SelectObject as it seems to link FNewDC between BitMaps.
And when I destroy this BitMap -

SelectObject(FNewDC, FaBitmap);
DeleteDC(FNewDC);
DeleteObject(FNewBitmap);

I have realized I can set TCanvas.Handle := FNewDC and use TCanvas to draw on the FNewDC's BitMap.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: HDC and windows Bitmaps
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 26, 2016 10:01 AM   in response to: Lex Dean in response to: Lex Dean
Lex wrote:

What is the new BitMap - FNewBitmap or FaBitmap and what is
the other bitmap for as its not used.

FNewBitmap is the new bitmap you created and is active inside the HDC during
drawing operations. FaBitmap is the old bitmap that the HDC originally owned.
You must restore the old bitmap before destroying the HDC, otherwise it
will be leaked.

2nd question is what is the point of SelectObject as it seems to link
FNewDC between BitMaps.

It is not linking the two bitmaps. It is replacing the old bitmap with
the new bitmap. SelectObject() returns the old bitmap so you don't lose it.

--
Remy Lebeau (TeamB)
Lex Dean

Posts: 132
Registered: 3/26/07
Re: HDC and windows Bitmaps
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 26, 2016 1:24 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks.
So SelectObject Selects a HDC to a Bitmap that is interchangeable.
With windows API I just got to think differently, thanks.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: HDC and windows Bitmaps
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 26, 2016 2:02 PM   in response to: Lex Dean in response to: Lex Dean
Lex wrote:

So SelectObject Selects a HDC to a Bitmap that is interchangeable.

It is the other way around. SelectObject() inserts the specified bitmap
into the HDC, replacing the bitmap that is already in it.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02