GadgetConstant() and a little api help.

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

GadgetConstant() and a little api help.

Post by GreenGiant »

Just two little requests. Neither of them are very major problems, but they are things that have caused me a bit of annoyance at various times.
Firstly, I'd quite like to see the command GadgetConstant(gadgetid) introduced. Basically something that did the exact opposite of GadgetID(), i.e. gave me the PB constant number of a system handle to a gadget. I just sometimes find that I've been using api commands and I'm left with the api handle to a gadget and want to use PB commands. The only way round this I've found is to manually store the handle to each gadget and compare them all to find out the PB number of the gadget. It works, but I think an inbuilt command would be more useful. Maybe returning -1 if the handle given wasn't a PB created gadget?
Also, I have no idea how extensive this is, but I've noticed that some api commands have been messed around with (maybe just a couple, if so its not so bad). But I noticed it tonight when I tried to use

Code: Select all

ChildWindowFromPoint_(hWnd,@p.POINT)

and was told I had the incorrect number of parameters. Then I vaguely remembered reading something about actually having to use

Code: Select all

ChildWindowFromPoint_(hWnd,x,y)
which was no problem for me to use once I'd realised that. I do think though that it'd be very helpful if there was some sort of reference to the fact that the paramaters weren't passed in a standard way, or at the very least if the parameters in the status bar at the bottom informed you of the change.
Anyway two pretty minor requests, nothing too major :)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: GadgetConstant() and a little api help.

Post by PB »

> I'd quite like to see the command GadgetConstant(gadgetid) introduced.
> Basically something that did the exact opposite of GadgetID(), i.e. gave
> me the PB constant number of a system handle to a gadget.

You can already do this quite easily, like so:

#bg=1 : bg=ButtonGadget(#bg,x,y,w,h,"button")

In this example, #bg is the PureBasic gadget number, and bg is the handle of it.
This means you can pick and choose which way you want to reference the gadget
in the rest of your code (eg. by number or handle, it's now up to you). Easy! :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post by GreenGiant »

I didn't really mean like that. I mean say I've used EnumChildWindows_() (just an example) and I'm left with the api hWnd of the gadget. Now say I want to use SetGadgetState() on the gadget I've just found. Currently I'd do something like have an array set up like this

Code: Select all

Dim Handles(NumberOfGadgets)

For temp=0 To NumberOfGadgets
  Handles(temp)=GadgetID(temp)
Next

then I'd use something like this to use SetGadgetState()

Code: Select all

GadgethWnd ;got via some api call
GadgetID=-1

For temp=0 To NumberOfGadgets
  If Handles(temp)=GadgethWnd
    GadgetID=temp
  EndIf
Next

If GadgetID<>-1
  SetGadgetState(GadgetID,1)
EndIf
Now that works, but I think the following code would be much simpler.

Code: Select all

GadgethWnd ;got via some api call
GadgetID=GadgetConstant(GadgethWnd)

If GadgetID<>-1
  SetGadgetState(GadgetID,1)
EndIf
I just think it would be a much nicer way to deal with this sort of thing.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> GadgethWnd ;got via some api call

Looks like you're trying to get the gadget handles of another app, instead of
your own app? Is that right? If so, you can't change the properties of those
gadgets with PureBasic's gadget commands. I don't understand what you're
trying to do. Changing third-party gadgets in other apps needs API calls, and
I assume that's what you're trying to do because of EnumChildWindows_() ?
If not, why would you need to use EnumChildWindows_() on your own app?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post by GreenGiant »

I was referring to my own app, and EnumChildWindows was only an example. Its not something I do generally use on my own app. But I do sometimes use api commands which leave me with the hWnd of my gadget (in my own app) and I then want to use a PB command on them. Here's the thread that reminded me of both of these things, maybe this will clear things up a bit viewtopic.php?t=12579&highlight=identify
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Until we get a native PB function, can you use the API GetDlgCtrlID_() function :?:

Code: Select all

#Button_0 = 10
#Button_1 = 99

If OpenWindow(0,0,0,400,100,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"") And CreateGadgetList(WindowID(0))
  
  ButtonGadget(#Button_0, 10, 10, 380, 20, "Who am I?")
  ButtonGadget(#Button_1, 10, 50, 380, 20, "Who am I?")
 
  Repeat 
    Event=WaitWindowEvent() 
     
    If Event=#PB_Event_CloseWindow 
      quit=1 
    EndIf 
    
    If Event = #PB_Event_Gadget
      hGadget = GadgetID(EventGadgetID()); get the gadget handle used by API
      buttonID = GetDlgCtrlID_(hGadget); get the control ID (PB Constant#) using the API handle
      SetGadgetText(buttonID, "My PB constant ID is " + Str(buttonID) + "    My API handle is " + Str(hGadget))
    EndIf 
    
  Until quit 
EndIf
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post by GreenGiant »

Thanks Sparkie, that's exactly what I was looking for :) . If I'd seen that api before I wouldnt have made the request. I didn't realise that the constants were in any way related to the api control that the gadget used, I assumed they were something PB just introduced to make life easier. Thanks again, one more step towards understanding the PB and the api :)
Post Reply