Assembly code snippets

Back to the snippets overview

Details

TitleCreating DC's to paint on
AuthorJimmyClif
Submitted by:JimmyClif
Date added:2002-02-17 18:11:42
Date modified:2002-02-17 18:18:39

Comments

This little function is used to create DC for BackBuffers, Images and so on.
All there is to do is pass 2 dwords which will hold the DC (the one you'll be painting on)
and the handleDC which both need to be deleted at program exit (with DeleteDC and DeleteObject)

Snippet

;========================================================================
;                           GetCompatibleBitmap
;========================================================================
;  Usage:
;  invoke GetCompatibleDC, ADDR ImageDC, ADDR hImageDC, hwnd, 500, 300
;========================================================================
GetCompatibleBitmap proc AnotherDC:DWORD, HandleOfDC:DWORD, hwnd:DWORD, xLenght:DWORD, yWidth:DWORD
    invoke CreateCompatibleDC,NULL
    mov edx,AnotherDC
    push eax
    mov [edx],eax
    invoke GetDC,hwnd
    push eax
    invoke CreateCompatibleBitmap,eax,xLenght,yWidth
    mov edx,HandleOfDC
    mov ecx,[esp]       ;pop ecx
    mov [esp],eax       ;push eax
    mov [edx],eax
    invoke ReleaseDC,hwnd,ecx
    pop eax             ;HandleOfDC
    pop ecx             ;AnotherDC
    invoke SelectObject,ecx,eax
    ret
GetCompatibleBitmap endp