Add Close buttons to Panel Tabs
Posted: Sun Jul 29, 2007 4:13 am
Code: Select all
;=======================================================
; Demo: Add close buttons to panel tabs
;
; netmaestro, July 2007
;
; Looks best with XP skins enabled
;=======================================================
Procedure ReAdjustTabButtons(hwnd, lParam)
item = GetProp_(hwnd, "itemnumber")
If item > lParam
newitem = item-1
SetProp_(hwnd, "itemnumber", newitem)
SendMessage_(GetParent_(hwnd), #TCM_GETITEMRECT, newitem, tr.RECT)
MoveWindow_(hwnd, tr\left+42,3,18,18,#True)
EndIf
ProcedureReturn #True
EndProcedure
Procedure ButtonProc(hwnd, msg, wParam, lParam)
oldproc = GetProp_(hwnd, "oldproc")
itemnumber = GetProp_(hwnd, "itemnumber")
parent = GetParent_(hwnd)
gadgetnumber = GetDlgCtrlID_(hwnd)
Select msg
Case #WM_LBUTTONUP
GetCursorPos_(@cp.POINT)
GetWindowRect_(hwnd, @br.RECT)
If PtInRect_(@br, cp\x, cp\y)
DestroyWindow_(hwnd)
RemoveGadgetItem(0,itemnumber)
EnumChildWindows_(parent, @ReAdjustTabButtons(), itemnumber)
numitems = SendMessage_(parent, #TCM_GETITEMCOUNT, 0, 0)
If numitems = 0
FreeGadget(GetDlgCtrlID_(parent))
Else
InvalidateRect_(parent, 0,1)
EndIf
EndIf
Case #WM_NCDESTROY
RemoveProp_(hwnd, "oldproc")
RemoveProp_(hwnd, "itemnumber")
EndSelect
ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wParam, lParam)
EndProcedure
OpenWindow(0,0,0,320,240,"",$CA0001)
CreateGadgetList(WindowID(0))
PanelGadget(0,20,20,280,200)
AddGadgetItem(0,0,"Tab 0 ")
AddGadgetItem(0,1,"Tab 1 ")
AddGadgetItem(0,2,"Tab 2 ")
Dim tabbutton(2)
For i=0 To 2
SendMessage_(GadgetID(0), #TCM_GETITEMRECT, i, @tr.RECT)
tabbutton(i) = CreateWindowEx_(0,"Button","X",#WS_CHILD|#WS_VISIBLE,tr\left+42,3,18,18,GadgetID(0),i+1,GetModuleHandle_(0),0)
SendMessage_(tabbutton(i), #WM_SETFONT, GetStockObject_(#DEFAULT_GUI_FONT),0)
oldbuttonproc = SetWindowLong_(tabbutton(i), #GWL_WNDPROC, @ButtonProc())
SetProp_(tabbutton(i), "oldproc", oldbuttonproc)
SetProp_(tabbutton(i), "itemnumber", i)
Next
Repeat:Until WaitWindowEvent() = #PB_Event_CloseWindow