You can register your own gadget, for example API-Controls, Controls from ext. Libraries and so on.
The source uses the infos from the actual SDK.
In the moment only for windows!
Code: Select all
;======================================================================
; Module: OwnGadget.pbi
;
; Author: Thomas (ts-soft) Schulz
; based on Code by edel (Hallodri)
; Date: Jul 08, 2013
; Version: 0.8
; Target Compiler: PureBasic 5.2+
; Target OS: in the moment only windows
; License: Free, unrestricted, no warranty whatsoever
; Use at your own risk
;======================================================================
; History:
; 0.7
; removed GetGadgetParent() (UseGadgetList(0) do the same)
; put RegisterGadget() to public
; 0.8
; fixed RegisterGadget
DeclareModule OwnGadget
Structure 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
GetRequiredSize.i
SetActiveGadget.i
GetGadgetFont.i
SetGadgetFont.i
SetGadgetItemImage.i
EndStructure
Declare RegisterGadget(ID.i, hWnd.i, *vt.GadgetVT = 0)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Declare CreateGadget(ID.i, ClassName.s, Text.s, Style.l, x.i, y.i, w.i, h.i, ExStyle.l = 0, *vt.GadgetVT = 0)
CompilerEndSelect
EndDeclareModule
Module OwnGadget
EnableExplicit
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Import ""
CompilerElse
ImportC ""
CompilerEndIf
PB_Object_GetOrAllocateID(Objects.i, ID.i)
PB_Gadget_RegisterGadget(ID.i, *Gadget, hWnd.i, *GadgetVT)
PB_Gadget_Objects.i
EndImport
Structure Gadget
Gadget.i
*vt.GadgetVT
UserData.i
OldCallback.i
Daten.i[4]
EndStructure
Procedure RegisterGadget(ID.i, hWnd.i, *vt.GadgetVT = 0)
Protected *Gadget.Gadget
Protected *vttmp.GadgetVT = AllocateMemory(SizeOf(GadgetVT))
If Not *vttmp : ProcedureReturn #False : EndIf
If Not hWnd Or ID < -1
ProcedureReturn #False
EndIf
If *vt
CopyMemory(*vt, *vttmp, SizeOf(GadgetVT))
*vttmp\SizeOf = SizeOf(GadgetVT)
EndIf
*Gadget = PB_Object_GetOrAllocateID(PB_Gadget_Objects, ID)
ProcedureReturn PB_Gadget_RegisterGadget(ID, *Gadget, hWnd, *vttmp)
EndProcedure
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Procedure CreateGadget(ID.i, ClassName.s, Text.s, Style.l, x.i, y.i, w.i, h.i, ExStyle.l = 0, *vt.GadgetVT = 0)
Protected hWnd.i, Parent.i = UseGadgetList(0), hInstance.i = GetModuleHandle_(0)
hWnd = CreateWindowEx_(ExStyle, ClassName, Text, Style, x, y, w, h, Parent, 0, hInstance, 0)
SendMessage_(hWnd, #WM_SETFONT, GetGadgetFont(#PB_Default), 1)
If Not hWnd : ProcedureReturn #False : EndIf
ProcedureReturn RegisterGadget(ID, hWnd, *vt)
EndProcedure
CompilerEndSelect
EndModule
CompilerIf #PB_Compiler_IsMainFile
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Enumeration
#btn1
#btn2
EndEnumeration
Procedure MyButton(Gadget, x, y, width, height, Text.s)
ProcedureReturn OwnGadget::CreateGadget(Gadget, "Button", Text, #WS_CHILD | #WS_VISIBLE, x, y, width, height)
EndProcedure
Procedure btn1_event()
Debug "Okay pressed"
EndProcedure
Procedure Btn3_event()
End
EndProcedure
Define btn3
OpenWindow(0, #PB_Ignore, #PB_Ignore, 190, 100, "example")
MyButton(#btn1, 10, 10, 80, 25, "Okay")
BindGadgetEvent(#btn1, @btn1_event())
MyButton(#btn2, 100, 10, 80, 25, "")
SetGadgetText(#btn2, "Cancel")
btn3 = MyButton(#PB_Any, 60, 60, 80, 25, "End")
GadgetToolTip(btn3, "Close Example!")
BindGadgetEvent(btn3, @Btn3_event())
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow : Break
Case #PB_Event_Gadget
Select EventGadget()
Case #btn2
Debug "Cancel pressed"
EndSelect
EndSelect
ForEver
CompilerEndSelect
CompilerEndIf