CountGadgets(#WindowID)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

CountGadgets(#WindowID)

Post by dracflamloc »

Please? I think this would be pretty handy and should be simple to do.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

If you use LinkedList to save GadgetIDs what made by #pb_any, you can count it with CountList(LinkedList()) .
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post 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.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

Yes , thats right, of course....
We need more easy commands for PB.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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?
quidquid Latine dictum sit altum videtur
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post 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.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post 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!
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post 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.
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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_?
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

Yea I may look into making the function myself if i get the time.
leo1991
New User
New User
Posts: 7
Joined: Tue Feb 24, 2004 7:25 pm

Post by leo1991 »

Here it is: :lol: :lol: :lol:

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
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post 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
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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.
dracflamloc
Addict
Addict
Posts: 1648
Joined: Mon Sep 20, 2004 3:52 pm
Contact:

Post by dracflamloc »

yea. though for enumerations thats a good idea right there for the count.
Post Reply