[Implemented] GetGadgetType

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

[Implemented] GetGadgetType

Post by Num3 »

Getgadgettype(handle), to retrive the gadget type, string, text, combo... etc...

This would be nice to create functions to act on certain types of gadgets...

(Implemented as 'GadgetType()')
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: GetGadgetType

Post by PB »

You could use something like this in the meantime (obviously you'll have to
work out the class names, in advance, for every type of gadget in use):

Code: Select all

Procedure.s GetGadgetType(gadget)
  class$=Space(255) : GetClassName_(GadgetID(gadget),class$,255)
  ProcedureReturn class$
EndProcedure

If OpenWindow(1,300,250,400,200,#PB_Window_SystemMenu,"Window")
  CreateGadgetList(WindowID())
  ButtonGadget(1,20,50,60,25,"Button") : Debug GetGadgetType(1)
  StringGadget(2,20,80,300,20,"String") : Debug GetGadgetType(2)
  Repeat : Until WaitWindowEvent()=#PB_EventCloseWindow
EndIf
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

That's exactly what i need for my code !
I need to make all buttons flat and edit boxes single lined...

There are about 600 of those... So doing it by hand would be... erh... titanic!!!

Thanks!
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> There are about 600 of those

Oh, sorry -- I didn't realise there were that many. But can't you just get
the class names for the gadget types that you're using? You're not using
600 different gadget types, or am I misunderstanding something?
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

I have to parse 600 gadgets and change their look...

If i do it by hand it will take me a very long time...

With this procedure here i just change'em at start with a simple line of code :P

Code: Select all


Procedure.s GetGadgetType(gadget) 
  class$=Space(255) : GetClassName_(GadgetID(gadget),class$,255) 
  ProcedureReturn class$ 
EndProcedure 



Procedure flatgadget(top.l)      

For x=0 To top
 If GetGadgetType(x)="Button"
  style.l=GetWindowLong_(GadgetID(x),#GWL_STYLE)
  SetWindowLong_(GadgetID(x),#GWL_STYLE,style|#BS_FLAT)
 EndIf
 If GetGadgetType(x)="Edit"
  style.l=GetWindowLong_(GadgetID(x),#GWL_STYLE)
  SetWindowLong_(GadgetID(x),#GWL_STYLE,style|#WS_GROUP|#WS_BORDER)
 EndIf
 If GetGadgetType(x)="SysListView32" Or GetGadgetType(x)="SysTreeView32"
  style.l=GetWindowLong_(GadgetID(x),#GWL_STYLE)
  SetWindowLong_(GadgetID(x),#GWL_STYLE,style|#WS_GROUP|#WS_BORDER)
 EndIf
Next

RedrawWindow_(WindowID(),0,0,#RDW_UPDATENOW|#RDW_ERASE|#RDW_INVALIDATE)

EndProcedure
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

Now I understand -- I actually helped you! :D I thought you were saying that
you had 600 different CLASSES of gadgets to check. Glad to be of assistance!

BTW, you should change your For...Next loop to this instead:

Code: Select all

For x=0 To top 
If GetGadgetType(x)="Button" 
  style.l=GetWindowLong_(GadgetID(x),#GWL_STYLE) 
  SetWindowLong_(GadgetID(x),#GWL_STYLE,style|#BS_FLAT) 
ElseIf GetGadgetType(x)="Edit" 
  style.l=GetWindowLong_(GadgetID(x),#GWL_STYLE) 
  SetWindowLong_(GadgetID(x),#GWL_STYLE,style|#WS_GROUP|#WS_BORDER) 
ElseIf GetGadgetType(x)="SysListView32" Or GetGadgetType(x)="SysTreeView32" 
  style.l=GetWindowLong_(GadgetID(x),#GWL_STYLE) 
  SetWindowLong_(GadgetID(x),#GWL_STYLE,style|#WS_GROUP|#WS_BORDER) 
EndIf 
Next
The way you had it, meant that the loop had to perform 3 checks during
the loop, but if you use ElseIf then the checking stops as soon as a match
is found. That is, if the class is Button then the loop won't check for Edit
and SysListView32, thus saving time. Your way would make the loop
check the last two even if Button was matched first (which is pointless).
Post Reply