#include once "gui.bas" 

#define Q_Dummy(ptr) *cast(PDummy,ptr)
#define W_Dummy(dlg) *cast(QDummy ptr,GetWindowLongPtr(dlg,GetClassLongPtr(dlg,gcl_cbwndextra)-cboffset))

type PDummy as QDummy ptr
type QDummy extends QFrame
    protected:
    declare virtual sub Dispatch(byref as QMessage)
    declare static function dlgproc(as hwnd,as uint,as wparam,as lparam) as lresult
    public:
    declare static function Register as integer
    declare virtual operator cast as any ptr
    declare constructor
    declare destructor
    #ifdef RTL
     declare virtual function GetProperties as zstring ptr
     declare virtual function GetPropertyInfo(as string) as PELPropInfo
     declare virtual function GetProperty(as string) as zstring ptr
     declare virtual function SetProperty(as string,as zstring ptr) as boolean
    #endif
end type

namespace Dummy
    function Register as zstring ptr
        return @"UserTypes=QDummy"
    end function
end namespace

'''QDummy'''
#ifdef RTL
     function QDummy.GetProperties as zstring ptr
         return Base.GetProperties
     end function

     function QDummy.GetPropertyInfo(v as string) as PELPropInfo
         return Base.GetPropertyInfo(v)
     end function

     function QDummy.GetProperty(v as string) as zstring ptr
         return Base.GetProperty(v)
     end function

     function QDummy.SetProperty(n as string,v as zstring ptr) as boolean
         return Base.SetProperty(n,v)
     end function
#endif

function QDummy.dlgproc(dlg as hwnd,msg as uint,wparam as wparam,lparam as lparam) as lresult
    dim as PFrame F=iif(CreationData,CreationData,cast(PFrame,GetWindowLongPtr(dlg,GetClassLongPtr(dlg,gcl_cbwndextra)-sizeof(integer))))
    dim as QMessage m=type(dlg,msg,wparam,lparam,0,F)
    if F then
       F->fhandle=dlg
       F->Dispatch(m)
       if m.result=0 then F->Handler(m)
       return m.result
    else
       F=new QDummy
       F->fhandle=dlg
       F->Dispatch(m)
       if m.result=0 then F->Handler(m)
       return m.result
    end if
    return m.result
end function

sub QDummy.Dispatch(byref m as QMessage)
    select case m.msg
    case wm_paint
         dim as paintstruct ps
         dim as hdc dc=BeginPaint(fhandle,@ps)
         rectangle(dc,ps.rcpaint.left+1,ps.rcpaint.top+1,ps.rcpaint.right-1,ps.rcpaint.bottom-1)
         TextOut(dc,10,10,"QDummy",7)
         EndPaint(fhandle,@ps)
         m.result=0
    end select
    Base.Dispatch(m)
end sub

function QDummy.Register as integer
    dim as wndclassex wcls
    wcls.cbsize=sizeof(wcls)
       wcls.lpszclassname=@"QDummy"
       wcls.lpfnwndproc=@dlgproc
       wcls.hinstance=instance
       wcls.hcursor=loadcursor(0,idc_arrow)
       wcls.cbwndextra+=sizeof(integer)
       return RegisterClassEx(@wcls)
end function

operator QDummy.cast as any ptr
    return @this
end operator

constructor QDummy
    classname="QDummy"
    classancestor=""
    fstyle=ws_child
    fwidth=175
    fheight=125
end constructor

destructor QDummy
end destructor

sub Dummy_initialization constructor
    QDummy.register
end sub