'Version: 0.1

'global vars
dim shared global_hdc as HDC



'#undef's
#undef line
#undef pset
#undef rgb
#define rgb(a,b,c) bgr(a,b,c)



'drawing functions
declare sub line (byval x1 as integer, byval y1 as integer, byval x2 as integer, byval y2 as integer, byval c as dword = bgr(0,0,0), byval b as integer = 1, byval style as integer = PS_SOLID)  

sub line (byval x1 as integer, byval y1 as integer, byval x2 as integer, byval y2 as integer, byval c as dword = bgr(0,0,0), byval b as integer = 1, byval style as integer = PS_SOLID)
  dim as HPEN pen = GetCurrentObject(global_hdc,OBJ_PEN)
  dim as HPEN pen2 = CreatePen(style,b,c)
  SelectObject(global_hdc,pen2)
  MoveToEx(global_hdc,x1,y1,0)
  LineTo(global_hdc,x2,y2)
  SelectObject(global_hdc,pen)
  DeleteObject(pen2)
end sub



sub pset (byval x1 as integer, byval y1 as integer, byval c as dword)
  SetPixel(global_hdc,x1,y1,c)
end sub



type Window
  hwnd as HWND
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval titel as string)
  declare constructor()
  declare property titel(byval new_titel as string)
  declare property x(byval new_x as integer)
  declare property y(byval new_y as integer)
  declare property h(byval new_h as integer)
  declare property w(byval new_w as integer)
  declare property x() as integer
  declare property y() as integer
  declare property h() as integer
  declare property w() as integer
  declare sub toTop()
  declare property enable(byval new_enable as bool)
  declare sub hide()
  declare sub restore()
  declare sub minimize()
  declare sub maximize()
  declare property OnPaint(byval new_onclicksub as sub())
  OnPaintSub as sub()
  declare property OnResize(byval new_onclicksub as sub())
  OnResizeSub as sub()
  declare property OnMove(byval new_onclicksub as sub())
  OnMoveSub as sub()
  declare property OnClose(byval new_onclosesub as sub())
  OnCloseSub as sub()
end type



constructor Window()
  
end constructor



constructor Window(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval t as string)
  OnPaintSub = 0
  OnResizeSub = 0
  OnMoveSub = 0
  OnCloseSub = 0
  hwnd = CreateWindowEx(0, @"Designer", t, WS_OVERLAPPEDWINDOW,new_x, new_y, new_w, new_h, NULL, NULL, GetModuleHandle(null), NULL)
  dim as RECT client
  GetClientRect(hwnd,@client)
  dim as integer xdif = new_w- client.right - client.left, ydif = new_h- client.bottom - client.top
  SetWindowPos(hwnd,0,0,0,new_w+xdif,new_h+ydif,SWP_NOZORDER or SWP_NOMOVE)
  SetProp(hwnd,@"Typ",cast(HANDLE,0))
  SetProp(hwnd,@"This",@this)
end constructor



property Window.titel(byval new_titel as string)
  SendMessage(hwnd,WM_SETTEXT,0,cast(LPARAM,@new_titel))
end property



property Window.x(byval new_x as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,new_x,r.top,0,0,SWP_NOZORDER or SWP_NOSIZE)
end property



property Window.y(byval new_y as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,r.left,new_y,0,0,SWP_NOZORDER or SWP_NOSIZE)
end property



property Window.w(byval new_w as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  dim as RECT client
  GetClientRect(hwnd,@client)
  dim as integer xdif = new_w- client.right - client.left
  SetWindowPos(hwnd,0,0,0,new_w+xdif,r.bottom-r.top,SWP_NOZORDER or SWP_NOMOVE)
end property



property Window.h(byval new_h as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  dim as RECT client
  GetClientRect(hwnd,@client)
  dim as integer ydif = new_h- client.bottom - client.top
  SetWindowPos(hwnd,0,0,0,r.right-r.left,new_h+ydif,SWP_NOZORDER or SWP_NOMOVE)
end property



property Window.x() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   x = r.left
end property



property Window.y() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   y = r.top
end property



property Window.h() as integer
   dim as RECT r
   GetClientRect(hwnd,@r)
   h = r.bottom - r.top
end property



property Window.w() as integer
   dim as RECT r
   GetClientRect(hwnd,@r)
   w = r.right - r.left
end property



sub Window.toTop()
  BringWindowToTop(hwnd)
end sub



property Window.enable(byval new_enable as bool)
  EnableWindow(hwnd,new_enable)
end property



sub Window.hide()
  ShowWindow(hwnd,SW_HIDE)
end sub



sub Window.restore()
  ShowWindow(hwnd,SW_RESTORE)
end sub



sub Window.maximize()
  ShowWindow(hwnd,SW_MAXIMIZE)
end sub



sub Window.minimize()
  ShowWindow(hwnd,SW_MINIMIZE)
end sub



property Window.OnPaint(byval new_onpaintsub as sub())
  OnPaintSub = new_onpaintsub
  SetProp(hwnd,@"This",@this)
end property



property Window.OnResize(byval new_onresizesub as sub())
  OnResizeSub = new_onresizesub
  SetProp(hwnd,@"This",@this)
end property



property Window.OnMove(byval new_onmovesub as sub())
  OnMoveSub = new_onmovesub
  SetProp(hwnd,@"This",@this)
end property



property Window.OnClose(byval new_onclosesub as sub())
  OnCloseSub = new_onclosesub
  SetProp(hwnd,@"This",@this)
end property






type Button
  hwnd as HWND
  xval as integer
  yval as integer
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval text as string, byval parent as Window)
  declare constructor()
  declare sub click()
  declare sub move(byval xnew as integer, byval ynew as integer)
  declare property text(byval new_text as string)
  declare property x(byval new_x as integer)
  declare property y(byval new_y as integer)
  declare property h(byval new_h as integer)
  declare property w(byval new_w as integer)
  declare property x() as integer
  declare property y() as integer
  declare property h() as integer
  declare property w() as integer
  declare property enable(byval new_enable as bool)
  declare property enable() as bool
  declare property OnClick(byval new_onclicksub as sub())
  OnClickSub as sub()
end type



constructor Button(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval t as string, byval parent as Window)
  hwnd = CreateWindowEx(0, @"Button", t, BS_PUSHBUTTON or WS_CHILD or WS_VISIBLE,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  SetProp(hwnd,@"Typ",cast(HANDLE,1))
  OnClick = 0
  xval = new_x
  yval = new_y
  SetProp(hwnd,@"This",@this)
end constructor



constructor Button()
  
end constructor




sub Button.click()
  SendMessage(hwnd,BM_CLICK,0,0)
end sub



sub Button.move(byval xnew as integer, byval ynew as integer)
  SetWindowPos(hwnd,0,xnew,ynew,0,0,SWP_NOZORDER or SWP_NOSIZE)
end sub



property Button.text(byval new_titel as string)
  SendMessage(hwnd,WM_SETTEXT,0,cast(LPARAM,@new_titel))
end property



property Button.x(byval new_x as integer)
  SetWindowPos(hwnd,0,new_x,yval,0,0,SWP_NOZORDER or SWP_NOSIZE)
  xval = new_x
end property



property Button.y(byval new_y as integer)
  SetWindowPos(hwnd,0,xval,new_y,0,0,SWP_NOZORDER or SWP_NOSIZE)
  yval = new_y
end property



property Button.w(byval new_w as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,new_w,r.bottom-r.top,SWP_NOZORDER or SWP_NOMOVE)
end property



property Button.h(byval new_h as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,r.right-r.left,new_h,SWP_NOZORDER or SWP_NOMOVE)
end property



property Button.x() as integer
   x = xval
end property



property Button.y() as integer
   y = yval
end property



property Button.h() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   h = r.bottom - r.top
end property



property Button.w() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   w = r.right - r.left
end property



property Button.enable(byval new_enable as bool)
  EnableWindow(hwnd,new_enable)
end property



property Button.enable() as bool
  enable = IsWindowEnabled(hwnd)
end property



property Button.OnClick(byval new_onclicksub as sub())
  OnClickSub = new_onclicksub
  SetProp(hwnd,@"This",@this)
end property








type Checkbox
  hwnd as HWND
  xval as integer
  yval as integer
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval text as string, byval parent as Window)
  declare constructor()
  declare sub click()
  declare sub move(byval xnew as integer, byval ynew as integer)
  declare property text(byval new_text as string)
  declare property x(byval new_x as integer)
  declare property y(byval new_y as integer)
  declare property h(byval new_h as integer)
  declare property w(byval new_w as integer)
  declare property x() as integer
  declare property y() as integer
  declare property h() as integer
  declare property w() as integer
  declare property enable(byval new_enable as bool)
  declare property enable() as bool
  declare property value(byval new_value as bool)
  declare property value() as bool
  declare property OnClick(byval new_onclicksub as sub())
  OnClickSub as sub()
end type



constructor Checkbox(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval t as string, byval parent as Window)
  hwnd = CreateWindowEx(0, @"Button", t, BS_AUTOCHECKBOX or WS_CHILD or WS_VISIBLE,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  SetProp(hwnd,@"Typ",cast(HANDLE,2))
  OnClick = 0
  xval = new_x
  yval = new_y
  SetProp(hwnd,@"This",@this)
end constructor



constructor Checkbox()
  
end constructor



sub Checkbox.click()
  SendMessage(hwnd,BM_CLICK,0,0)
end sub



sub Checkbox.move(byval xnew as integer, byval ynew as integer)
  SetWindowPos(hwnd,0,xnew,ynew,0,0,SWP_NOZORDER or SWP_NOSIZE)
end sub



property Checkbox.text(byval new_titel as string)
  SendMessage(hwnd,WM_SETTEXT,0,cast(LPARAM,@new_titel))
end property



property Checkbox.x(byval new_x as integer)
  SetWindowPos(hwnd,0,new_x,yval,0,0,SWP_NOZORDER or SWP_NOSIZE)
  xval = new_x
end property



property Checkbox.y(byval new_y as integer)
  SetWindowPos(hwnd,0,xval,new_y,0,0,SWP_NOZORDER or SWP_NOSIZE)
  yval = new_y
end property



property Checkbox.w(byval new_w as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,new_w,r.bottom-r.top,SWP_NOZORDER or SWP_NOMOVE)
end property



property Checkbox.h(byval new_h as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,r.right-r.left,new_h,SWP_NOZORDER or SWP_NOMOVE)
end property



property Checkbox.x() as integer
   x = xval
end property



property Checkbox.y() as integer
   y = yval
end property



property Checkbox.h() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   h = r.bottom - r.top
end property



property Checkbox.w() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   w = r.right - r.left
end property



property Checkbox.enable(byval new_enable as bool)
  EnableWindow(hwnd,new_enable)
end property



property Checkbox.enable() as bool
  enable = IsWindowEnabled(hwnd)
end property



property Checkbox.value(byval new_value as bool)
  if new_value = true then
    SendMessage(hwnd,BM_SETCHECK,BST_CHECKED,0)
  elseif new_value = false then
    SendMessage(hwnd,BM_SETCHECK,BST_UNCHECKED,0)
  end if
end property



property Checkbox.value() as bool
  dim as integer s = SendMessage(hwnd,BM_GETCHECK,0,0)
  if s = BST_CHECKED then
    value = true
  elseif s = BST_UNCHECKED then
    value = false
  end if
end property



property Checkbox.OnClick(byval new_onclicksub as sub())
  OnClickSub = new_onclicksub
  SetProp(hwnd,@"This",@this)
end property








type LineEdit
  hwnd as HWND
  xval as integer
  yval as integer
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval text as string, byval parent as Window)
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval text as string, byval parent as Window, byval extra as integer)
  declare constructor()
  declare sub move(byval xnew as integer, byval ynew as integer)
  declare property text(byval new_text as string)
  declare property x(byval new_x as integer)
  declare property y(byval new_y as integer)
  declare property h(byval new_h as integer)
  declare property w(byval new_w as integer)
  declare property text() as string
  declare property x() as integer
  declare property y() as integer
  declare property h() as integer
  declare property w() as integer
  declare property canUndo() as bool
  
  declare property OnChange(byval new_changesub as sub())
  OnChangeSub as sub()
end type



constructor LineEdit(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval t as string, byval parent as Window)
  hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, @"Edit", t, ES_LEFT or ES_AUTOHSCROLL or WS_CHILD or WS_VISIBLE,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  OnChangeSub = null
  xval = new_x
  yval = new_y
  SetProp(hwnd,@"Typ",cast(HANDLE,3))
  SetProp(hwnd,@"This",@this)
end constructor



constructor LineEdit(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval t as string, byval parent as Window, byval extra as integer)
  hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, @"Edit", t, ES_LEFT or ES_AUTOHSCROLL or WS_CHILD or WS_VISIBLE or extra,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  OnChangeSub = null
  xval = new_x
  yval = new_y
  SetProp(hwnd,@"Typ",cast(HANDLE,3))
  SetProp(hwnd,@"This",@this)
end constructor



constructor LineEdit()
  
end constructor



sub LineEdit.move(byval xnew as integer, byval ynew as integer)
  SetWindowPos(hwnd,0,xnew,ynew,0,0,SWP_NOZORDER or SWP_NOSIZE)
end sub



property LineEdit.text(byval new_titel as string)
  SendMessage(hwnd,WM_SETTEXT,0,cast(LPARAM,@new_titel))
end property



property LineEdit.x(byval new_x as integer)
  SetWindowPos(hwnd,0,new_x,yval,0,0,SWP_NOZORDER or SWP_NOSIZE)
  xval = new_x
end property



property LineEdit.y(byval new_y as integer)
  SetWindowPos(hwnd,0,xval,new_y,0,0,SWP_NOZORDER or SWP_NOSIZE)
  yval = new_y
end property



property LineEdit.w(byval new_w as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,new_w,r.bottom-r.top,SWP_NOZORDER or SWP_NOMOVE)
end property



property LineEdit.h(byval new_h as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,r.right-r.left,new_h,SWP_NOZORDER or SWP_NOMOVE)
end property



property LineEdit.text() as string
  dim t as string*1024
  SendMessage(hwnd,WM_GETTEXT,1024,cast(LPARAM,@t))
  text = t
end property



property LineEdit.x() as integer
   x = xval
end property



property LineEdit.y() as integer
   y = yval
end property



property LineEdit.h() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   h = r.bottom - r.top
end property



property LineEdit.w() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   w = r.right - r.left
end property



property LineEdit.canUndo() as bool
  canUndo = SendMessage(hwnd,EM_CANUNDO,0,0)
end property



property LineEdit.OnChange(byval new_onchangesub as sub())
  OnChangeSub = new_onchangesub
  SetProp(hwnd,@"This",@this)
end property









type TextEdit
  hwnd as HWND
  xval as integer
  yval as integer
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval text as string, byval parent as Window)
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval text as string, byval parent as Window, byval extra as integer)
  declare constructor()
  declare sub move(byval xnew as integer, byval ynew as integer)
  declare property text(byval new_text as string)
  declare property x(byval new_x as integer)
  declare property y(byval new_y as integer)
  declare property h(byval new_h as integer)
  declare property w(byval new_w as integer)
  declare property text() as string
  declare property x() as integer
  declare property y() as integer
  declare property h() as integer
  declare property w() as integer
  declare property canUndo() as bool
  
  declare property OnChange(byval new_changesub as sub())
  OnChangeSub as sub()
end type



constructor TextEdit(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval t as string, byval parent as Window)
  hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, @"Edit", t, ES_LEFT or ES_AUTOHSCROLL or ES_MULTILINE or WS_CHILD or WS_VISIBLE,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  OnChangeSub = null
  xval = new_x
  yval = new_y
  SetProp(hwnd,@"Typ",cast(HANDLE,4))
  SetProp(hwnd,@"This",@this)
end constructor



constructor TextEdit(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval t as string, byval parent as Window, byval extra as integer)
  hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, @"Edit", t, ES_LEFT or ES_AUTOHSCROLL or ES_MULTILINE or WS_CHILD or WS_VISIBLE or extra,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  OnChangeSub = null
  xval = new_x
  yval = new_y
  SetProp(hwnd,@"Typ",cast(HANDLE,4))
  SetProp(hwnd,@"This",@this)
end constructor



constructor TextEdit()
  
end constructor



sub TextEdit.move(byval xnew as integer, byval ynew as integer)
  SetWindowPos(hwnd,0,xnew,ynew,0,0,SWP_NOZORDER or SWP_NOSIZE)
end sub



property TextEdit.text(byval new_titel as string)
  SendMessage(hwnd,WM_SETTEXT,0,cast(LPARAM,@new_titel))
end property



property TextEdit.x(byval new_x as integer)
  SetWindowPos(hwnd,0,new_x,yval,0,0,SWP_NOZORDER or SWP_NOSIZE)
  xval = new_x
end property



property TextEdit.y(byval new_y as integer)
  SetWindowPos(hwnd,0,xval,new_y,0,0,SWP_NOZORDER or SWP_NOSIZE)
  yval = new_y
end property



property TextEdit.w(byval new_w as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,new_w,r.bottom-r.top,SWP_NOZORDER or SWP_NOMOVE)
end property



property TextEdit.h(byval new_h as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,r.right-r.left,new_h,SWP_NOZORDER or SWP_NOMOVE)
end property



property TextEdit.text() as string
  dim t as string*1024
  SendMessage(hwnd,WM_GETTEXT,1024,cast(LPARAM,@t))
  text = t
end property



property TextEdit.x() as integer
   x = xval
end property



property TextEdit.y() as integer
   y = yval
end property



property TextEdit.h() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   h = r.bottom - r.top
end property



property TextEdit.w() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   w = r.right - r.left
end property



property TextEdit.canUndo() as bool
  canUndo = SendMessage(hwnd,EM_CANUNDO,0,0)
end property



property TextEdit.OnChange(byval new_onchangesub as sub())
  OnChangeSub = new_onchangesub
  SetProp(hwnd,@"This",@this)
end property






type Combobox
  hwnd as HWND
  xval as integer
  yval as integer
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval parent as Window)
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval parent as Window, byval extra as integer)
  declare constructor()
  declare sub move(byval xnew as integer, byval ynew as integer)
  declare property text(byval new_text as string)
  declare property x(byval new_x as integer)
  declare property y(byval new_y as integer)
  declare property h(byval new_h as integer)
  declare property w(byval new_w as integer)
  declare property text() as string
  declare property x() as integer
  declare property y() as integer
  declare property h() as integer
  declare property w() as integer
  
  declare property OnChange(byval new_changesub as sub())
  OnChangeSub as sub()
end type



constructor Combobox(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval parent as Window)
  hwnd = CreateWindowEx(0, @"Combobox",0, CBS_DROPDOWNLIST or WS_CHILD or WS_VISIBLE,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  OnChangeSub = null
  xval = new_x
  yval = new_y
  SetProp(hwnd,@"Typ",cast(HANDLE,4))
  SetProp(hwnd,@"This",@this)
end constructor



constructor Combobox(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval parent as Window, byval extra as integer)
  hwnd = CreateWindowEx(0, @"Combobox", 0, CBS_DROPDOWNLIST or WS_CHILD or WS_VISIBLE or extra,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  OnChangeSub = null
  xval = new_x
  yval = new_y
  SetProp(hwnd,@"Typ",cast(HANDLE,4))
  SetProp(hwnd,@"This",@this)
end constructor



constructor Combobox()
  
end constructor



sub Combobox.move(byval xnew as integer, byval ynew as integer)
  SetWindowPos(hwnd,0,xnew,ynew,0,0,SWP_NOZORDER or SWP_NOSIZE)
end sub



property Combobox.text(byval new_titel as string)
  SendMessage(hwnd,WM_SETTEXT,0,cast(LPARAM,@new_titel))
end property



property Combobox.x(byval new_x as integer)
  SetWindowPos(hwnd,0,new_x,yval,0,0,SWP_NOZORDER or SWP_NOSIZE)
  xval = new_x
end property



property Combobox.y(byval new_y as integer)
  SetWindowPos(hwnd,0,xval,new_y,0,0,SWP_NOZORDER or SWP_NOSIZE)
  yval = new_y
end property



property Combobox.w(byval new_w as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,new_w,r.bottom-r.top,SWP_NOZORDER or SWP_NOMOVE)
end property



property Combobox.h(byval new_h as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,r.right-r.left,new_h,SWP_NOZORDER or SWP_NOMOVE)
end property



property Combobox.text() as string
  dim t as string*1024
  SendMessage(hwnd,WM_GETTEXT,1024,cast(LPARAM,@t))
  text = t
end property



property Combobox.x() as integer
   x = xval
end property



property Combobox.y() as integer
   y = yval
end property



property Combobox.h() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   h = r.bottom - r.top
end property



property Combobox.w() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   w = r.right - r.left
end property



property Combobox.OnChange(byval new_onchangesub as sub())
  OnChangeSub = new_onchangesub
  SetProp(hwnd,@"This",@this)
end property








type Listbox
  hwnd as HWND
  xval as integer
  yval as integer
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval parent as Window)
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval parent as Window, byval extra as integer)
  declare constructor()
  declare sub move(byval xnew as integer, byval ynew as integer)
  declare sub add (byval n as string)
  declare sub remove(byval index as integer)
  declare function find(byval f as string, byval start as integer = -1) as integer
  declare property x(byval new_x as integer)
  declare property y(byval new_y as integer)
  declare property h(byval new_h as integer)
  declare property w(byval new_w as integer)
  declare property x() as integer
  declare property y() as integer
  declare property h() as integer
  declare property w() as integer
  
  declare property OnChange(byval new_changesub as sub())
  OnChangeSub as sub()
end type



constructor Listbox(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval parent as Window)
  hwnd = CreateWindowEx(0, @"Listbox",0, LBS_NOTIFY or LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or WS_CHILD or WS_VISIBLE,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  OnChangeSub = null
  SetProp(hwnd,@"Typ",cast(HANDLE,6))
  SetProp(hwnd,@"This",@this)
end constructor



constructor Listbox(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval parent as Window, byval extra as integer)
  hwnd = CreateWindowEx(0, @"Listbox", 0, LBS_NOTIFY or LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or WS_CHILD or WS_VISIBLE or extra,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  OnChangeSub = null
  xval = new_x
  yval = new_y
  SetProp(hwnd,@"Typ",cast(HANDLE,6))
  SetProp(hwnd,@"This",@this)
end constructor



constructor Listbox()
  
end constructor



sub Listbox.move(byval xnew as integer, byval ynew as integer)
  SetWindowPos(hwnd,0,xnew,ynew,0,0,SWP_NOZORDER or SWP_NOSIZE)
end sub



sub Listbox.add (byval n as string)
  SendMessage(hwnd,LB_ADDSTRING,0,cast(lParam,@n))
end sub



sub Listbox.remove (byval n as integer)
  SendMessage(hwnd,LB_DELETESTRING,n,0)
end sub



function Listbox.find (byval f as string, byval start as integer = -1) as integer
  dim as integer i = SendMessage(hwnd,LB_FINDSTRINGEXACT,start,@f)
  if i <> LB_ERR then
    return i
  end if
end function



property Listbox.x(byval new_x as integer)
  SetWindowPos(hwnd,0,new_x,yval,0,0,SWP_NOZORDER or SWP_NOSIZE)
  xval = new_x
end property



property Listbox.y(byval new_y as integer)
  SetWindowPos(hwnd,0,xval,new_y,0,0,SWP_NOZORDER or SWP_NOSIZE)
  yval = new_y
end property



property Listbox.w(byval new_w as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,new_w,r.bottom-r.top,SWP_NOZORDER or SWP_NOMOVE)
end property



property Listbox.h(byval new_h as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,r.right-r.left,new_h,SWP_NOZORDER or SWP_NOMOVE)
end property



property Listbox.x() as integer
   x = xval
end property



property Listbox.y() as integer
   y = yval
end property



property Listbox.h() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   h = r.bottom - r.top
end property



property Listbox.w() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   w = r.right - r.left
end property



property Listbox.OnChange(byval new_onchangesub as sub())
  OnChangeSub = new_onchangesub
  SetProp(hwnd,@"This",@this)
end property






type RichEdit
  hwnd as HWND
  xval as integer
  yval as integer
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval text as string, byval parent as Window)
  declare constructor(byval x as integer, byval y as integer, byval w as integer, byval h as integer, byval text as string, byval parent as Window, byval extra as integer)
  declare constructor()
  declare sub move(byval xnew as integer, byval ynew as integer)
  declare property text(byval new_text as string)
  declare property x(byval new_x as integer)
  declare property y(byval new_y as integer)
  declare property h(byval new_h as integer)
  declare property w(byval new_w as integer)
  declare property text() as string
  declare property x() as integer
  declare property y() as integer
  declare property h() as integer
  declare property w() as integer
  declare property canUndo() as bool
  
  declare property OnChange(byval new_changesub as sub())
  OnChangeSub as sub()
end type



constructor RichEdit(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval t as string, byval parent as Window)
  hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "Richedit20A", t, ES_LEFT or ES_AUTOHSCROLL or ES_MULTILINE or WS_CHILD or WS_VISIBLE,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  OnChangeSub = null
  xval = new_x
  yval = new_y
  SetProp(hwnd,@"Typ",cast(HANDLE,7))
  SetProp(hwnd,@"This",@this)
end constructor



constructor RichEdit(byval new_x as integer, byval new_y as integer, byval new_w as integer, byval new_h as integer, byval t as string, byval parent as Window, byval extra as integer)
  hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "Richedit20A", t, ES_LEFT or ES_AUTOHSCROLL or ES_MULTILINE or WS_CHILD or WS_VISIBLE or extra,new_x, new_y, new_w, new_h, parent.hwnd, NULL, GetModuleHandle(null), NULL)
  SendMessage(hwnd,WM_SETFONT,cast(WPARAM,GetStockObject(DEFAULT_GUI_FONT)),TRUE)
  OnChangeSub = null
  SetProp(hwnd,@"Typ",cast(HANDLE,7))
  SetProp(hwnd,@"This",@this)
end constructor



constructor RichEdit()
  
end constructor



sub RichEdit.move(byval xnew as integer, byval ynew as integer)
  SetWindowPos(hwnd,0,xnew,ynew,0,0,SWP_NOZORDER or SWP_NOSIZE)
end sub



property RichEdit.text(byval new_titel as string)
  SendMessage(hwnd,WM_SETTEXT,0,cast(LPARAM,@new_titel))
end property



property RichEdit.x(byval new_x as integer)
  SetWindowPos(hwnd,0,new_x,yval,0,0,SWP_NOZORDER or SWP_NOSIZE)
  xval = new_x
end property



property RichEdit.y(byval new_y as integer)
  SetWindowPos(hwnd,0,xval,new_y,0,0,SWP_NOZORDER or SWP_NOSIZE)
  yval = new_y
end property



property RichEdit.w(byval new_w as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,new_w,r.bottom-r.top,SWP_NOZORDER or SWP_NOMOVE)
end property



property RichEdit.h(byval new_h as integer)
  dim r as RECT
  GetWindowRect(hwnd,@r)
  SetWindowPos(hwnd,0,0,0,r.right-r.left,new_h,SWP_NOZORDER or SWP_NOMOVE)
end property



property RichEdit.text() as string
  dim t as string*1024
  SendMessage(hwnd,WM_GETTEXT,1024,cast(LPARAM,@t))
  text = t
end property



property RichEdit.x() as integer
   x = xval
end property


property RichEdit.y() as integer
   y = yval
end property



property RichEdit.h() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   h = r.bottom - r.top
end property



property RichEdit.w() as integer
   dim as RECT r
   GetWindowRect(hwnd,@r)
   w = r.right - r.left
end property



property RichEdit.canUndo() as bool
  canUndo = SendMessage(hwnd,EM_CANUNDO,0,0)
end property



property RichEdit.OnChange(byval new_onchangesub as sub())
  OnChangeSub = new_onchangesub
  SetProp(hwnd,@"This",@this)
end property




function WndProc ( byval hwnd as HWND,byval msg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
    dim as integer typ
    dim as PAINTSTRUCT ps
    dim as Window ptr w
    dim as Button ptr b
    dim as Checkbox ptr c
    dim as Listbox ptr lb
    dim as LineEdit ptr le
    dim as TextEdit ptr te
    dim as RichEdit ptr re
    
    select case(msg)
        case WM_DESTROY
            PostQuitMessage(0)
            return 0
            
        case WM_COMMAND
            if lParam <> 0 then
              typ = cast(integer,GetProp(cast(HWND,lParam),@"Typ"))
              if typ = 1 then
                b = GetProp(cast(HWND,lParam),"This")
                if b->OnClickSub <> null and hiword(wParam) = BN_CLICKED then
                  b->OnClickSub()
                end if
              elseif typ = 2 then
                c = GetProp(cast(HWND,lParam),"This")
                if c->OnClickSub <> null and hiword(wParam) = BN_CLICKED then
                  c->OnClickSub()
                end if
              elseif typ = 3 then
                le = GetProp(cast(HWND,lParam),"This")
                if le->OnChangeSub <> null and hiword(wParam) = EN_CHANGE then
                  le->OnChangeSub()
                end if
              elseif typ = 4 then
                te = GetProp(cast(HWND,lParam),"This")
                if te->OnChangeSub <> null and hiword(wParam) = EN_CHANGE then
                  te->OnChangeSub()
                end if
              elseif typ = 6 then
                lb = GetProp(cast(HWND,lParam),"This")
                if lb->OnChangeSub <> null and hiword(wParam) = LBN_SELCHANGE then
                  lb->OnChangeSub()
                end if
              elseif typ = 7 then
                re = GetProp(cast(HWND,lParam),"This")
                if re->OnChangeSub <> null and hiword(wParam) = EN_UPDATE then
                  re->OnChangeSub()
                end if
              end if
            end if
            return 0
            
        case WM_PAINT
            typ = cast(integer,GetProp(hwnd,@"Typ"))
            if typ = 0 then
              w = GetProp(hwnd,"This")
              global_hdc = BeginPaint(hwnd,@ps)
              if w->OnPaintSub <> null then
                w->OnPaintSub()
              end if
              EndPaint(hwnd,@ps)
            end if
            return 0
            
        case WM_SIZE
          typ = cast(integer,GetProp(hwnd,@"Typ"))
          if typ = 0 then
            w = GetProp(hwnd,"This")
            if w = 0 then
              return 0
            end if
            if w->OnResizeSub <> null then
              w->OnResizeSub()
            end if
          end if
          return 0
        
        case WM_MOVE
          typ = cast(integer,GetProp(hwnd,@"Typ"))
          if typ = 0 then
            w = GetProp(hwnd,"This")
            if w->OnMoveSub <> null then
              w->OnMoveSub()
            end if
          end if
          return 0
          
        case WM_CLOSE
          typ = cast(integer,GetProp(hwnd,@"Typ"))
          if typ = 0 then
            w = GetProp(hwnd,"This")
            if w->OnCloseSub <> null then
              w->OnCloseSub()
            end if
          end if
          return DefWindowProc( hwnd, msg, wParam, lParam )
          
    end select
    return DefWindowProc( hwnd, msg, wParam, lParam )
end function