invoke dispatchmessage, addr msg
.endw
mov eax,msg.wparam
ret
winmain endp
wndproc proc hwnd:hwnd, umsg:uint, wparam:wparam, lparam:lparam
local ps:paintstruct
local hdc:hdc
local hmemdc:hdc
local rect:rect
.if umsg==wm_create
invoke loadbitmap,hinstance,idb_main
mov hbitmap,eax
.elseif umsg==wm_paint
invoke beginpaint,hwnd,addr ps
mov hdc,eax
invoke createcompatibledc,hdc
mov hmemdc,eax
invoke selectobject,hmemdc,hbitmap
invoke getclientrect,hwnd,addr rect
invoke bitblt,hdc,0,0,rect.right,rect.bottom,hmemdc,0,0,srccopy
invoke deletedc,hmemdc
invoke endpaint,hwnd,addr ps
.elseif umsg==wm_destroy
invoke deleteobject,hbitmap
invoke postquitmessage,null
.else
invoke defwindowproc,hwnd,umsg,wparam,lparam
ret
.endif
xor eax,eax
ret
wndproc endp
end start
;---------------------------------------------------------------------
; the resource script
;---------------------------------------------------------------------
#define idb_main 1
idb_main bitmap "tweety78.bmp"
analysis:
there is not much to analyze in this tutorial ;)#define idb_main 1define a constant named idb_main, assign 1 as its value. and then use that constant as the bitmap resource identifier. the bitmap file to be included in the resource is "tweety78.bmp" which resides in the same folder as the resource script.
idb_main bitmap "tweety78.bmp"
.if umsg==wm_create
invoke loadbitmap,hinstance,idb_main
mov hbitmap,eax
in response to wm_create, we call loadbitmap to load the bitmap from the resource, passing the bitmap's resource identifier as the second parameter to the api. we get the handle to the bitmap when the function returns.
now that the bitmap is loaded, we can paint it in the client area of our main window.
.elseif umsg==wm_paint
invoke beginpaint,hwnd,addr ps
mov hdc,eax
invoke createcompatibledc,hdc
mov hmemdc,eax
invoke selectobject,hmemdc,hbitmap
invoke getclientrect,hwnd,addr rect
invoke bitblt,hdc,0,0,rect.right,rect.bottom,hmemdc,0,0,srccopy
invoke deletedc,hmemdc
invoke endpaint,hwnd,addr ps
we choose to paint the bitmap in response to wm_paint message. we first call beginpaint to obtain the handle to the device context. then we create a compatible memory dc with createcompatibledc. next select the bitmap into the memory dc with selectobject. determine the dimension of the client area with getclientrect. now we can display the bitmap in the client area by calling bitblt which copies the bitmap from the memory dc to the real dc. when the painting is done, we have no further need for the memory dc so we delete it with deletedc. end painting session with endpaint.
.elseif umsg==wm_destroy
invoke deleteobject,hbitmap