Mouse "UP" no longer works in 5.11

Just starting out? Need help? Post your questions and find answers here.
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Mouse "UP" no longer works in 5.11

Post by offsides »

I have a small ap that worked fine under PB 5.0 but doesn't work compiled under 5.11. The culprit appears to be "#WM_LBUTTONUP" which is no longer detected. "#WM_RBUTTONUP" isn't either.

Did I miss a change?

Thanks,
Bill

Code: Select all

; No button up detection

If OpenWindow(0,0,0,200,200,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  Repeat
    
    eventid=WaitWindowEvent()
    Select eventid
        
      Case #PB_Event_CloseWindow
        quit=1
        
      Case #WM_LBUTTONDOWN
        Debug "Left button Down"
        
      Case #WM_LBUTTONUP
        Debug "Left button up"
        
      Case #WM_RBUTTONDOWN
        Debug "Right button down"
        
      Case #WM_RBUTTONUP  
        Debug "Right button up"
        
    EndSelect
    
  Until quit
EndIf
PB 5.72 (32-bit) on Win 10.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Mouse "UP" no longer works in 5.11

Post by luis »

http://www.purebasic.fr/english/viewtop ... 13&t=53112

(Wait)WindowEvent() was never documented suggesting it can be used to retrieve Windows messages.
It works but can stop to do so for some messages at any moment as you just discovered.
Better to use a callback (that's the "clean" way) or just switch to the new native PB message in your case if you prefer to do so.
"Have you tried turning it off and on again ?"
A little PureBasic review
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: Mouse "UP" no longer works in 5.11

Post by offsides »

Thanks for the quick reply, Luis. Much appreciated.

Bill
PB 5.72 (32-bit) on Win 10.
eJan
Enthusiast
Enthusiast
Posts: 366
Joined: Sun May 21, 2006 11:22 pm
Location: Sankt Veit am Flaum

Re: Mouse "UP" no longer works in 5.11

Post by eJan »

I have replaced #WM_LBUTTONUP with #PB_Event_LeftClick, which does the same.
Only in some cases i use both: #PB_Event_LeftClick, #WM_LBUTTONUP where i have to receive events from various gadgets which doesn't accept #PB_Event_LeftClick.
Image
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: Mouse "UP" no longer works in 5.11

Post by offsides »

If I understand Luis' answer, and the link he provided, any use of the #WM messages from (Wait)WindowEvent() is asking for trouble. The frustrating part of this is that these messages have been used for years and examples abound throughout these forums. Documented or not, they worked and became part of the code base we learn PB from. Now, some work, some don't.

Bill
PB 5.72 (32-bit) on Win 10.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Mouse "UP" no longer works in 5.11

Post by MachineCode »

offsides wrote:Documented or not, they worked and became part of the code base we learn PB from. Now, some work, some don't.
The #WM messages were NEVER part of the official documentation, and both Fred and Freak have warned us in these forums, over and over, NOT to rely on them in future. For those of us who took the risk, that's their choice. (Including myself, mind you).
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Mouse "UP" no longer works in 5.11

Post by IdeasVacuum »

The #WM messages were NEVER part of the official documentation, and both Fred and Freak have warned us in these forums, over and over, NOT to rely on them in future. For those of us who took the risk, that's their choice. (Including myself, mind you).
Well, I think the note on the first page of the documentation "The Win32 API is fully supported as if they were BASIC keywords" does suggest #WM messages are supported - that might not be the intention of course.

Bill (offsides) is correct in his observation of their use - there are many code examples on the forum, some posted by PB power Users, using the #WM messages.

I haven't seen a warning about their use by Fred/Freak - perhaps that should be in the documentation.

Edit: Strange thing, can't get #WM_LBUTTONUP to work in your example but I just found it used in one of my apps, similar loop, works fine :shock: I'm going to move that code into a CallBack though.
Last edited by IdeasVacuum on Sat Mar 30, 2013 3:37 pm, edited 1 time in total.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Mouse "UP" no longer works in 5.11

Post by MachineCode »

API commands are different to Windows messages. (Disclaimer: I;m drunk right now)./
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Mouse "UP" no longer works in 5.11

Post by IdeasVacuum »

API commands are different to Windows messages. (Disclaimer: I;m drunk right now)./
A newbie is not necessarily going to 'get' that, they will see "The Win32 API is fully supported" - from there, it's reasonable to assume that Windows messages are supported, and indeed they are - but not necessarily with WaitWindowEvent().
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Mouse "UP" no longer works in 5.11

Post by luis »

offsides wrote:Documented or not, they worked and became part of the code base we learn PB from. Now, some work, some don't.
For some the advantage compared to the callback (apart less code) it's you can process both #PB_Events and #WM_* messages easily in the same loop.
Keep in mind that now, with the new PostEvent() command, you can use the "clean" callback method and still process the messages in the PB event loop, if you choose to do so.

At least that's my take, I haven't experimented with PostEvent() until now :)

Example:

Code: Select all

Enumeration 
 #My_Event_LeftClick_Down = #PB_Event_FirstCustomValue
 #My_Event_RightClick_Down 
EndEnumeration

Procedure wc (hWnd, uMsg, wParam, lParam)   
 Select uMsg
    Case #WM_LBUTTONDOWN
        PostEvent(#My_Event_LeftClick_Down)
    Case #WM_RBUTTONDOWN
        PostEvent(#My_Event_RightClick_Down)
 EndSelect     

 ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure


If OpenWindow(0,0,0,200,200,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
 
 SetWindowCallback(@wc())
 
 Repeat
   
    eventid = WaitWindowEvent()
    
    Select eventid
       
      Case #PB_Event_CloseWindow
        quit=1
       
      Case #My_Event_LeftClick_Down
        Debug "Left button Down"
       
      Case #PB_Event_LeftClick
        Debug "Left button up"
       
      Case #My_Event_RightClick_Down
        Debug "Right button down"
       
      Case #PB_Event_RightClick
        Debug "Right button up"
       
    EndSelect
   
 Until quit
EndIf
Obviously in this case you get only the message/event type and not the associated lParam / wParam, but if needed they can always be squeezed in the Data param of PostEvent(). This is ok if you just want to use them in readonly mode. If you have to block the message or do other tricky things the right place it's still the callback.

So you have many choices:

use the undocumented #WM_ returned by (Wait)WindowEvent() and possibly the undocumented EventlParam() / EventWParam()

use the SetWindowCallback() and process only the #WM_ messages there (the #PB_Events still in the PB loop)

use the SetWindowCallback() and forward the #WM_ messages you want to process as PB events through PostEvent() (like in the above example) when it's easier / more comfortable to do so.

Hope this helps.
"Have you tried turning it off and on again ?"
A little PureBasic review
offsides
Enthusiast
Enthusiast
Posts: 103
Joined: Sun May 01, 2011 3:09 am
Location: Northern California

Re: Mouse "UP" no longer works in 5.11

Post by offsides »

Hope this helps.
Luis, indeed it does. Thanks.

I suppose what we're seeing here is, as PB evolves and more functions are added, the new functions can interfere with existing functionality. When the existing functionality is "undocumented", well, sorry...

Maybe this explains why PB now explicitly prohibits all in-line boolean operations. In many basics of yore (TRSDOS, GWBasic, QBX(BC7), etc., such as (ie. test = (a<b<c)) was built in. PB has Bool(), but it won't work on my example.

Anyway, thanks again, Luis and all who helped on this.

Bill
PB 5.72 (32-bit) on Win 10.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: Mouse "UP" no longer works in 5.11

Post by electrochrisso »

Here is my two cents worth, code added for middle button. :)

Code: Select all

Enumeration 
 #My_Event_LeftClick_Down = #PB_Event_FirstCustomValue
 #My_Event_RightClick_Down
 #My_Event_MiddleClick_Down
 #My_Event_MiddleClick_Up
EndEnumeration

Procedure wc (hWnd, uMsg, wParam, lParam)   
 Select uMsg
    Case #WM_LBUTTONDOWN
        PostEvent(#My_Event_LeftClick_Down)
    Case #WM_RBUTTONDOWN
        PostEvent(#My_Event_RightClick_Down)
    Case #WM_MBUTTONDOWN
        PostEvent(#My_Event_MiddleClick_Down)
    Case #WM_MBUTTONUP
        PostEvent(#My_Event_MiddleClick_Up)
 EndSelect     

 ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure


If OpenWindow(0,0,0,200,200,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
 
 SetWindowCallback(@wc())
 
 Repeat
   
    eventid = WaitWindowEvent()
    
    Select eventid
       
      Case #PB_Event_CloseWindow
        quit=1
       
      Case #My_Event_LeftClick_Down
        Debug "Left button Down"
       
      Case #PB_Event_LeftClick
        Debug "Left button up"
       
      Case #My_Event_RightClick_Down
        Debug "Right button down"
       
      Case #PB_Event_RightClick
        Debug "Right button up"
       
      Case #My_Event_MiddleClick_Down
        Debug "Middle button down"
       
      Case #My_Event_MiddleClick_Up
        Debug "Middle button up"
       
    EndSelect
   
 Until quit
EndIf
PureBasic! Purely the best 8)
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Mouse "UP" no longer works in 5.11

Post by Michael Vogel »

Wouldn't feel good with this quick & dirty solution, but seems to be a workaround for 5.11 (and maybe PB 5.21 bring back the lost window events)

Code: Select all

; (No) button up detection

If OpenWindow(0,0,0,200,200,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
	Repeat

		eventid=WaitWindowEvent()
		Select eventid

		Case #PB_Event_CloseWindow
			quit=1

		Case #WM_LBUTTONDOWN
			Debug "Left button Down"
			
		Case #WM_LBUTTONUP,#PB_Event_LeftClick
			Debug "Left button up"

		Case #WM_RBUTTONDOWN
			Debug "Right button down"

		Case #WM_RBUTTONUP,#PB_Event_RightClick
			Debug "Right button up"

		EndSelect

	Until quit
EndIf
Post Reply