format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.data' data readable writeable

  _title db 'Win32 program template',0
  _class db 'FASMWIN32',0
  _class_cb db 'COMBOBOX',0

  mainhwnd dd ?
  hinstance dd ?

  hwnd_cb dd ?

  msg MSG
  wc WNDCLASS

section '.code' code readable executable

  start:
	invoke	GetModuleHandle,0
	mov	[hinstance],eax
	invoke	LoadIcon,0,IDI_APPLICATION
	mov	[wc.hIcon],eax
	invoke	LoadCursor,0,IDC_ARROW
	mov	[wc.hCursor],eax
	mov	[wc.style],0
	mov	[wc.lpfnWndProc],WindowProc
	mov	[wc.cbClsExtra],0
	mov	[wc.cbWndExtra],0
	mov	eax,[hinstance]
	mov	[wc.hInstance],eax
	mov	[wc.hbrBackground],COLOR_BTNFACE+1
	mov	[wc.lpszMenuName],0
	mov	[wc.lpszClassName],_class
	invoke	RegisterClass,wc
	invoke	CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,128,192,192,NULL,NULL,[hinstance],NULL
	mov	[mainhwnd],eax
  msg_loop:
	invoke	GetMessage,msg,NULL,0,0
	or	eax,eax
	jz	end_loop
	invoke	TranslateMessage,msg
	invoke	DispatchMessage,msg
	jmp	msg_loop
  end_loop:
	invoke	ExitProcess,[msg.wParam]

proc WindowProc, hwnd,wmsg,wparam,lparam
	push	ebx esi edi
	cmp	[wmsg],WM_CREATE
	je	wmcreate
	cmp	[wmsg],WM_DESTROY
	je	wmdestroy
  defwndproc:
	invoke	DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
	jmp	finish
  wmcreate:
	;invoke  CreateWindowEx,0,_class_cb,0,WS_CHILD+WS_VISIBLE+CBS_DROPDOWNLIST,16,40,130,125,[hwnd],0,[hinstance],0
	;mov     [hwnd_cb],eax
	stdcall create_control,hwnd_cb,_class_cb,0,WS_CHILD+WS_VISIBLE+CBS_DROPDOWNLIST,[hwnd],16,40,130,100,1005
	;invoke  SendMessage,[hwnd_cb],CB_SETITEMDATA,0,_title
	invoke	SendMessage,[hwnd_cb],CB_ADDSTRING,0,_class
	invoke	SendMessage,[hwnd_cb],CB_ADDSTRING,0,_class
	xor	eax,eax
	jmp	finish
  wmdestroy:
	invoke	PostQuitMessage,0
	xor	eax,eax
  finish:
	pop	edi esi ebx
	return
endp

proc create_control,handle,_class_name,_caption,style,parent,x,y,w,h,control_id
	push	ebx esi edi
	invoke	CreateWindowEx,0,[_class_name],[_caption],[style],[x],[y],[w],[h],[parent],0,[hinstance],[control_id]
	mov	ecx,[handle]
	mov	[ecx],eax
	;invoke  SendMessage,eax,WM_SETFONT,[hFont],0
	pop	edi esi ebx
	return
endp

section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
	  user32,'USER32.DLL'

  include '%fasminc%\apia\kernel32.inc'
  include '%fasminc%\apia\user32.inc'
