Results 1 to 11 of 11

Thread: VS2012 Press & Hold for Right Click.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    VS2012 Press & Hold for Right Click.

    Hi,

    I've created a win forms application that is designed to run on a windows 8 tablet, however I have one issue that I cannot seem to resolve.

    The application allows the users to move remote objects by holding down directional buttons, this works fine with actual mouse clicks and mouse down events but when operated using a finger press on the tablet the mouse down event becomes a right button click and the remote device stops moving.

    I've read about the stylus class and ways to disable the 'press and hold for right mouse' but this only applies to WPF, does anybody have a method of disabling this on a win forms application ?

    Thanks in advance.
    If my post helps , please feel free to rate it

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: VS2012 Press & Hold for Right Click.

    No, the mouse down event doesn't become a click. The point is that the button is actually irrelevant except as a location. It is the mouse down event which does all the work and, of course, if you don't use the mouse, there is no mouse down event. The click is always fired by the button however it is operated. I don't (and won't!!!) use W8 or a touchscreen of any kind but surely there is some kind of "finger down" event equivalent to mouse down otherwise drag and drop etc. would be effectively impossible?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: VS2012 Press & Hold for Right Click.

    Thanks for your reply, what you are saying regarding the mouse down event does make sense, I can however get it to work by tapping the button quickly then holding it down and the mousedown code executes as expected but this is pretty hit and miss.

    There is as far as I can tell no 'finger down' type event and I'm sure that the mousedown event at least initially fires as the device begins to move as all the movement code is within the mousedown event but then stops once the 'perceived' right click takes place.

    I think the key to the solution is to disable this action if possible.
    If my post helps , please feel free to rate it

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: VS2012 Press & Hold for Right Click.

    Well you could just use a disabled button! But that may not look right. In which case I'd be tempted simply to draw your own pseudo-buttons which obviously won't have any click event. (I was gonna suggest using another control without a click event but I don't think there is one!)
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: VS2012 Press & Hold for Right Click.

    Looks like the answer is to stop the window receiving the event using this method.

    http://msdn.microsoft.com/en-gb/libr...=vs.85%29.aspx

    It steps beyond my comfort zone but hopefully I'll figure it out.
    If my post helps , please feel free to rate it

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: VS2012 Press & Hold for Right Click.

    OK need a little advice on this, I've had a few goes at it and done a fair bit of reading but I must be missing something as I can't seem to disable the press and hold function.

    Here are the functions and constants that have been declared

    Code:
     Public Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Integer
        Public Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal hData As Integer) As Integer
        Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
        Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
        Public Declare Function GlobalDeleteAtom Lib "kernel32" Alias "GlobalDeleteAtom" (ByVal nAtom As Integer) As Integer
        Const SWP_HIDEWINDOW = &H80
        Const SWP_SHOWWINDOW = &H40
        Dim taskBar As Integer
        Dim WindowHandle As Integer
    
        Const WM_SYSCOMMAND As Integer = &H112
        Const SC_RESTORE As Integer = &HF120
        Const WM_TABLET_DEFBASE As Integer = &H2C0
        Const WM_TABLET_QUERYSYSTEMGESTURESTATUS As Integer = WM_TABLET_DEFBASE + 12
        Const TABLET_DISABLE_PRESSANDHOLD As Integer = &H1
    And here's how I'm implementing it, I also hide the taskbar as well which does work !

    Code:
    Protected Overrides Sub WndProc(ByRef m As Message)
    
            If m.Msg = WM_TABLET_QUERYSYSTEMGESTURESTATUS Then
                'Call the GlobalAdd atom Function
                Dim atom As String = GlobalAddAtom("MICROSOFT_TABLETPENSERVICE_PROPERTY")
                'Call the setProc function
                SetProp(WindowHAndle, atom, TABLET_DISABLE_PRESSANDHOLD)
                GlobalDeleteAtom(atom)
            End If
    
            If m.Msg = WM_SYSCOMMAND And m.WParam.ToInt32 = SC_RESTORE Then
                SetWindowPos(taskBar, 0&, 0&, 0&, 0&, 0&, SWP_HIDEWINDOW)
            End If
    
            MyBase.WndProc(m)
        End Sub
    As I said earlier, this is outside my current comfort zone so any advice would be greatly appreciated.
    If my post helps , please feel free to rate it

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: VS2012 Press & Hold for Right Click.

    You're allowing the message to pass through to the normal windows routines which are therefore undoing any changes you make.

    vb.net Code:
    1. Protected Overrides Sub WndProc(ByRef m As Message)
    2.  Dim AllowNormalProcessing As Boolean = True
    3.  
    4.         If m.Msg = WM_TABLET_QUERYSYSTEMGESTURESTATUS Then
    5.             'Call the GlobalAdd atom Function
    6.             Dim atom As String = GlobalAddAtom("MICROSOFT_TABLETPENSERVICE_PROPERTY")
    7.             'Call the setProc function
    8.             SetProp(WindowHAndle, atom, TABLET_DISABLE_PRESSANDHOLD)
    9.             GlobalDeleteAtom(atom)
    10.  
    11.             AllowNormalProcessing = False
    12.  
    13.         End If
    14.  
    15.         If m.Msg = WM_SYSCOMMAND And m.WParam.ToInt32 = SC_RESTORE Then
    16.             SetWindowPos(taskBar, 0&, 0&, 0&, 0&, 0&, SWP_HIDEWINDOW)
    17.  
    18.            AllowNormalProcessing = False
    19.  
    20.         End If
    21.  
    22.         If AllowNormalProcessing Then MyBase.WndProc(m)
    23.  
    24.     End Sub
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  8. #8
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: VS2012 Press & Hold for Right Click.

    Quote Originally Posted by dunfiddlin View Post
    Well you could just use a disabled button! But that may not look right. In which case I'd be tempted simply to draw your own pseudo-buttons which obviously won't have any click event. (I was gonna suggest using another control without a click event but I don't think there is one!)
    Couldn't he simply inherit the button control and override click event? Therefore he'd then be able to theoretically preventing the click events from being fire without disabling the button itself.

    vbnet Code:
    1. Public Class CustomButton
    2.     Inherits System.Windows.Forms.Button
    3.  
    4.     Sub New()
    5.         MyBase.New()
    6.         Call InitializeComponent()
    7.     End Sub
    8.  
    9.     Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
    10.         'MyBase.OnClick(e) '  Prevents this event from firing.
    11.     End Sub
    12.  
    13. End Class
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: VS2012 Press & Hold for Right Click.

    In theory, certainly. But then will he need to also disable MouseClick? And having done so, what about MouseDown? It would be very easy to end up just chasing your tail (if you'll pardon the punning allusion!) If there is a way to say "I'm doing a drag now so I don't want any nonsense from you other events!" that would be the better option.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Lancashire UK
    Posts
    375

    Re: VS2012 Press & Hold for Right Click.

    Thanks for the help unfortunately if I prevent the MyBase.Wnproc(m) from executing with the boolean flag, the form does not load and I get the folowing exception

    'An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.Windows.Forms.dll
    Additional information: Error creating window handle.'

    From what I have read I just need to respond to the WM_TABLET_QUERYSYSTEMGESTURESTATUS message with the constant for disabling the 'press and hold for click' gesture, sounds pretty straight forward but to be honest I'm pretty stuck.

    I'm also sure it has nothing to do with buttons as no matter where I press and hold the right click is done but at a lower level than my code if that makes sense.
    If my post helps , please feel free to rate it

  11. #11
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: VS2012 Press & Hold for Right Click.

    Try it with the Boolean on the first If only. I almost left it at that anyway. Unfortunately I have no way to lay hands on a touchscreen device to check it for myself.

    Otherwise we may have to go back to some of the original suggestions.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width