
; Template for program using standard Win32 headers

format PE GUI 4.0
entry start

include '%fasminc%\win32ax.inc'

section '.text' code readable executable

  start:

	invoke	GetModuleHandle,0
	mov	[wc.hInstance],eax
	invoke	LoadIcon,0,IDI_APPLICATION
	mov	[wc.hIcon],eax
	invoke	LoadCursor,0,IDC_ARROW
	mov	[wc.hCursor],eax
	invoke	RegisterClass,wc
	test	eax,eax
	jz	error

	invoke	GetSystemMetrics, SM_CXSCREEN	; SM_CXSCREEN = 0
	sub	eax,256
	shr	eax,1

	mov	[wX],eax
	invoke	GetSystemMetrics, SM_CYSCREEN	; SM_CYSCREEN = 1
	sub	eax,192
	shr	eax,1

	mov	[wY],eax
	invoke	CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,\
										[wX],[wY],256,192,NULL,NULL,[wc.hInstance],NULL
	test	eax,eax
	jz	error

  msg_loop:
	invoke	GetMessage,msg,NULL,0,0
	cmp	eax,1
	jb	end_loop
	jne	msg_loop
	invoke	TranslateMessage,msg
	invoke	DispatchMessage,msg
	jmp	msg_loop

  error:
	invoke	MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK

  end_loop:
	invoke	ExitProcess,[msg.wParam]

proc WindowProc uses ebx esi edi, hwnd,wmsg,wparam,lparam
	cmp	[wmsg],WM_CREATE
	je	.wmcreate
	cmp	[wmsg],WM_COMMAND
	je	.wmcommand
	cmp	[wmsg],WM_DESTROY
	je	.wmdestroy
		.defwndproc:
	invoke	DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
	jmp	.finish
		.wmcreate:
	invoke	CreateWindowEx,0,'STATIC','ID_ST_TEST',WS_VISIBLE+WS_CHILD+SS_SUNKEN+SS_NOTIFY,\
										20,20,100,100,[hwnd],ID_ST_TEST,[wc.hInstance],NULL
	mov	[hwndstatic1],eax
	invoke	CreateWindowEx,0,'BUTTON',' EXIT',WS_VISIBLE+WS_CHILD,\
										185,125,55,25,[hwnd],ID_BT_EXIT,[wc.hInstance],NULL
    invoke	CreateWindowEx,0,'BUTTON',' COLOR',WS_VISIBLE+WS_CHILD,\
										130,55,65,25,[hwnd],ID_BT_COLOR,[wc.hInstance],NULL
	mov	[hwndbtn1],eax
	xor	eax,eax
	jmp	.finish
		.wmcommand:
	cmp	[wparam],BN_CLICKED shl 16 + ID_BT_EXIT
	jne @F
	jmp .wmdestroy
	@@:
	cmp	[wparam],BN_CLICKED shl 16 + ID_BT_COLOR
	jne @F
; xxxxxxxxxxxxxxxxxxxxxxxxxxxx  code  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	invoke MessageBox ,0,'???',"Code for changing 'ID_ST_TEST' color needed !",0
	;    Code ???

; xxxxxxxxxxxxxxxxxxxxxxxxxxxx  code  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
	xor	eax,eax
	jmp	.finish
	@@:

	xor	eax,eax
	jmp	.finish
		.wmdestroy:
	invoke	PostQuitMessage,0
	xor	eax,eax
		.finish:
	ret
endp

section '.data' data readable writeable

	_class db 'FASMWIN32',0
	_title  db 'Win32 TMPL',0
	_error db 'Startup failed.',0

	wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,COLOR_BTNFACE+1,NULL,_class

	msg MSG

	hwndstatic1 dd ?
	hwndbtn1 dd ?
	wX dd ?
	wY dd ?

section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
	user32,'USER32.DLL'

  include 'api\kernel32.inc'
  include 'api\user32.inc'

ID_BT_EXIT = 1000
ID_ST_TEST = 1001
ID_BT_COLOR = 1002
