Jump to content

Cleaning up ( SelectObject )


Go to solution Solved by trancexx,

Recommended Posts

Posted

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.

  • Solution
Posted (edited)

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

♡♡♡

.

eMyvnE

Posted (edited)

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

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...