It is currently Sat Aug 24, 2019 5:38 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Detecting right-clicks on ButtonGadgets
PostPosted: Sat Feb 04, 2006 1:01 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
Version 4.00 removed the AdvancedGadgetEvents() command, so to detect a
right-click on a ButtonGadget now you can use the code below (which should
also work for any gadget, actually).

But don't forget that most gadgets, after an event, can trigger an EventType()
of #PB_EventType_RightClick, so this code is really only useful for Buttons. :)

Code:
; Original code by Danilo.
; Modified by PB, MLK and Trond.

If OpenWindow(0,200,200,200,200,"ButtonGadget Right-click",#PB_Window_SystemMenu)
  CreateGadgetList(WindowID(0))
  ButtonGadget(0,50,50,100,100,"Right-click me!")
  Repeat
    Select WaitWindowEvent()
      Case #WM_RBUTTONDOWN
        GetWindowRect_(GadgetID(0),@rect.RECT) : GetCursorPos_(@pt.POINT)
        If PtInRect_(@rect,pt\x,pt\y)
          Repeat : Sleep_(1) : Until GetAsyncKeyState_(#VK_RBUTTON)=0
          GetCursorPos_(@pt.POINT)
          If PtInRect_(@rect,pt\x,pt\y) : Debug "Right-click" : EndIf
        EndIf
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf

(Edited again due to OpenWindow changing parameter order)

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Last edited by PB on Sat Mar 18, 2006 1:20 am, edited 6 times in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Feb 04, 2006 1:47 pm 
Offline
Moderator
Moderator

Joined: Sat Dec 27, 2003 3:55 am
Posts: 3321
Location: Great Southern Land
Neat. Thanks!

_________________
@}--`--,-- A rose by any other name ..


Top
 Profile  
Reply with quote  
 Post subject: Great
PostPosted: Sat Feb 04, 2006 5:32 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 4:00 pm
Posts: 103
Location: France
Thank's for the code, but i see one can only click one time on the button !
No other click is detected . . .

Dominique

_________________
Dominique

Windows 10 64bits. Pure basic 32bits


Top
 Profile  
Reply with quote  
 Post subject: Re: Great
PostPosted: Sun Feb 05, 2006 1:08 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> i see one can only click one time on the button

Weird! Works fine for me with 98se, Win2K and WinXP SP2. I can't see
anything in the code that would cause it to only work once. The program
flow is quite easy to follow, and logical. Maybe it's a SP1 issue? Dunno.
Are you using a clean v4.00 Beta 1 installation of PureBasic?

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Feb 05, 2006 12:10 pm 
Offline
Always Here
Always Here

Joined: Mon Sep 22, 2003 6:45 pm
Posts: 7439
Location: Norway
That's not a right-click. That's a right release. This means that you don't have to CLICK (as in a right-click), it's enough to release the rmb over the button. So you can press the rmb outside the button and release the rmb over the button.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sun Feb 05, 2006 1:13 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> That's not a right-click. That's a right release. This means that you don't
> have to CLICK (as in a right-click), it's enough to release the rmb over the
> button.

Good point, Trond -- I've edited the example to prevent that. ;)

@MLK: I also edited in your corrections, and deleted your post since it's now
incorporated into the tip. Hope you don't mind!

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Top
 Profile  
Reply with quote  
 Post subject: Oh, i see !
PostPosted: Sun Feb 05, 2006 8:15 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 4:00 pm
Posts: 103
Location: France
Well, if i click once on the button then the debugger window appears.
If i close the debugger, then click again on the button . . nothing happens !

Effectively, if i let the debugger window open i can see on each click on the button a new line in the debugger telling the click as been detected.

Is it normal or not, i don't now ?

Dominique

_________________
Dominique

Windows 10 64bits. Pure basic 32bits


Top
 Profile  
Reply with quote  
 Post subject: Re: Oh, i see !
PostPosted: Sun Feb 05, 2006 9:05 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> If i close the debugger, then click again on the button . . nothing happens !

That's because you chose to CLOSE the debugger! :roll: Not a bug at all.
Replace both "Debug" lines in the code with the following and you'll see:

Code:
MessageRequester("test","click")

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Top
 Profile  
Reply with quote  
 Post subject: Re: Detecting right-clicks on ButtonGadgets
PostPosted: Thu Feb 09, 2006 2:24 am 
Offline
Addict
Addict
User avatar

Joined: Thu Oct 16, 2003 8:30 pm
Posts: 1998
Location: North Florida
Nice api ..


- np


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Feb 09, 2006 4:23 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3109
Location: United Kingdom
I don't understand why buttons can't always have the #PB_EventType_RightClick enabled too?

This would be far more consistant with the other gadgets.

Fred, is there a reason for this?

If its because the Mac only has one button, most people I know who have Macs go out and buy a two button mouse straight away (the Mac OS supports 2 buttons).

-Anthony

_________________
http://www.SinisterSoft.com <- My Business website
http://www.ReportComplete.com and http://www.ReportPlus.co.uk <- School end of term reports system


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 17, 2006 10:43 pm 
Offline
User
User

Joined: Wed Mar 15, 2006 8:30 pm
Posts: 12
Why was the AvbancedGadgetEvents feature removed? Now you have to use a Windows-specific API call to detect a right click, which will not work under Linux.

Before you could just enable Advanced and use #PB_EventType_RightClick which would work for both Windows and Linux. Seems like a step backwards to me.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 17, 2006 11:36 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Dec 22, 2004 4:12 pm
Posts: 2446
Location: Norway
:(


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 17, 2006 11:50 pm 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8004
Location: Fort Nelson, BC, Canada
[edit] There's a goof in this one, check post after next for correct code
Code:
Procedure ButtonCallback(hWnd, Message, wParam, lParam)
  Select message
    Case #WM_PARENTNOTIFY
      Select ChildWindowFromPoint_(WindowID(0),WindowMouseX(0),WindowMouseY(0))
        Case GadgetID(0)
          Debug "Right button down on button 0"
        Case GadgetID(1)
          Debug "Right button down on button 1"
      EndSelect
    Case #WM_CONTEXTMENU
      Select ChildWindowFromPoint_(WindowID(0),WindowMouseX(0),WindowMouseY(0))
        Case GadgetID(0)
          Debug "Right button up on button 0"
        Case GadgetID(1)
          Debug "Right button up on button 1"
      EndSelect
  EndSelect
  Result = #PB_ProcessPureBasicEvents
  ProcedureReturn Result
EndProcedure

OpenWindow(0,0,0,400,300,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
ButtonGadget(0,120,80,160,46," Button 0")
ButtonGadget(1,120,140,160,46," Button 1")
SetWindowCallback(@ButtonCallback())
Repeat   
  ev=WaitWindowEvent()
   If ev=#PB_Event_Gadget
      ; Do something useful
  EndIf
Until ev=#PB_Event_CloseWindow 
End

_________________
Veni, vidi, vici.


Last edited by netmaestro on Sat Mar 18, 2006 12:14 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Mar 18, 2006 12:05 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
@netmaestro: Not so good -- If I LEFT click a button, it generates a RIGHT click event. ;)

_________________
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat Mar 18, 2006 12:10 am 
Offline
PureBasic Bullfrog
PureBasic Bullfrog
User avatar

Joined: Wed Jul 06, 2005 5:42 am
Posts: 8004
Location: Fort Nelson, BC, Canada
Sorry! I forgot a step :oops:
Code:
Procedure ButtonCallback(hWnd, Message, wParam, lParam)
  Select message
    Case #WM_PARENTNOTIFY
      If GetAsyncKeyState_(#VK_RBUTTON)
        Select ChildWindowFromPoint_(WindowID(0),WindowMouseX(0),WindowMouseY(0))
        Case GadgetID(0)
          Debug "Right button down on button 0"
        Case GadgetID(1)
          Debug "Right button down on button 1"
        EndSelect
      EndIf 
    Case #WM_CONTEXTMENU
      Select ChildWindowFromPoint_(WindowID(0),WindowMouseX(0),WindowMouseY(0))
        Case GadgetID(0)
          Debug "Right button up on button 0"
        Case GadgetID(1)
          Debug "Right button up on button 1"
      EndSelect
  EndSelect
  Result = #PB_ProcessPureBasicEvents
  ProcedureReturn Result
EndProcedure

OpenWindow(0,0,0,400,300,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateGadgetList(WindowID(0))
ButtonGadget(0,120,80,160,46," Button 0")
ButtonGadget(1,120,140,160,46," Button 1")
SetWindowCallback(@ButtonCallback())
Repeat   
  ev=WaitWindowEvent()
   If ev=#PB_Event_Gadget
      ; Do something useful
  EndIf
Until ev=#PB_Event_CloseWindow 
End

_________________
Veni, vidi, vici.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye