DISABLE A PANELGADGET ITEM
Posted: Fri Jun 24, 2005 9:05 pm
ok folks, here it is. code for a disabled panelgadget item. some notes first:
1) if you inspect a PB panelgadget closely with WinID, youll find that the parent of the panel is NOT the main window, but a STATIC control EXACTLY the same size and position. this most likely is used to trap all the drawitem and other messages.
2) this static control now allows you to SUBCLASS and process messages ANY way you want WITHOUT setting windowcallback.
3) this took me a while to do, so if you use it, give me my props.
and there you have it. DISABLED TAB ITEMS
and the crowd goes wild:::::
1) if you inspect a PB panelgadget closely with WinID, youll find that the parent of the panel is NOT the main window, but a STATIC control EXACTLY the same size and position. this most likely is used to trap all the drawitem and other messages.
2) this static control now allows you to SUBCLASS and process messages ANY way you want WITHOUT setting windowcallback.
3) this took me a while to do, so if you use it, give me my props.

Code: Select all
Global OriginProc.l,textcolor
Dim oldsel.l(1)
Procedure tabproc(hwnd,msg,wParam,lParam)
Select msg
Case #WM_DRAWITEM
textbuffer.s=Space(255)
*lpdis.DRAWITEMSTRUCT=lParam
tab.TC_ITEM
Select *lpdis\CtlType
Case #ODT_TAB
Select *lpdis\itemState
Case #ODS_SELECTED
tab\Mask=#TCIF_TEXT
tab\pszText=@textbuffer
tab\cchTextMax=255
SendMessage_(*lpdis\hwndItem,#TCM_GETITEM,*lpdis\itemID,@tab)
textcolor.l= #Black
Case #ODS_SELECTED | #ODS_FOCUS
drawfoc.l=#True
Case 0
tab\Mask=#TCIF_PARAM
SendMessage_(*lpdis\hwndItem,#TCM_GETITEM,*lpdis\itemID,@tab)
If tab\lParam=1
tab\Mask=#TCIF_TEXT
tab\pszText=@textbuffer
tab\cchTextMax=255
SendMessage_(*lpdis\hwndItem,#TCM_GETITEM,*lpdis\itemID,@tab)
textcolor.l= #White
*lpdis\rcItem\left+5
*lpdis\rcItem\top+3
SetTextColor_(*lpdis\hdc, textcolor)
DrawText_(*lpdis\hdc, textbuffer, Len(textbuffer), *lpdis\rcItem, dtFlags)
textcolor.l= RGB(84,82,84)
*lpdis\rcItem\top-3
*lpdis\rcItem\left-5
; this code here draws text just like windows disabled, grey with white shadow
; by messing with the RECT coordinates
Else
tab\Mask=#TCIF_TEXT
tab\pszText=@textbuffer
tab\cchTextMax=255
SendMessage_(*lpdis\hwndItem,#TCM_GETITEM,*lpdis\itemID,@tab)
textcolor.l= #Black
EndIf
EndSelect
If drawfoc=#True
DrawFocusRect_(*lpdis\hdc, *lpdis\rcItem)
EndIf
SetBkMode_(*lpdis\hdc, #TRANSPARENT)
*lpdis\rcItem\left+4
*lpdis\rcItem\top+2
SetTextColor_(*lpdis\hdc, textcolor)
DrawText_(*lpdis\hdc, textbuffer, Len(textbuffer), *lpdis\rcItem, dtFlags)
ProcedureReturn 0
EndSelect
Case #WM_NOTIFY
*pNMHDR.NMHDR = lParam
tab1.TC_ITEM
Select *pNMHDR\code
Case #TCN_SELCHANGING
; --> Get the index of the Tab that is about to lose focus
oldsel(0)=SendMessage_(*pNMHDR\hwndFrom,#TCM_GETCURSEL,0,0)
Case #TCN_SELCHANGE
; --> Get the index of the selected Tab
newTab = SendMessage_(*pNMHDR\hwndFrom,#TCM_GETCURSEL,0,0)
tab1\Mask=#TCIF_PARAM
SendMessage_(*pNMHDR\hwndFrom,#TCM_GETITEM,newTab,@tab1)
If tab1\lParam=1
SendMessage_(*pNMHDR\hwndFrom,#TCM_SETCURSEL,oldsel(0),0)
EndIf
ProcedureReturn 0
EndSelect
EndSelect
ProcedureReturn CallWindowProc_(OriginProc,hwnd,msg,wParam,lParam)
EndProcedure
Procedure disablepanelitem(panel,item,State)
If State=1
itm.TC_ITEM
itm\Mask=#TCIF_PARAM
SendMessage_(GadgetID(panel),#TCM_GETITEM,item,@itm)
itm\lParam=1
itm\Mask=#TCIF_PARAM
SendMessage_(GadgetID(panel),#TCM_SETITEM,item,@itm)
ElseIf State=0
itm.TC_ITEM
itm\Mask=#TCIF_PARAM
SendMessage_(GadgetID(panel),#TCM_GETITEM,item,@itm)
itm\lParam=0
itm\Mask=#TCIF_PARAM
SendMessage_(GadgetID(panel),#TCM_SETITEM,item,@itm)
EndIf
EndProcedure
#WindowWidth = 390
#WindowHeight = 350
If OpenWindow(0, 100, 200, #WindowWidth, #WindowHeight, #PB_Window_MinimizeGadget, "")
If CreateGadgetList(WindowID())
PanelGadget(30,30,30,360,300)
SetWindowLong_(GadgetID(30),#GWL_STYLE,GetWindowLong_(GadgetID(30),#GWL_STYLE) |#TCS_OWNERDRAWFIXED)
RedrawWindow_(GadgetID(30),0,0,7)
ShowWindow_(GadgetID(30),#SW_SHOW)
OriginProc=SetWindowLong_(GetParent_(GadgetID(30)),#GWL_WNDPROC,@tabproc())
For a=0 To 3
AddGadgetItem(30,a,"test" + Str(a))
Next
CloseGadgetList()
EndIf
disablepanelitem(30,2,1)
;- event loop
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
EndSelect
EndIf
Until EventID = #PB_EventCloseWindow
EndIf
End
and the crowd goes wild:::::