CountGadgets(#WindowID)
-
- Addict
- Posts: 1648
- Joined: Mon Sep 20, 2004 3:52 pm
- Contact:
CountGadgets(#WindowID)
Please? I think this would be pretty handy and should be simple to do.
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
-
- Addict
- Posts: 1648
- Joined: Mon Sep 20, 2004 3:52 pm
- Contact:
- Hroudtwolf
- Addict
- Posts: 803
- Joined: Sat Feb 12, 2005 3:35 am
- Location: Germany(Hessen)
- Contact:
-
- Addict
- Posts: 1648
- Joined: Mon Sep 20, 2004 3:52 pm
- Contact:
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.
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.
> 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.
> 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.
"PureBasic won't be object oriented, period" - Fred.
-
- Addict
- Posts: 1648
- Joined: Mon Sep 20, 2004 3:52 pm
- Contact:
...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.
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.
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_?
I basically presented the same arguement you did, but in the end, Fred said nada



I wish you luck actually

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

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_?
-
- Addict
- Posts: 1648
- Joined: Mon Sep 20, 2004 3:52 pm
- Contact:
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
Don't know if this helps, but there's a #PB_Compiler_EnumerationValuedracflamloc 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.
Good programmers don't comment their code. It was hard to write, should be hard to read.
Hmm!
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.
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"
But for static stuff added/setup at runtime, this is the easiest solution.
-
- Addict
- Posts: 1648
- Joined: Mon Sep 20, 2004 3:52 pm
- Contact: