#include once "window9.bi"

Function CheckBoxGadget(ByVal gadget As long, _
						ByVal x As Long, ByVal y As Long, _
						ByVal w As Long, ByVal h As Long, _
						ByRef sWindowTitle As USTRING, _
						ByVal Style As Long) As HWND Export
	#ifdef UNICODE
		Var hWin = CreateWindowEx( 0, "Button", *sWindowTitle, WS_VISIBLE Or WS_CHILD Or Style, x,y,w,h, Cast(HWND,win9GetCurrent()), Cast(HMENU,CInt(gadget)), 0, 0)
	#else	
		Var hWin = CreateWindowEx( 0, "Button", sWindowTitle, WS_VISIBLE Or WS_CHILD Or Style, x,y,w,h, Cast(HWND,win9GetCurrent()), Cast(HMENU,CInt(gadget)), 0, 0)
	#EndIf 
	win9AddNewGadget(gadget,hWin)
	win9AddColor(hWin,15790320,0)
    dim as hwnd hwParent = Cast(HWND,win9GetCurrent())
    for i as Long = 0 to 1000
        dim as USTRING sz = getclassname_(hwParent)
        if instr(sz , "CLASSCLASS_") andalso getparent(hwParent) = 0 then
            if getprop(hwParent , "tabstopenable") then
                win9AddTabStop(hwParent , gadget)
            EndIf
            exit for
        else
            hwParent = getparent(hwParent)
            if hwParent = 0 then exit for
        EndIf
    Next
	If win9GetGadgetFont()<>0 Then SendMessage(Cast(HWND,hWin),WM_SETFONT,win9GetGadgetFont(),0)
	Return hWin
End Function
