NO

Author Topic: Creating icon from binary data  (Read 4285 times)

Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Creating icon from binary data
« on: March 18, 2011, 08:17:46 PM »
Here is an example of creating and displaying an icon from binary data. Poasm's powerful INCBIN statement is used to embed the icon file.

Code: [Select]
DlgProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

LOCAL ii:ICONINFO
LOCAL hDC:DWORD
LOCAL ps:PAINTSTRUCT

    .IF uMsg==WM_INITDIALOG

        invoke  CreateBmpFromMem,hWnd,ADDR pIcon
        mov     hBitmap,eax

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

    .ELSEIF uMsg==WM_PAINT
       
        invoke  BeginPaint,hWnd,ADDR ps
        mov     hDC,eax
        invoke  DrawIcon,hDC,180,90,hIcon
        invoke  EndPaint,hWnd, ADDR ps
Code it... That's all...

Offline Vortex

  • Member
  • *
  • Posts: 867
    • http://www.vortex.masmcode.com
Re: Creating icon from binary data
« Reply #1 on: April 16, 2011, 07:54:56 PM »
The code creating the icon is moved to a separate procedure :

Code: [Select]
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
Code it... That's all...