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