Jump to content
Sign in to follow this  
JohnOne

Cleaning up ( SelectObject )

Recommended Posts

JohnOne

Something I'm not certain about with regards this function, if anyone can help.

msdn says

The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type.

So does that mean I only need to clean up the original object?

Example:

HDC hdc = GetDC(NULL);
HDC hdcMEM = CreateCompatibleDC(hdc);
HBITMAP hBitmap = CreateCompatibleBitmap(hdc, iWidth, iHeight);
SelectObject(hdcMEM,hBitmap);

DeleteObject(hBitmap);
DeleteDC(hdcMEM);

Is that sufficient to clean that up, or do I need to assign are variable to SelectObject and clean that up too, or just the new object?

HDC hdc = GetDC(NULL);
HDC hdcMEM = CreateCompatibleDC(hdc);
HBITMAP hBitmap = CreateCompatibleBitmap(hdc, iWidth, iHeight);
HANDLE hObj = SelectObject(hdcMEM,hBitmap);

DeleteObject(hObj);
DeleteDC(hdcMEM);

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
trancexx

Usually if you don't have the use for replaced you do this:

::DeleteObject(::SelectObject(hdcMEM,hBitmap));

... And you should call ReleaseDC for hdc.

Edited by trancexx
  • Like 1

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
UEZ

Something like that maybe in AutoIt notation:

$hDC = _WinAPI_GetDC(0)
$hdcMEM = _WinAPI_CreateCompatibleDC($hDC)
$hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
_WinAPI_SelectObject ($hdcMEM, $hBitmap)


_WinAPI_DeleteObject($hDC)
_WinAPI_ReleaseDC(0, $hDC)
_WinAPI_DeleteDC($hdcMEM)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hDC)

Br,

UEZ

Edited by UEZ
  • Like 1

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
UEZ

I think thorough but you can create a loop with 1000 calls and leave some off to see whether memory consumption is increasing constantly to check for memory leaks.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
trancexx

You must not call DeleteDC for hdc.

Edited by trancexx
  • Like 1

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
forever0donotknowme

UEZ & JohnOne had beautiful picture in profile

Share this post


Link to post
Share on other sites
UEZ

I'm really a big fan of them - one of the best comedians ever!

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×