Why WaitWindowEvent() w/o timeout sends #PB_Event_None events

Just starting out? Need help? Post your questions and find answers here.
Axolotl
Addict
Addict
Posts: 837
Joined: Wed Dec 31, 2008 3:36 pm

Why WaitWindowEvent() w/o timeout sends #PB_Event_None events

Post by Axolotl »

Hi folks,

I am a bit surprised about these #PB_Event_None events.
It doesn't match the description in the help, does it?

I copied the following text from help:
WaitWindowEvent()
Wait until an event occurs. It's the same function as WindowEvent() but locks the program execution, which is very important in a multitasking environment.
and
Timeout (optional) => The timeout (in milliseconds) which causes the function to return if no events are occurring. If no timeout is specified, it will wait infinitely until an event occurs.
And here is the small code to show the reason for my confusion......

Code: Select all

EnableExplicit 

Macro Trace(Message) 
  AddGadgetItem(1, -1, Message) 
  Debug ">> " + Message 
EndMacro 

If OpenWindow(1, 0, 0, 400, 200, "Window Caption", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
  ListViewGadget(1, 0, 0, 400, 200)  ; <== shows the messages 

  Repeat  ; .. main loop 
    Select WaitWindowEvent()   ; <== no Timeout defined, as far as I can see (?)  
      Case #PB_Event_None 
        Trace("None Window Event w/o timeout ?")   ; <== at program start this is received six times. (?) 

      Case #PB_Event_CloseWindow 
        Break ; done with main loop 
    EndSelect
  ForEver 
EndIf 
TIA for every kind of enlightenment.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
mk-soft
Always Here
Always Here
Posts: 6246
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Why WaitWindowEvent() w/o timeout sends #PB_Event_None events

Post by mk-soft »

It looks like some uMsg will be set to event zero when handed over.

Code: Select all

EnableExplicit 

Macro Trace(Message) 
  AddGadgetItem(1, -1, Message) 
  Debug ">> " + Message 
EndMacro 

Procedure WinCallback(hWnd, uMsg, wParam, lParam) 
  ; Windows füllt die Parameter automatisch, welche wir im Callback verwenden...
  
  If IsGadget(1)
    Trace("WinCB uMsg: " + uMsg)  
  EndIf
  Select uMsg
    ;
  EndSelect
  
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

Define Event
If OpenWindow(1, 0, 0, 400, 200, "Window Caption", #PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
  ListViewGadget(1, 0, 0, 400, 200)  ; <== shows the messages 
  
  SetWindowCallback(@WinCallback())
  
  Repeat  ; .. main loop 
    Event = WaitWindowEvent()   ; <== no Timeout defined, as far as I can see (?)  
    Trace("Event: " + Event)
    Select Event
      Case #PB_Event_None 
        Trace("None Window Event w/o timeout ? ")   ; <== at program start this is received six times. (?) 

      Case #PB_Event_CloseWindow 
        Break ; done with main loop 
        
      Default
        
    EndSelect
  ForEver 
EndIf 
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Axolotl
Addict
Addict
Posts: 837
Joined: Wed Dec 31, 2008 3:36 pm

Re: Why WaitWindowEvent() w/o timeout sends #PB_Event_None events

Post by Axolotl »

Thanks for the answer.
This is still confusing for me, it seems to be the same with #PB_Event_None only at the beginning.
It is also interesting that windows messages and events are not synchronized (do not occur in pairs). This means that there are messages without events and vice versa.
Is that a problem: Nope, probably not, but since I always like to get to the bottom of things.......

Code: Select all

EnableExplicit 

Macro Trace(Message) 
  If IsGadget(1) : AddGadgetItem(1, -1, Message) : EndIf 
  Debug Message 
EndMacro 

Procedure WinCallback(hWnd, uMsg, wParam, lParam) 
  Trace("CB: uMsg  = " + uMsg) 
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

Define Event
If OpenWindow(1, 0, 0, 400, 200, "Window Caption", #PB_Window_SystemMenu|#PB_Window_ScreenCentered);|#PB_Window_NoGadgets) 
  ; ListViewGadget(1, 0, 0, 400, 200)  ; <== shows the messages | commented out 

  SetWindowCallback(@WinCallback())
  
  Repeat  ; .. main loop 
    Event = WaitWindowEvent()   ; <== no Timeout defined, as far as I can see (?)  
    Trace("ML: Event = " + Event) 
    Select Event
      Case #PB_Event_None 
        Trace("ML: None Window Event w/o timeout ? ")   ; <== at program start this is received six times. (?) 
      Case #PB_Event_CloseWindow 
        Break ; done with main loop 
    EndSelect
    Trace("") ; empty separator line 
  ForEver 
EndIf 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
PBJim
Enthusiast
Enthusiast
Posts: 296
Joined: Fri Jan 19, 2024 11:56 pm

Re: Why WaitWindowEvent() w/o timeout sends #PB_Event_None events

Post by PBJim »

I feel that it is to be expected, Axolotl, the reason being that the drawing of a window's graphical elements requires cycling of the event loop — not just on one iteration.

This is observed easily if you create a window containing many gadgets and deliberately slow the event loop down with a 1-2 sec. delay. You'll see that the gadgets appear in clusters of just a few at a time, therefore requiring several iterations of the event loop before drawing is complete.

So the documentation on #PB_Event_None is correct because as far as programme logic is concerned, no event took place.
Axolotl
Addict
Addict
Posts: 837
Joined: Wed Dec 31, 2008 3:36 pm

Re: Why WaitWindowEvent() w/o timeout sends #PB_Event_None events

Post by Axolotl »

Thanks for your reply.
In my opinion, I already understand the basic functionality of windows messages very well. Sometimes I just have a different opinion.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
User avatar
mk-soft
Always Here
Always Here
Posts: 6246
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Why WaitWindowEvent() w/o timeout sends #PB_Event_None events

Post by mk-soft »

Microsoft also has a different opinion for most. Unfortunately, we have to live with that. :mrgreen:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply