Assembly code snippets

Back to the snippets overview

Details

TitleGetting the DC from a Bitmap
AuthorJimmyClif
Submitted by:JimmyClif
Date added:2002-02-17 18:17:27
Date modified:2002-02-17 18:17:27

Comments

This is used to create DC's for Bitmaps. Just pass :
BitmapDC an empty dword - which will receive the DC you'll be working with later on.
NameOfBitmap - the name of the Bitmap to take into the DC.
HandleOfBitmap - an empty dword which will receive the handle of the Bitmap.
Do not forget to DeleteDC and DeleteObject for the created Handle and DC at program exit.

Snippet

;========================================================================
;                           GetBitmapDC
;========================================================================
;  Usage:
;  invoke GetBitmapDC, ADDR BitmapDC, ADDR NameOfBitmap, ADDR hBitmap, hwnd
;========================================================================
GetBitmapDC proc AnotherDC:DWORD, BitmapADDR:DWORD,HandleOfBitmap:DWORD, hwnd:DWORD
    invoke GetDC,hwnd
    push eax            ;1 push DC for release later
    invoke CreateCompatibleDC,eax
    mov edx,AnotherDC
    push eax            ;2 push DC for SelectObject
    mov [edx],eax
    invoke LoadBitmap,hInstance,BitmapADDR
    mov edx,HandleOfBitmap
    pop ecx             ;2 pop Created DC
    mov [edx],eax
    invoke SelectObject,ecx,eax
    pop eax             ;1 pop DC to release
    invoke ReleaseDC,hwnd,eax
ret
GetBitmapDC endp