Posted: Sat Feb 17, 2007 6:40 pm
You're most welcome, thanks for the kind words. I like to use window properties to associate all the vars and handles with the current instance of the gadget. It is much cleaner and simpler than using structured lists, you just have to remember that you are responsible for removing the properties at WM_DESTROY, as Windows won't do it for you. Using this method, no globals or shared vars are needed at all:
Another way is to use:
and now all the vars are available with:
And you don't have to iterate a list looking for your instance-specific data.
PureBasic in v4 leaves this field open for us to use for all gadgets except the WebGadget, see here:
http://www.purebasic.fr/english/viewtopic.php?t=23354
Code: Select all
Procedure SubClass(hwnd, msg, wparam, lparam)
oldproc = GetProp_(hwnd, "oldproc")
gadget2 = GetProp_(hwnd, "gadget2")
var1 = GetProp_(hwnd, "var1")
; Now all the vars are known and specific to this instance only
Select msg
Case ..
Case ..
Case #WM_DESTROY
RemoveProp_(hwnd, "oldproc")
RemoveProp_(hwnd, "var1")
RemoveProp_(hwnd, "gadget2")
EndSelect
EndProcedure
Procedure MyGadget(GadgetNumber, x, y, etc..)
gadget1 = StringGadget(GadgetNumber, ... etc)
gadget2 = CreateWindowEx_( arguments etc..)
var1 = animportantvalue
oldproc = SetWindowLong_( set up the subclass)
; associate all vars and handles with the instance
SetProp_(gadget1, "oldproc", oldproc)
SetProp_(gadget1, "gadget2", gadget2)
SetProp_(gadget1, "var1", var1)
ProcedureReturn GadgetNumber
EndProcedure
Code: Select all
*this = AllocateMemory(SizeOf(MyStruct))
; write your vars
SetWindowLong_(hwnd, #GWL_USERDATA, *this)
Code: Select all
*this.MyStruct = GetWindowLong_(hwnd, #GWL_USERDATA)
var1 = *this\var1
PureBasic in v4 leaves this field open for us to use for all gadgets except the WebGadget, see here:
http://www.purebasic.fr/english/viewtopic.php?t=23354