Help with gadget extra storage space.
Help with gadget extra storage space.
Isn’t it infuriating when you have x,000s of lines of working code but can’t get a few lines to work at all, no matter how many times you look at them!
I just need to store some information with a canvas gadget, a bit more then is possible with SetGadgetData.
The following is basically what I am trying to do.
SetClassLong_(GadgetID(canvisgadget),#GCL_CBWNDEXTRA,4)
SetWindowLong_(GadgetID(canvisgadget),0,99)
Debug GetWindowLong_(GadgetID(canvisgadget),0)
Does a canvas gadget use this storage space for it’s own purpose?
Thanks in anticipation.
I just need to store some information with a canvas gadget, a bit more then is possible with SetGadgetData.
The following is basically what I am trying to do.
SetClassLong_(GadgetID(canvisgadget),#GCL_CBWNDEXTRA,4)
SetWindowLong_(GadgetID(canvisgadget),0,99)
Debug GetWindowLong_(GadgetID(canvisgadget),0)
Does a canvas gadget use this storage space for it’s own purpose?
Thanks in anticipation.
Re: Help with gadget extra storage space.
You can store many of infos in GadgetData
The only limit is the memory of your computer.
Greetings - Thomas
Code: Select all
Structure mycanvasdata
a.i
b.i
c.s
d.d
; ...
EndStructure
Global *cdata.mycanvasdata = AllocateMemory(SizeOf(mycanvasdata))
*cdata\a = 100
*cdata\b = 200
*cdata\c = "Hello World"
*cdata\d = #PI
If OpenWindow(0, 0, 0, 220, 220, "CanvasGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 200, 160)
SetGadgetData(0, *cdata)
ButtonGadget(1, 65, 180, 100, 20, "show canvasdata")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0
If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
If StartDrawing(CanvasOutput(0))
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
StopDrawing()
EndIf
EndIf
EndIf
If Event = #PB_Event_Gadget And EventGadget() = 1
*a.mycanvasdata = GetGadgetData(0)
Debug *a\a
Debug *a\b
Debug *a\c
Debug *a\d
EndIf
Until Event = #PB_Event_CloseWindow
EndIfGreetings - Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

-
IdeasVacuum
- Always Here

- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Help with gadget extra storage space.
I don't know the answer to your question, but you should use SetWindowLongPtr_, GetWindowLongPtr_, SetClassLongPtr_
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Help with gadget extra storage space.
or you can use
So you can use different values with different keynames...
Code: Select all
; Set Data
SetProp_(GadgetID(GadgetNo), Keyname.s, Value)
;Get Data
Value = GetProp_(GadgetID(GadgetNo), KeyName.s)
Code: Select all
SetProp_(GadgetID(#Canvas), "MouseX", Value) Re: Help with gadget extra storage space.
Thanks for the replies.
The canvas gadgets (and there could be many) are allocated dynamically so I don’t want to have to maintain a separate array to store the associated data. Storing the data with the gadget is the neatest solution, but only if I can get it to work!
Any other ideas?
Regards.
The canvas gadgets (and there could be many) are allocated dynamically so I don’t want to have to maintain a separate array to store the associated data. Storing the data with the gadget is the neatest solution, but only if I can get it to work!
Any other ideas?
Regards.
Re: Help with gadget extra storage space.
Bisonte wrote:or you can useSo you can use different values with different keynames...Code: Select all
; Set Data SetProp_(GadgetID(GadgetNo), Keyname.s, Value) ;Get Data Value = GetProp_(GadgetID(GadgetNo), KeyName.s)
Code: Select all
SetProp_(GadgetID(#Canvas), "MouseX", Value)
Ya that worked!!!!
Cheers!!
Re: Help with gadget extra storage space.
But you have to RemoveProp_() before FreeGadget!
Better simple use SetGadgetData with pointer to a structured var Or use a Map
Better simple use SetGadgetData with pointer to a structured var Or use a Map
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: Help with gadget extra storage space.
If you already create your gadgets dynamically, just link your data to any gadgetid's you like and don't bother with setproperties or setgadgetdata() stuff. 
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Help with gadget extra storage space.
You should really use SetGadgetData() here.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Help with gadget extra storage space.
SetGadgetData() with a structured pointer to allocated memory, I fully recommend the approach posted by ts-soft. SetProp_() / RemoveProp_() is best handled in a callback and there's just no need for this. Also, maybe you don't plan to make it crossplatform at all right now, but you might change your mind next year and then all the Prop stuff would have to be completely rewritten. The ts-soft code is good to go.
BERESHEIT


