PureBasic allows you to create your own gadgets through a special type of user libraries, which have the following common characteristics:
One exported function which creates the gadget.
Within that function, the gadget is registered using a function exported by the GadgetExtension include file. A structure with the addresses to the gadget functions that your gadget handles must be passed using that function:
Structure PB_GadgetVT GadgetType.l SizeOf.l GadgetCallback.i FreeGadget.i GetGadgetState.i SetGadgetState.i GetGadgetText.i SetGadgetText.i AddGadgetItem2.i AddGadgetItem3.i RemoveGadgetItem.i ClearGadgetItemList.i ResizeGadget.i CountGadgetItems.i GetGadgetItemState.i SetGadgetItemState.i GetGadgetItemText.i SetGadgetItemText.i OpenGadgetList2.i GadgetX.i GadgetY.i GadgetWidth.i GadgetHeight.i HideGadget.i AddGadgetColumn.i RemoveGadgetColumn.i GetGadgetAttribute.i SetGadgetAttribute.i GetGadgetItemAttribute2.i SetGadgetItemAttribute2.i SetGadgetColor.i GetGadgetColor.i SetGadgetItemColor2.i GetGadgetItemColor2.i SetGadgetItemData.i GetGadgetItemData.i EndStructure
These function handlers allow you to provide custom actions for the built-in PB functions by the same name. If a member of this structure is set to 0, PB will use it's standard function.
To allow creating gadgets with TailBite and without having to use inline ASM, a helper funcion,
TB_RegisterGadget() is provided and installed with TailBite. (you just need to add an IncludeFile to the TB_GadgetExtension.pb file (it's in TailBite Folder/Helper Libraries)
But the best way to understand how this works is having a look at the included sample 'MyPaintBoxGadget'. There you'll see that, after creating the gadget or control, you call
TB_RegisterGadget(ID, hWnd, @VT), 'ID' being the gadget index (#Gadget) used (which is given usually as first argument when your gadget creation function is called), 'hWnd' the Windows handle of your gadget or control and '@VT' the pointer to the (already filled)
PB_GadgetVT structure. If your gadget doesn't process any of these functions, the corresponding member must be reset to 0 before passing the structure.
You should return what TB_RegisterGadget returns, in case the programmer uses #PB_Any
Please note that since the GadgetExtension lib has been re-added, the function names have changed.