Click to See Complete Forum and Search --> : get DC of HBITMAP


Zolix2010
September 19th, 2005, 08:18 AM
hi,
i want to make a skin (like we all).
i load a bitmap.
got a dc.
but now, when i wanna make bitblt, i need to enter the HDC of the destination (the bitmap as i think).
how do i do it?
and if im wrong - where is my mistake?

Avi.

golanshahar
September 19th, 2005, 08:37 AM
look at this code its doing what you want to:

HWND hwnd = m_hWnd; // handle to the window you want to blit to.
HDC hDC = ::GetDC( hwnd );

HBITMAP bmp = ::LoadBitmap(::GetModuleHandle(0),MAKEINTRESOURCE (IDB_BITMAP1));

HDC dcMem = ::CreateCompatibleDC( hDC );
HBITMAP hOld = (HBITMAP)::SelectObject(dcMem,bmp);

BITMAP bitmap={0};
::GetObject ( bmp,sizeof(BITMAP),&bitmap);
::BitBlt(hDC,0,0,bitmap.bmWidth,bitmap.bmHeight,dcMem,0,0,SRCCOPY);

// clean up
::SelectObject(dcMem,hOld);
::DeleteObject(bmp);
::ReleaseDC(hwnd,dcMem);
::ReleaseDC(hwnd,hDC);



Cheers

Zolix2010
September 19th, 2005, 08:49 AM
once again you saved me! :)
thanks!

Avi.

NoHero
September 19th, 2005, 09:04 AM
Golan's code is leaking memory objects because he is not deleting his loaded bitmap. So DeleteObject() your bitmap if you don't need it anymore.

golanshahar
September 19th, 2005, 09:09 AM
Golan's code is leaking memory objects because he is not deleting his loaded bitmap. So DeleteObject() your bitmap if you don't need it anymore.

why? look agian:

:
::DeleteObject(bmp);
:

;)

Cheers

NoHero
September 19th, 2005, 09:48 AM
Whoops missed that... I'm sorry.

golanshahar
September 19th, 2005, 10:05 AM
Whoops missed that... I'm sorry.
it ok mate :wave:

Cheers