WaitWindowEvent()

Just starting out? Need help? Post your questions and find answers here.
CaddMan
User
User
Posts: 21
Joined: Sat Jul 10, 2004 8:05 pm
Location: USA (East Coast)

WaitWindowEvent()

Post by CaddMan »

Hello,
Can anyone tell me if I am using this correctly

Thanks
Ken

Code: Select all

;Capture mousedown and abort events
  CallFunction (0,"VCSetAlertAppDll",@iError,"Test","DrawLine",ALERT_APP_UTOOL_MOUSEDOWN)
    
;User tool prompt 
  CallFunction (1,"VCSetUserTool",2,"DrawLine","Enter lower left corner")
  CallFunction (1,"VCSetPrompt",1,"Enter lower right corner")
  
  
  Repeat 
    WaitWindowEvent() 
    Event = EventType()
  If Event = #PB_EventType_LeftClick
;Get 1st mouse down point  
  ;CallFunction (0,"VCGetUserToolLBDown",@iError,StartLine())
  MessageRequester("Test", "MouseClick1", 0)
  Else  
    Delay(1)  ; No event, let the others apps get some CPU time too ! 
  EndIf 
  Until ToolState  = 10 
  
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post by fsw »

NO :!:
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: WaitWindowEvent()

Post by fsw »

It should more look like:

Code: Select all

;Capture mousedown and abort events
  CallFunction (0,"VCSetAlertAppDll",@iError,"Test","DrawLine",ALERT_APP_UTOOL_MOUSEDOWN)
   
;User tool prompt
  CallFunction (1,"VCSetUserTool",2,"DrawLine","Enter lower left corner")
  CallFunction (1,"VCSetPrompt",1,"Enter lower right corner")
 
 OpenWindow(0,0,0,230,90,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Event handling example...") 


  Repeat
    Event = WaitWindowEvent()
    ; EventType() is only used with Gadgets...
    ; #PB_EventType_LeftClick is only used with Gadgets...

    If Event = #WM_LBUTTONDOWN ;this is a WinAPI constant
      ;Get 1st mouse down point 
      ;CallFunction (0,"VCGetUserToolLBDown",@iError,StartLine())
      MessageRequester("Test", "MouseClick1", 0)
    Else 
      Delay(1)  ; No event, let the others apps get some CPU time too !
    EndIf
  Until EventID = #PB_Event_CloseWindow
  ; don't know what this should be -> Until ToolState  = 10 
hope this helps a bit...
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

No need for

Code: Select all

Delay(1)
in the updated code when using

Code: Select all

WaitWindowEvent()
because this command waits for an event then continues the main loop. If this was used

Code: Select all

WindowEvent()
the the delay would be necessary because this is nothing to halt the program taking 100% cpu time.
--Kale

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

Post by PB »

> If this was used
> WindowEvent()
> the the delay would be necessary because this is nothing to halt the
> program taking 100% cpu time

And you should only use Delay(1) if the result of WindowEvent() = 0,
otherwise it'll slow down the updating of all gadgets on your window.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
CaddMan
User
User
Posts: 21
Joined: Sat Jul 10, 2004 8:05 pm
Location: USA (East Coast)

Post by CaddMan »

Thanks all,

This is good info. I will try it out as soon as I can & let you know

Ken
Post Reply