;============================================================================	
;FileName       :TEMPLATE.ASM
;Function       :Template for program using standard Win32 headers
;               :
;Complier       :FASM   TEMPLATE.ASM     TEMPLATE.EXE
;Author         :Kenneth Zheng (Zheng Hongwen) 
;Date           :January 28th,2004 15:00:00 AM
;Nationality	:China
;Notice		:None
;============================================================================
FORMAT          PE GUI 4.0 on 'stub.exe'
ENTRY		Start
;============================================================================
_TITLE          EQU  "Win32 program template"
_NAME           EQU  "template"
_VERSION	EQU  "1.00"
_VERSIONTEXT	EQU  _VERSION
;============================================================================
include         'private\win32a.inc'
;============================================================================
section	'.text' code readable executable
;----------------------------------------------------------------------------
;
;	_ProcWinMain - Win32 Message Dispatch Handler
;
;	Entry:
;		hWnd - Windows Handle
;		uMsg - Message Index
;		wparam - Parameter of Message
;		lParam - Paraemter of Message
;	Exit:
;		EAX - Message Dispatch Result
;	Modified:
;		EAX, ECX, EDX
;	Processing:
;		Win32 Message Dispatch Handler 
;
;----------------------------------------------------------------------------
proc 	_ProcWinMain uses ebx esi edi,hWnd,uMsg,wParam,lParam
        local   stPs    :PAINTSTRUCT,       ,\
                stRect  :RECT               ,\
                hDC     :DWORD

	mov	eax,[uMsg]
;****************************************************************************	
	cmp	eax,WM_PAINT
	je	.wmPaint
	cmp	eax,WM_CLOSE
	je	.wmClose
  .defwndproc:
	stdcall	DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
	jmp	.finish
	
;****************************************************************************  	
  .wmPaint:
  	lea	eax,[stPs]
  	stdcall	BeginPaint,[hWnd],eax
  	mov	[hDC],eax
  	
  	;When specifying an explicit RGB color, the COLORREF value 
  	;has the following hexadecimal form: 0x00bbggrr 
	stdcall	SetTextColor,[hDC],(200 SHL 16)+(68 SHL 8)+210
	stdcall	SetBkColor,[hDC],(255 SHL 16)+(174 SHL 8)+6
	stdcall	SetBkMode,[hDC],TRANSPARENT
	
  	lea	ebx,[stRect]
  	stdcall	GetClientRect,[hWnd],ebx
  	mov	eax,[stRect.bottom]
  	shr	eax,1
        sub     eax,20          ; one line height
  	mov	[stRect.top],eax
  	  	  	
  	stdcall	DrawText,[hDC],szText,-1, \
  		ebx,\
  		DT_CENTER
  	
  	lea	eax,[stPs]
  	stdcall	EndPaint,[hWnd],eax
  	jmp	.processed
;****************************************************************************	
  .wmClose:
  	stdcall	DestroyWindow,[hWnd]
  	stdcall	PostQuitMessage,NULL
;**************************************************************************** 
  .processed:
  	xor	eax,eax  
  .finish:	
	ret	
endp	
;----------------------------------------------------------------------------
;
;	_WinMain - Win32 Main Procedure
;
;	Entry:
;		NONE
;	Exit:
;		EAX - Result
;	Modified:
;		EAX, ECX, EBX, EDX , ESI , EDI
;	Processing:
;		Win32 Main Procedure
;
;----------------------------------------------------------------------------
proc	_WinMain 
        local   stWndClass      :WNDCLASSEX     ,\
                stMsg           :MSG

	stdcall	GetModuleHandle,NULL
	mov	[hInstance],eax
	
;****************************************************************************
;       Register Windows Class 
;****************************************************************************
	lea	eax,[stWndClass]
	stdcall	RtlZeroMemory,eax,sizeof.WNDCLASSEX
	stdcall	LoadCursor,NULL,IDC_ARROW
	mov	[stWndClass.hCursor],eax
	
	stdcall	LoadIcon,[hInstance],IDI_MAIN
	mov	[stWndClass.hIcon],eax
	mov	[stWndClass.hIconSm],eax
	push	[hInstance]
	pop	[stWndClass.hInstance]
	mov	[stWndClass.cbSize],sizeof.WNDCLASSEX
	mov	[stWndClass.style],CS_HREDRAW OR CS_VREDRAW
	mov	[stWndClass.lpfnWndProc],_ProcWinMain
	mov	[stWndClass.hbrBackground],COLOR_WINDOW+1
	mov	[stWndClass.lpszClassName],szClassName
	lea	eax,[stWndClass]
	stdcall	RegisterClassEx,eax
;****************************************************************************
;       Create and then show Window 
;****************************************************************************
	stdcall	CreateWindowEx,WS_EX_CLIENTEDGE,\
		szClassName,szCaptionMain,\
		WS_OVERLAPPEDWINDOW,\
		CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,\
		NULL,NULL,[hInstance],NULL
	mov	[hWinMain],eax
	stdcall	ShowWindow,[hWinMain],SW_SHOWNORMAL
	stdcall	UpdateWindow,[hWinMain]	
;****************************************************************************
;       Win32 Message Loop 
;****************************************************************************	
        lea     ebx,[stMsg]
  .msg_loop:
        stdcall GetMessage,ebx,NULL,0,0
        or      eax,eax
  	jz	.end_loop
        stdcall TranslateMessage,ebx
        stdcall DispatchMessage,ebx
  	jmp	.msg_loop
  .end_loop:
	ret
endp		
;----------------------------------------------------------------------------
Start:
        stdcall _WinMain
	stdcall	ExitProcess,NULL
;============================================================================
section	'.data'	data readable writeable
hInstance	DD	?
hWinMain	DD	?

szClassName	DB	'FASMWIN32',0
szCaptionMain	DB	_TITLE,0
szText          DB      "Win32 Assembly, Simple and Powerful!",0Dh,0Ah
		DB	"Author:Kenneth Zheng Date:January 27th, 2004",0
;============================================================================
section	'.idata' import	data readable writeable
	library kernel32,"kernel32.dll",\
		user32  ,"user32.dll",\
                gdi32   ,"gdi32.dll"
                include "apia\kernel32.inc"
                include "apia\user32.inc"
                include "apia\gdi32.inc"
               
;============================================================================
section	'.rsrc' resource data readable
	; identifiers
	IDM_MAIN	=	100
	IDI_MAIN	=	100
	IDC_MAIN	=	100
	IDA_MAIN	=	100
	_ 		EQU	,09h,
	; resources
	directory RT_GROUP_ICON,group_icons,\
		  RT_ICON,icons,\
		  RT_VERSION,versions
				  	
	resource group_icons,\
		 IDI_MAIN,LANG_NEUTRAL,main_icon
		 
	resource icons,\
		 1,LANG_NEUTRAL,main_icon_data
	
	resource versions,\
		 1,LANG_NEUTRAL+SUBLANG_NEUTRAL,version_info	
	
	; icons
        icon    main_icon,main_icon_data,"res\east32.ico"
        	 
	; version
	version version_info,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_NEUTRAL+SUBLANG_NEUTRAL,0,\
		"CompanyName","Wistron Infocomm (Shanghai) Corp.",\
		"FileDescription",_TITLE,\
		"FileVersion",_VERSION,\
		"InternalName",_NAME,\
		"LegalCopyright",<"Copyright ",0A9h," Kenneth Zheng">,\
		"OriginalFilename",<_NAME,".exe">,\
		"ProductName",_TITLE,\
		"ProductVersion",_VERSION
;============================================================================
