

.data
AppName				db		"Smilies",0
ClassName			db		"Smilies",0



.data?


hBackDC		dd		?
hBackBmp	dd		?
hStepDC		dd		?
hStepBmp	dd		?

hInstance	dd		?

.data

.code
	start:
	; Get module handle and save it
	invoke 	GetModuleHandle, NULL
	mov 	hInstance, eax
	invoke	InitRand32
	
	
	; Run winmain procedure and exit program
	invoke 	WinMain, hInstance, NULL, NULL, SW_SHOWNORMAL
	invoke 	ExitProcess,eax

;===============================================================================
; WinMain
;===============================================================================
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
	mov   	wc.cbSize,SIZEOF WNDCLASSEX
	mov   	wc.style, CS_HREDRAW or CS_VREDRAW
	mov   	wc.lpfnWndProc, OFFSET WndProc
	mov   	wc.cbClsExtra,NULL
	mov   	wc.cbWndExtra,NULL
	push  	hInstance
	pop   	wc.hInstance
	mov   	wc.hbrBackground,COLOR_WINDOW
	mov   	wc.lpszMenuName, NULL
	mov   	wc.lpszClassName,OFFSET ClassName
	invoke 	LoadIcon, hInstance, 100
	mov   	wc.hIcon, eax
	invoke 	LoadIcon, hInstance, 101
	mov   	wc.hIconSm, eax
	invoke 	LoadCursor,NULL,IDC_ARROW
	mov   	wc.hCursor,eax
	invoke 	RegisterClassEx, addr wc
	INVOKE 	CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           	WS_OVERLAPPEDWINDOW-WS_MAXIMIZEBOX-WS_SIZEBOX,\
           	CW_USEDEFAULT, CW_USEDEFAULT,400,300,NULL,0,\
           	hInst,NULL
	mov   	hwnd,eax
	invoke 	ShowWindow, hwnd, CmdShow
	invoke 	UpdateWindow, hwnd
	.WHILE 	TRUE
		invoke 	GetMessage, ADDR msg,NULL,0,0
		.BREAK 	.IF (!eax)
		invoke 	TranslateMessage, ADDR msg
		invoke 	DispatchMessage, ADDR msg
	.ENDW
	mov     eax,msg.wParam
	ret
WinMain endp

.code
;===============================================================================
;	Window procedure
;===============================================================================	
WndProc proc	uses ebx esi hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
LOCAL	hDC:DWORD
LOCAL	ps:PAINTSTRUCT
LOCAL	temp:DWORD
LOCAL	TempRect:RECT
mov eax, uMsg
	.IF 	eax==WM_CREATE
		invoke	GetDC, hWnd
		mov		hDC, eax
		invoke	CreateCompatibleDC, hDC
		mov		hBackDC, eax
		invoke	CreateCompatibleBitmap, hDC, 400, 300
		mov		hBackBmp, eax
		invoke	SelectObject, hBackDC, hBackBmp
		
		invoke	CreateCompatibleDC, hDC
		mov		hStepDC, eax
		invoke	CreateCompatibleBitmap, hDC, 400, 300
		mov		hStepBmp, eax
		invoke	SelectObject, hStepDC, hStepBmp
		
		invoke	Initialization, hWnd
		
		invoke	SetTimer, hWnd, 555, 70, NULL
		invoke	ReleaseDC, hWnd, hDC
	.ELSEIF eax==WM_TIMER
		.IF		wParam==555
			invoke	InvalidateRect, hWnd, NULL, FALSE		
		.ENDIF
	.ELSEIF eax==WM_PAINT
		invoke	DrawProc
		invoke	BeginPaint, hWnd, ADDR ps
		mov		hDC,eax
		invoke	BitBlt, hDC, 0,0, 400, 300, hBackDC, 0, 0, SRCCOPY
		invoke	EndPaint, hWnd, ADDR ps
	.ELSEIF	eax==WM_DESTROY
		invoke	KillTimer, hWnd, 555
		invoke	DeleteDC, hBackDC
		invoke	DeleteObject, hBackBmp
		invoke	DeleteDC, hStepDC
		invoke	DeleteObject, hStepBmp
		
		invoke	Cleanup
		
		
		invoke	PostQuitMessage, NULL
	.ELSE
		invoke 	DefWindowProc,hWnd,uMsg,wParam,lParam		
		ret
	.ENDIF
ret
WndProc endp

