CreateBmpFromMem updated

Started by Vortex, September 27, 2006, 06:45:07 PM

Previous topic - Next topic

Vortex

Here is the new version of the function CreateBmpFromMem

- returns NULL if GetDC fails
- some minor modifications to improve the readability of the source code


; CreateBmpFromMem V1.1 by Vortex
; Retrieves the handle of a bitmap stored in memory

.386
.model flat,stdcall
option casemap:none

include             \GeneSys\include\windows.inc

GetDC               PROTO :DWORD
CreateDIBitmap      PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
ReleaseDC           PROTO :DWORD,:DWORD

.code
CreateBmpFromMem PROC hWnd:DWORD,pBmp:DWORD,hDCnew

invoke     GetDC,hWnd
test       eax,eax
jz         @f
  push       eax
mov        edx,hDCnew
mov        DWORD PTR [edx],eax
mov        edx,pBmp
lea        ecx,[edx+sizeof(BITMAPFILEHEADER)]   ; start of the BITMAPINFOHEADER header
mov        eax,BITMAPFILEHEADER.bfOffBits[edx]
add        edx,eax                              ; edx points the array of bytes containing the bitmap data
pop        eax
invoke     CreateDIBitmap,eax,ecx,CBM_INIT,edx,ecx,DIB_RGB_COLORS
@@:
ret

CreateBmpFromMem ENDP
END