#Include once "window9.bi"

Function PanelGadget(ByVal gadget As Integer, ByVal x As Integer,ByVal y As Integer,ByVal Width_ As Integer,ByVal height_ As Integer,ByVal SizeIcon As Integer=16,ByVal par As Integer=0) As HWND Export
  Dim As RECT rcClient
  Dim As HWND hwndTab
  Dim As hImageList hImageList

  GetClientRect(Cast(HWND,GETGURRENTAL), @rcClient)
  If width_=0 Or Height_=0 Then
    width_=rcClient.right
    height_=rcClient.bottom
  EndIf
  hwndTab = CreateWindow(WC_TABCONTROL, "", WS_CHILD or WS_CLIPSIBLINGS Or WS_VISIBLE Or par,x, y, width_, height_,Cast(HWND,GETGURRENTAL), Cast(HMENU,gadget), 0, NULL)
  ADDIN9999 (gadget,hwndTab)
  If GGF()<>0 Then
    SendMessage(Cast(hwnd,hwndTab),WM_SETFONT,GGF(),0)
  EndIf
  hImageList=  ImageList_Create(SizeIcon,SizeIcon,ILC_COLOR32,1,1)
  SetProp(hwndTab,"addparam60000",hImageList)
  SendMessage(Cast(hwnd,hwndTab), TCM_SETIMAGELIST, 0,Cast(LPARAM, hImageList))
  Return hwndTab
End Function

Function AddPanelGadgetItem(ByVal gadget As Integer, ByVal Item As Integer,ByVal text As String, ByVal ImageID As HBITMAP=0, ByVal flag As bool=0) As HWND Export
  Dim As RECT re
  Dim As Integer ppoos=-1
  If ImageID<>0 Then
    ppoos=ImageList_Add(Cast(HIMAGELIST,GetHimageCombo_(gadget)),Cast(HBITMAP,ImageID),0)
  EndIf
  Var t1=openWindow("",0,0,0,0,0)
  SetProp(GadgetID(gadget),"paneltab",t1)
  SetProp(GadgetID(gadget),"paneltabItem",Cast(HANDLE,Item))
  SetProp(t1,"panelevent",Cast(Handle,1))
  Dim As  TCITEM tie
  tie.mask = TCIF_TEXT or TCIF_IMAGE Or TCIF_PARAM
  tie.pszText=StrPtr(text)
  tie.iImage =ppoos
  tie.lParam=Cast(LPARAM,t1)
  TabCtrl_InsertItem(GadgetID(gadget), item, @tie)
  SetParent(t1,GadgetID(gadget))
  SetWindowLong(t1,GWL_STYLE,  WS_CHILD)
  SendMessage(GadgetID(gadget),TCM_GETITEMRECT,item,Cast(LPARAM,@re))
  ResizeWindow(t1,1,re.bottom+1,GadgetWidth(gadget)-3,GadgetHeight(gadget)-26)
  If flag=0 Then
    UseGadgetList(GetParent(GadgetID(gadget)))
  EndIf
  DeleteObject(Cast(HGDIOBJ,ppoos))
  Return t1
End Function

Function DeleteItemPanelGadget(ByVal gadget As Integer, ByVal item As Integer) As Integer Export
  Dim As TC_ITEM TC_ITEM_
  TC_ITEM_.mask=TCIF_PARAM
  SendMessage(GadgetID(gadget),TCM_GETITEM,item,Cast(LPARAM,@TC_ITEM_))
  DestroyWindow(Cast(HWND,TC_ITEM_.LPARAm))
  Function=SendMessage(GadgetID(gadget),TCM_DELETEITEM,item,0)
End Function
