Page 1 of 2
CountGadgets(#WindowID)
Posted: Wed Mar 30, 2005 10:06 pm
by dracflamloc
Please? I think this would be pretty handy and should be simple to do.
Posted: Wed Mar 30, 2005 10:39 pm
by Hroudtwolf
If you use LinkedList to save GadgetIDs what made by #pb_any, you can count it with CountList(LinkedList()) .
Posted: Wed Mar 30, 2005 11:19 pm
by dracflamloc
That's not what I want
I know there are hundreds of ways of working around this. But a function would be a simple and nice feature.
Posted: Thu Mar 31, 2005 12:53 am
by Hroudtwolf
Yes , thats right, of course....
We need more easy commands for PB.
Posted: Thu Mar 31, 2005 1:02 am
by freak
What is the purpose of this command?
I mean, what does it help you to know the number of gadgets on a window?
Posted: Thu Mar 31, 2005 2:17 am
by dracflamloc
the same thing that the list suggested above would let me do. Lets say I want to disable all gadgets on a window...I can either call the disableGadget function once for every #gadget constant or I could just do a loop through.
A better function would be something like "EnumerateGadgets" that returned the ID numbers of every gadget, not just a count. But I figure fred is so busy that a simpler solution would get the okay.
Posted: Thu Mar 31, 2005 2:46 am
by PB
> A better function would be something like "EnumerateGadgets" that
> returned the ID numbers of every gadget, not just a count
If you created the gadgets then you already know the number of them...
I don't see the problem? And if you created them with Enumeration then
it's just a simple matter of doing a For/Next loop to disable them all.
Posted: Thu Mar 31, 2005 3:24 am
by dagcrack
I dont want to bother anyone but I think this lacks of sense.
Theres many other commands I would add before this one if I were in charge. In fact ill let this one at the bottom of the list. as Its senseless!
Posted: Thu Mar 31, 2005 4:26 am
by dracflamloc
...senseless? I think you're senseless for saying that just because you fail to see any reason for it.
Obviously if I created the gadgets as enumeration I could loop through. However theres still no way short of counting up manually how many constants are in that enumeration. And then if you go and add a bunch of new gadgets later on in development after you've already set a loop for one value, you have to go find that loop and change the value it's looping to. The other thing is after you've counted them you could make a "#GadgetCount" constant, which is great but it still requires manual counting of the gadgets when things change.
Also what if gadgets were to be added during runtime instead of being made at startup? There really ought to be a simple and quick function to count up any existing gadgets, or obtain a list of them.
Posted: Thu Mar 31, 2005 4:51 am
by Shannara
I ran into a similar problem when i was dinking around with Hibeko. (visual designer), it could have any number of windows and any number of gadgets on each window .. a royal pain and basically impossible to do it dynamically (compared to static limitations) up until Fred released partial support for #PB_ANY. After that, there are only limits with forced to use constants for menus ...
I basically presented the same arguement you did, but in the end, Fred said nada

I actually consider #PB_ANY the next step up from the archiac constants/enums

But ... To each their own
I wish you luck actually

But Fred's answer to mine is most likely the answer for this. Anyways, I think PB's way the same way I do mine, use #PB_ANY for all (possible) gadgets created, use a linklist (w/ win ID member), and cycle through that. Though it would be easier to do a DisableAllGadgets or some such command ...
Actually in
http://www.is-edu.hcmuns.edu.vn/BoMon/C ... 1/ch02.htm there is an API (I believe) that does just that ... Unfortunately it's in VC

But basically using showwindow_ API i think .. by checking the GetParent_ of each control.
Hmm, now you've made a challenge. Maybe someone (or I) could create a simple lib or some code to do just that .. hrm ... GetWindow_?
Posted: Thu Mar 31, 2005 5:02 am
by dracflamloc
Yea I may look into making the function myself if i get the time.
Posted: Thu Mar 31, 2005 8:11 am
by leo1991
Here it is:
Code: Select all
;
; 31.March 2005
; CountGadgets by leo1991
;
Procedure EnumChildWindowProc(hwnd,*Result.LONG)
*Result\l + 1
ProcedureReturn 1
EndProcedure
Procedure CountGadgets(hwnd)
EnumChildWindows_(hwnd,@EnumChildWindowProc(),@count)
ProcedureReturn count
EndProcedure
hwnd = OpenWindow(0,0,0,640,480,#PB_Window_ScreenCentered|#PB_Window_SystemMenu,"Titel")
CreateGadgetList(hwnd)
For I = 0 To 2
ButtonGadget(#PB_Any,I*150+10,10,140,30,Str(I))
Next
For I = 0 To 6
StringGadget(#PB_Any,10,I*30+50,200,20,Str(Random(2000)))
Next
For I = 0 To 3
CheckBoxGadget(#PB_Any,220,I*30+50,200,20,"möhö"+Str(Random(2000)))
Next
countGadgets.l = CountGadgets(hwnd)
MessageRequester("Muha","I count "+Str(countGadgets)+" gadgets!")
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Posted: Thu Mar 31, 2005 9:52 am
by traumatic
dracflamloc wrote:The other thing is after you've counted them you could make a "#GadgetCount" constant, which is great but it still requires manual counting of the gadgets when things change.
Don't know if this helps, but there's a #PB_Compiler_EnumerationValue
Posted: Fri Apr 01, 2005 10:43 am
by Rescator
Hmm!
Code: Select all
Enumeration
#Bla1 ;this starts at 0
#Bla2
#Bla3
#Bla4
#Bla5
#BlahCount ;this would be #Blah5+1, which would be 5 in this case.
EndEnumeration
Debug Str(#BlahCount)+" Blahs"
If gadgets are added dynamically however, you need a completly differnt way to do all this.
But for static stuff added/setup at runtime, this is the easiest solution.
Posted: Fri Apr 01, 2005 1:42 pm
by dracflamloc
yea. though for enumerations thats a good idea right there for the count.