format PE GUI 4.0
entry start

include 'win32a.inc'
include 'ssdev_define.txt'

section '.data' data readable writeable
;										
wc					WNDCLASS			; [class]		~ window class
wc.h				dd ?				; [handle]		~ main window
wc.name				db 'SSDEV',0
wc.title			db ' Sleepsleep Developer Framework',0
wmsg				MSG
wdc					dd ?

modh				dd ?				; [handle]		~ module
dbh					dd ?				; [handle]		~ sqlite database

; user defined variable
fonta				dd ?
fontb				dd ?
labela				dd ?
labelb				dd ?
labela.caption		db "caption for label a",0
labelb.caption		db "yo yo from sleepsleep",0
buttona				dd ?
buttonb				dd ?
listboxa			dd ?

buffer				rb 0x1FF
f1					db "%lu",0
f2					db "%s",0

section '.code' code readable executable
;										
include 'ssdev_procedure.txt'
start:
			invoke	InitCommonControls
			invoke	GetModuleHandle,NULL
					mov  [modh],eax
					mov  [wc.hInstance],eax
					mov  [wc.style],0
					mov  [wc.lpfnWndProc],proc_window
					mov  [wc.lpszClassName],wc.name
					mov  [wc.hbrBackground],COLOR_BTNFACE+1
			invoke	LoadIcon,NULL,IDI_APPLICATION
					mov  [wc.hIcon],eax
			invoke	LoadCursor,NULL,IDC_ARROW
					mov  [wc.hCursor],eax
			invoke	RegisterClass,wc
	
			invoke	CreateWindowEx,0,wc.name,wc.title,\
					WS_OVERLAPPEDWINDOW,\
					200,200,640,480,\
					NULL,NULL,[modh],NULL
					mov  [wc.h],eax
			invoke	ShowWindow,eax,SW_SHOW
			invoke	UpdateWindow,[wc.h]

msg_start:
			invoke	GetMessage,wmsg,NULL,0,0
					or   eax,eax
					je   msg_end
			invoke	TranslateMessage,wmsg
			invoke	DispatchMessage,wmsg
					jmp  msg_start
msg_end:

exit:
			invoke	ExitProcess,0

; +-------------+
; | proc_window |
; +-------------+
proc proc_window hwnd,msg,wparam,lparam
					push ebx esi edi
					mov  eax,[msg]
					mmsg eax,\
					WM_CREATE,		.wmcreate,\
					WM_CLOSE,		.wmclose

	.wmdefault:
			invoke	DefWindowProc,[hwnd],[msg],[wparam],[lparam]
					jmp  .wmbye
	.wmcreate:
			stdcall	proc_createfont,8,sfont.bitstream
					mov  [fonta],eax
					push [sfont.handle]
					pop  [fonta]				; store the font handle, if you don't call another proc_createfont,
												; [sfont.handle] would still always store the last created font handle
			stdcall	proc_label,labela.caption,10,10,300,20,[hwnd]
					push [slabel.handle]
					pop  [labela]				; store the label handle
					mov  [labela],eax			; same, get the label handle
			invoke	SendMessage,[slabel.handle],WM_SETFONT,[fonta],TRUE

			stdcall	proc_createfont,8,sfont.tahoma
					mov  [slabel.id],102		; set the label ID
			stdcall	proc_label,labelb.caption,10,30,300,20,[hwnd]
			invoke	SendMessage,[slabel.handle],WM_SETFONT,[sfont.handle],TRUE

			stdcall	proc_createfont,8,sfont.verdana
			stdcall	proc_label,labelb.caption,10,50,300,20,[hwnd]
			invoke	SendMessage,[slabel.handle],WM_SETFONT,[sfont.handle],TRUE
			
			stdcall proc_button,labela.caption,10,80,200,30,[hwnd],300
					mov  [buttona],eax
			invoke	SendMessage,eax,WM_SETFONT,[fonta],TRUE
			stdcall proc_button,labelb.caption,300,80,200,30,[hwnd],301
			
			stdcall	proc_edit,labela.caption,10,110,200,200,[hwnd],400
			invoke	SendMessage,eax,WM_SETFONT,[fonta],TRUE
			
			stdcall proc_listbox,300,110,200,200,[hwnd],401
					mov  [listboxa],eax
			invoke	SendMessage,eax,WM_SETFONT,[fonta],TRUE
			invoke	SendMessage,[listboxa],LB_ADDSTRING,0,labela.caption
			invoke	SendMessage,[listboxa],LB_ADDSTRING,0,labelb.caption
					jmp  .wmbye
	
	.wmclose:
			call	proc_deleteobject			; invoke DeleteObject on all object that store using proc_deleteobject_store
			invoke  PostQuitMessage,0
			
	.wmprocessed:
					mov  eax,1

	.wmbye:
					pop  edi esi ebx
					ret
endp

section '.idata' import data readable
;										
	library	kernel32,		'KERNEL32.DLL',\
			user32,			'USER32.DLL',\
			shell32,		'SHELL32.DLL',\
			ole32,			'OLE32.DLL',\
			comctl32,		'COMCTL32.DLL',\
			gdi32,			'GDI32.DLL'

	include 'apia\Kernel32.inc'
	include 'apia\User32.inc'
	include 'apia\Shell32.inc'
	include 'apia\Ole32.inc'
	include 'apia\Comctl32.inc'
	include 'apia\Gdi32.inc'

section '.rsrc' resource data readable
;										
	directory	RT_VERSION,versions
	
	resource versions,\
	1,LANG_ENGLISH+SUBLANG_DEFAULT,version
	
	versioninfo version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLANG_DEFAULT,0,\
		'FileDescription','Sleepsleep Developer Framework',\
		'LegalCopyright','LICENSE.TXT',\
		'FileVersion','1.0',\
		'ProductVersion','1.0',\
		'OriginalFilename','SSDEV.EXE',\
		'Website','http://www.boinc.ch/~sleepsleep/'