Windows API mouse commands no longer work

Just starting out? Need help? Post your questions and find answers here.
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Windows API mouse commands no longer work

Post by Samuel »

On PB 5.0 they work fine, but i recently downloaded the newest beta and they no longer seem to work.
Any help is appreciated.


Code: Select all


If OpenWindow(0, 0, 0, 800, 600, "Test",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
     StartDrawing(WindowOutput(0)) 
        Box(0,0,800,600,RGB(0,0,0))
     StopDrawing()
EndIf



Repeat
     
    Event= WaitWindowEvent()   


    Select event
      Case #WM_LBUTTONUP
        Debug "Left Button Up"
      Case #WM_RBUTTONUP
        Debug "Right Button Up"
    EndSelect     

     
  Until Event = #PB_Event_CloseWindow
  End

User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Windows API mouse commands no longer work

Post by ts-soft »

This events native in PB5.10

Code: Select all

If OpenWindow(0, 0, 0, 800, 600, "Test",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  StartDrawing(WindowOutput(0))
  Box(0,0,800,600,RGB(0,0,0))
  StopDrawing()
EndIf

Repeat
  
  Event= WaitWindowEvent()   
  
  
  Select event
    Case #PB_Event_LeftClick
      Debug "Left Button Up"
    Case #PB_Event_RightClick
      Debug "Right Button Up"
  EndSelect     
  
  
Until Event = #PB_Event_CloseWindow
End

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Windows API mouse commands no longer work

Post by luis »

And if you want windows messages just use SetWindowCallback(), look at the doc and you will see windows #WM_ messages were never documented as possible return values for WaitWindowEvent().

Code: Select all

Procedure wc (hWnd, uMsg, wParam, lParam)   
 Select uMsg
  Case #WM_LBUTTONUP
    Debug "Left Button Up"
  Case #WM_RBUTTONUP
    Debug "Right Button Up"
 EndSelect     

 ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure 

If OpenWindow(0, 0, 0, 800, 600, "Test",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
     StartDrawing(WindowOutput(0))
        Box(0,0,800,600,RGB(0,0,0))
     StopDrawing()
EndIf

SetWindowCallback(@wc())

Repeat
 Event = WaitWindowEvent()   
Until Event = #PB_Event_CloseWindow

End
 
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Windows API mouse commands no longer work

Post by Samuel »

Thanks ts-soft that takes care of my problem, but I have one question. How do you tell if the mouse button was pressed or released? Looking in the help files
I only see options for right,left, and left double click.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Windows API mouse commands no longer work

Post by netmaestro »

How do you tell if the mouse button was pressed or released?
Pressed vs. released is only native in the keyboard library for screens. See the solution from luis above for acheiving it on a window.
BERESHEIT
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: Windows API mouse commands no longer work

Post by VB6_to_PBx »

is the Code below how the next PureBasic version will be ?

Code: Select all


;        Windows_Message__Mouse_Events__v1.pb

;        Post subject: Windows API mouse commands no longer work
;        http://www.purebasic.fr/english/viewtopic.php?f=13&t=53112


Procedure wc (hWnd, uMsg, wParam, lParam)   
    Select uMsg
    Case #WM_LBUTTONDOWN
         SetWindowTitle(0,"Left Button Down")
    Case #WM_LBUTTONUP
         SetWindowTitle(0,"Left Button Up")
    Case #WM_LBUTTONDBLCLK
         SetWindowTitle(0,"Left Button DoubeClick")
    Case #WM_RBUTTONDOWN
         SetWindowTitle(0,"Right Button Down")
    Case #WM_RBUTTONUP
         SetWindowTitle(0,"Right Button Up")
    Case #WM_RBUTTONDBLCLK
         SetWindowTitle(0,"Right Button DoubeClick")
    EndSelect     

    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

OpenWindow(0, 0, 0, 800, 600, "Test",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
     
StartDrawing(WindowOutput(0))
    Box(0,0,800,600,RGB(0,0,0))
StopDrawing()

SetWindowCallback(@wc())

Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow


 

so this older 5.0 version Code below , is not planned to work correctly in the next final version release ?
you will now need to use the above Code in all future releases ?

Code: Select all


;        Windows_Message__Mouse_Events__v2.pb

;        Post subject: Windows API mouse commands no longer work
;        http://www.purebasic.fr/english/viewtopic.php?f=13&t=53112

OpenWindow(0, 0, 0, 800, 600, "Test",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
    
StartDrawing(WindowOutput(0))
    Box(0,0,800,600,RGB(0,0,0))
StopDrawing()

Repeat
 
Event= WaitWindowEvent()   
    Select event
    Case #PB_Event_CloseWindow
         End
    Case #WM_LBUTTONDOWN
         SetWindowTitle(0,"Left Button Down")
    Case #WM_LBUTTONUP
         SetWindowTitle(0,"Left Button Up")
    Case #WM_LBUTTONDBLCLK
         SetWindowTitle(0,"Left Button DoubeClick")
    Case #WM_RBUTTONDOWN
         SetWindowTitle(0,"Right Button Down")
    Case #WM_RBUTTONUP
         SetWindowTitle(0,"Right Button Up")
    EndSelect     
Until Event = #PB_Event_CloseWindow
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Windows API mouse commands no longer work

Post by netmaestro »

The buttonup events can be identified by the appropriate click events in the PB event loop:

Code: Select all

;        Windows_Message__Mouse_Events__v2.pb

;        Post subject: Windows API mouse commands no longer work
;        http://www.purebasic.fr/english/viewtopic.php?f=13&t=53112

OpenWindow(0, 0, 0, 800, 600, "Test",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
   
StartDrawing(WindowOutput(0))
    Box(0,0,800,600,RGB(0,0,0))
StopDrawing()

Repeat
 
  Event= WaitWindowEvent()   
  Debug event
    Select event
    Case #PB_Event_CloseWindow
         End
    Case #WM_LBUTTONDOWN
         SetWindowTitle(0,"Left Button Down")
    Case #PB_Event_LeftClick
         SetWindowTitle(0,"Left Button Up")
    Case #PB_Event_LeftDoubleClick
         SetWindowTitle(0,"Left Button DoubeClick")
    Case #WM_RBUTTONDOWN
         SetWindowTitle(0,"Right Button Down")
    Case #PB_Event_RightClick
         SetWindowTitle(0,"Right Button Up")
    EndSelect     
  Until Event = #PB_Event_CloseWindow
  
As seen in this code, the only events you need to use WM_ messages for are the buttondown events. Everything else is available through native events.
BERESHEIT
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 627
Joined: Mon May 09, 2011 9:36 am

Re: Windows API mouse commands no longer work

Post by VB6_to_PBx »

netmaestro, thank you for the clarification !

(luis's ) type Code below seems to work in all the versions from 5.0 to latest 5.10Beta's

Code: Select all


;        Windows_Message__Mouse_Events__v3.pb

;        Post subject: Windows API mouse commands no longer work
;        http://www.purebasic.fr/english/viewtopic.php?f=13&t=53112


Procedure wc (hWnd, uMsg, wParam, lParam)   
    Select uMsg
    Case #WM_LBUTTONDOWN   : SetWindowTitle(0,"Left Button Down")
    Case #WM_LBUTTONUP     : SetWindowTitle(0,"Left Button Up")
    Case #WM_LBUTTONDBLCLK : SetWindowTitle(0,"Left Button DoubleClick")
    Case #WM_RBUTTONDOWN   : SetWindowTitle(0,"Right Button Down")
    Case #WM_RBUTTONUP     : SetWindowTitle(0,"Right Button Up")
    Case #WM_RBUTTONDBLCLK : SetWindowTitle(0,"Right Button DoubleClick")
    EndSelect     

    ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

OpenWindow(0, 0, 0, 800, 600, "Test",  #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
     
SetWindowCallback(@wc())

Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow


 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
aliza12
New User
New User
Posts: 1
Joined: Tue Jun 04, 2013 7:19 am

Re: Windows API mouse commands no longer work

Post by aliza12 »

Hi Guys
1st Type the code type Code below seems to work in all the versions from 5.0 to latest 5.10Beta's

Code:

; Windows_Message__Mouse_Events__v3.pb

; Post subject: Windows API mouse commands no longer work
; http://www.purebasic.fr/english/viewtop ... 13&t=53112


Procedure wc (hWnd, uMsg, wParam, lParam)
Select uMsg
Case #WM_LBUTTONDOWN : SetWindowTitle(0,"Left Button Down")
Case #WM_LBUTTONUP : SetWindowTitle(0,"Left Button Up")
Case #WM_LBUTTONDBLCLK : SetWindowTitle(0,"Left Button DoubleClick")
Case #WM_RBUTTONDOWN : SetWindowTitle(0,"Right Button Down")
Case #WM_RBUTTONUP : SetWindowTitle(0,"Right Button Up")
Case #WM_RBUTTONDBLCLK : SetWindowTitle(0,"Right Button DoubleClick")
EndSelect

ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

OpenWindow(0, 0, 0, 800, 600, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered )

SetWindowCallback(@wc())

Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow
Post Reply