Gadget Events

Just starting out? Need help? Post your questions and find answers here.
CaptainFrank
User
User
Posts: 16
Joined: Sun Sep 21, 2003 2:20 pm
Location: In front of my Monitor :)

Gadget Events

Post by CaptainFrank »

Hello,

I`m new around here, so please accept my appologies if this has already been discussed to death!

I`m writing a small program to allow me to remotely restart/shutdown computers over my works network.

For the Client sode, I created a small window with three gadgets in it at the moment. Then my program waits for a WindowEvent to happen, when it does this, it then checks which gadgetevent happened. Everything OK so far.

My program then deals with what ever it was supposed to do (eg sent the shutdown message) and then returns to the main loop. This is where the problem starts.

My program then checks for a WindowEvent then a GadgetEvent, then does the same thing again, this happens over and over, until I terminate the program.

It seems that it still thinks an event has happened (which it has), but I`ve alreay dealt with it. How do I clear the Events?

Best Regards,


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

Re: Gadget Events

Post by PB »

> How do I clear the Events?

Are you using WaitWindowEvent() or WindowEvent() ?

In any event (LOL!) you can clear pending events by doing this:

Code: Select all

While WindowEvent() : Wend
CaptainFrank
User
User
Posts: 16
Joined: Sun Sep 21, 2003 2:20 pm
Location: In front of my Monitor :)

Re: Gadget Events

Post by CaptainFrank »

PB wrote:> How do I clear the Events?

Are you using WaitWindowEvent() or WindowEvent() ?
Hi,

I`m doing it like this :

Code: Select all

Repeat
WaitWindowEvent()
       Select EventGadgetID()
               Case 1
               Case 2 etc.....
I`m using the Select - Case to determine which gadget has been pressed.
Your While - Went worked fine for the WindowEvent however, when I move the mouse back over the window (causing a window event) the EventGadgetID() is still set to the old value and therefore triggers the same button again, even though I haven`t pressed any buttons.

I tried a while - wend for the EventGadgetID() but it just goes round in an infinate loop.

Best Regards,


Frank.
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

you have to check the result of WaitWindowEvent()
if it returns #PB_EventGadget, then check for the gadget event.

EventGadgetID() will return the same value until another
#PB_EventGadget is returned from WaitWindowEvent()

like this:

Code: Select all

Repeat
  Event.l = WaitWindowEvent()
  If Event = #PB_EventGadget
    Select EventGadgetID()
      ; ...
    EndSelect
  Endif
Until Event = #PB_EventCloseWindow
This code will process the Gadget events correctly, and exit, as soon
as the user pressed the 'X' button of the window. (use #PB_Window_SystemMenu
at OpenWindow() to make the 'X' buttton appear.

Timo
quidquid Latine dictum sit altum videtur
CaptainFrank
User
User
Posts: 16
Joined: Sun Sep 21, 2003 2:20 pm
Location: In front of my Monitor :)

Post by CaptainFrank »

Hi Freak,
freak wrote:you have to check the result of WaitWindowEvent()
if it returns #PB_EventGadget, then check for the gadget event.

EventGadgetID() will return the same value until another
#PB_EventGadget is returned from WaitWindowEvent()
Thanks,

Thats sorted it now.

Best Regards,


Frank.
Post Reply