#include once "window9.bi"

Function ButtonImageGadget(ByVal gadget As Long, _
						ByVal x As Long, ByVal y As Long, _
						ByVal w As Long, ByVal h As Long, _
						ByVal imageId As Any ptr, ByVal Style As Long) As HWND Export
	Var hWin = CreateWindowEx( 0, "Button", 0, WS_VISIBLE Or WS_CHILD Or Style, x,y,w,h, Cast(HWND,win9GetCurrent()), Cast(HMENU,CInt(gadget)), 0, 0)
	If imageId<>0 Then 
		If style And BS_BITMAP Then
			SendMessage(hWin, BM_SETIMAGE, 0,Cast(LPARAM,imageId))
		ElseIf style And BS_ICON Then
			SendMessage(hWin, BM_SETIMAGE, IMAGE_ICON,Cast(LPARAM,imageId))
		EndIf 
	EndIf
	win9AddNewGadget(gadget, hWin)
    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
	Return hWin
End Function
