News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Icon from binary data

Started by Vortex, April 16, 2011, 09:17:02 AM

Previous topic - Next topic

Vortex

Here is the icon from binary data example converted to Poasm. The code creating the icon is moved to a separate procedure.


DlgProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

LOCAL hDC:DWORD
LOCAL ps:PAINTSTRUCT

    .IF uMsg==WM_INITDIALOG

        invoke  CreateIconFromMem,hWnd,ADDR pIcon
        mov     hIcon,eax
.
.

DlgProc ENDP


CreateIconFromMem PROC hWnd:DWORD,pBmp:DWORD

LOCAL hDC:DWORD
LOCAL hBmp:DWORD
LOCAL ii:ICONINFO

    invoke  GetDC,hWnd
    test    eax,eax
    jz      @f
    mov     hDC,eax
    mov     edx,pBmp
    lea     ecx,[edx + SIZEOF BITMAPFILEHEADER]  ; start of the BITMAPINFOHEADER header
    mov     eax,BITMAPFILEHEADER.bfOffBits[edx]
    add     edx,eax
    invoke  CreateDIBitmap,hDC,ecx,CBM_INIT,edx,ecx,DIB_RGB_COLORS
    mov     hBmp,eax
    invoke  ReleaseDC,hWnd,hDC

;; Code portion from xandaz
                     
    mov     ii.fIcon,1
    push    hBmp
    pop     ii.hbmMask
    push    hBmp
    pop     ii.hbmColor
    invoke  CreateIconIndirect,ADDR ii
;;

@@:
    ret

CreateIconFromMem ENDP