473,738 Members | 3,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hook system mouse down?



I need to hook the system mouse down event.

I'm trying to replicate how a context menu hides when the mouse clicks
outside of the control.

Thanks,

Schneider
Jun 27 '08 #1
22 6427

"schneider" <es********@com munity.nospamwr ote in message
news:Oc******** ******@TK2MSFTN GP02.phx.gbl...
>

I need to hook the system mouse down event.

I'm trying to replicate how a context menu hides when the mouse clicks
outside of the control.

Thanks,

Schneider
I'm assuming you want to be able to get the mouse anywhere on the screen.
If you only mean in your app, then you would handle the mouse events for
your form - otherwise you can look at this sample :) This needs a lot more
work to be complete - but here is a sample of installing a global mouse
hook. The work that needs to be done is in the HookProc in the
GlobalMouseHook class. You can use the information that is passed to
actually send information to the event (that's why I used the
mouseeventhandl er). You also have access to mouse wheel info if you so
desire. Anyway, here is a basic example, watch for wrap :)

Option Strict On
Option Explicit On
Option Infer Off

Imports System.Runtime. InteropServices

Public Class Form1
Inherits System.Windows. Forms.Form

Public Sub New()
InitializeCompo nent()
End Sub

#Region "Designer Code"
'Form overrides dispose to clean up the component list.
<System.Diagnos tics.DebuggerNo nUserCode()_
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Disp ose()
End If
Finally
MyBase.Dispose( disposing)
End Try
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()_
Private Sub InitializeCompo nent()
Me.ListBox1 = New System.Windows. Forms.ListBox
Me.SuspendLayou t()
'
'ListBox1
'
Me.ListBox1.Doc k = System.Windows. Forms.DockStyle .Fill
Me.ListBox1.For mattingEnabled = True
Me.ListBox1.Int egralHeight = False
Me.ListBox1.Loc ation = New System.Drawing. Point(0, 0)
Me.ListBox1.Nam e = "ListBox1"
Me.ListBox1.Siz e = New System.Drawing. Size(284, 264)
Me.ListBox1.Tab Index = 0
'
'Form1
'
Me.AutoScaleDim ensions = New System.Drawing. SizeF(6.0!, 13.0!)
Me.AutoScaleMod e = System.Windows. Forms.AutoScale Mode.Font
Me.ClientSize = New System.Drawing. Size(284, 264)
Me.Controls.Add (Me.ListBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub
Friend WithEvents ListBox1 As System.Windows. Forms.ListBox
#End Region

Private WithEvents gmh As GlobalMouseHook

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
gmh = New GlobalMouseHook ()

End Sub

Private Sub Form1_FormClose d(ByVal sender As System.Object, ByVal e As
System.Windows. Forms.FormClose dEventArgs) Handles MyBase.FormClos ed
gmh.Dispose()
End Sub

Private Sub gmh_MouseDown(B yVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles gmh.MouseDown
Me.ListBox1.Ite ms.Add(String.F ormat("{0} down at screen coordinate
({1},{2})", e.Button, e.X, e.Y))
End Sub

Private Sub gmh_MouseMove(B yVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles gmh.MouseMove
'Me.ListBox1.It ems.Add("Move")
End Sub

Private Sub gmh_MouseUp(ByV al sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles gmh.MouseUp
Me.ListBox1.Ite ms.Add("Up")
End Sub
End Class
Friend Class GlobalMouseHook
Implements IDisposable

Private hhk As IntPtr = IntPtr.Zero
Private disposedValue As Boolean = False ' To detect redundant
calls

Public Event MouseDown As MouseEventHandl er
Public Event MouseUp As MouseEventHandl er
Public Event MouseMove As MouseEventHandl er

Public Sub New()
Hook()
End Sub

Private Sub Hook()
Dim hInstance As IntPtr = LoadLibrary("Us er32")
hhk = SetWindowsHookE x(WH_MOUSE_LL, AddressOf Me.HookProc,
hInstance, 0)
End Sub

Private Sub Unhook()
UnhookWindowsHo okEx(hhk)
End Sub

Private Function HookProc(ByVal nCode As Integer, ByVal wParam As
UInteger, ByRef lParam As MSLLHOOKSTRUCT) As Integer
If nCode >= 0 Then
Select Case wParam
Case WM_LBUTTONDOWN
RaiseEvent MouseDown(Me, New
MouseEventArgs( MouseButtons.Le ft, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_RBUTTONDOWN
RaiseEvent MouseDown(Me, New
MouseEventArgs( MouseButtons.Ri ght, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_MBUTTONDOWN
RaiseEvent MouseDown(Me, New
MouseEventArgs( MouseButtons.Mi ddle, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_LBUTTONUP, WM_RBUTTONUP, WM_MBUTTONUP
RaiseEvent MouseUp(Nothing , Nothing)
Case WM_MOUSEMOVE
RaiseEvent MouseMove(Nothi ng, Nothing)
Case WM_MOUSEWHEEL, WM_MOUSEHWHEEL
Case Else
Console.WriteLi ne(wParam)
End Select
End If
Return CallNextHookEx( hhk, nCode, wParam, lParam)
End Function

#Region "API Declarations"
<StructLayout(L ayoutKind.Seque ntial)_
Private Structure API_POINT
Public x As Integer
Public y As Integer
End Structure

<StructLayout(L ayoutKind.Seque ntial)_
Private Structure MSLLHOOKSTRUCT
Public pt As API_POINT
Public mouseData As UInteger
Public flags As UInteger
Public time As UInteger
Public dwExtraInfo As IntPtr
End Structure

Private Const WM_MOUSEWHEEL As UInteger = &H20A
Private Const WM_MOUSEHWHEEL As UInteger = &H20E
Private Const WM_MOUSEMOVE As UInteger = &H200
Private Const WM_LBUTTONDOWN As UInteger = &H201
Private Const WM_LBUTTONUP As UInteger = &H202
Private Const WM_MBUTTONDOWN As UInteger = &H207
Private Const WM_MBUTTONUP As UInteger = &H208
Private Const WM_RBUTTONDOWN As UInteger = &H204
Private Const WM_RBUTTONUP As UInteger = &H205
Private Const WH_MOUSE_LL As Integer = 14

Private Delegate Function LowLevelMouseHo okProc(ByVal nCode As Integer,
ByVal wParam As UInteger, ByRef lParam As MSLLHOOKSTRUCT) As Integer

Private Declare Auto Function LoadLibrary Lib "kernel32" (ByVal
lpFileName As String) As IntPtr
Private Declare Auto Function SetWindowsHookE x Lib "user32.dll " (ByVal
idHook As Integer, ByVal lpfn As LowLevelMouseHo okProc, ByVal hInstance As
IntPtr, ByVal dwThreadId As UInteger) As IntPtr
Private Declare Function CallNextHookEx Lib "user32" (ByVal hhk As
IntPtr, ByVal nCode As Integer, ByVal wParam As UInteger, ByRef lParam As
MSLLHOOKSTRUCT) As Integer
Private Declare Function UnhookWindowsHo okEx Lib "user32" (ByVal hhk As
IntPtr) As Boolean
#End Region

' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValu e Then
If disposing Then
' TODO: free other state (managed objects).
End If

Unhook()
End If
Me.disposedValu e = True
End Sub

#Region " IDisposable Support "
' This code added by Visual Basic to correctly implement the disposable
pattern.
Public Sub Dispose() Implements IDisposable.Dis pose
' Do not change this code. Put cleanup code in Dispose(ByVal
disposing As Boolean) above.
Dispose(True)
GC.SuppressFina lize(Me)
End Sub
#End Region

End Class

Jun 27 '08 #2
Tom,

Nice sample, I always am curious why people are using for describing window
messages those UpperCase words.

I never saw any reason for that, however by that so frequent use of that, it
gives the idea that it is needed.

Can you tell what is it, that I am missing?

Or is it just conventional stuff used in past in VB6 and C*?

Cor

"Tom Shelton" <to*********@co mcastYOUKNOWTHE DRILL.netschree f in bericht
news:A0******** *************** ***********@mic rosoft.com...
>
"schneider" <es********@com munity.nospamwr ote in message
news:Oc******** ******@TK2MSFTN GP02.phx.gbl...
>>

I need to hook the system mouse down event.

I'm trying to replicate how a context menu hides when the mouse clicks
outside of the control.

Thanks,

Schneider

I'm assuming you want to be able to get the mouse anywhere on the screen.
If you only mean in your app, then you would handle the mouse events for
your form - otherwise you can look at this sample :) This needs a lot
more work to be complete - but here is a sample of installing a global
mouse hook. The work that needs to be done is in the HookProc in the
GlobalMouseHook class. You can use the information that is passed to
actually send information to the event (that's why I used the
mouseeventhandl er). You also have access to mouse wheel info if you so
desire. Anyway, here is a basic example, watch for wrap :)

Option Strict On
Option Explicit On
Option Infer Off

Imports System.Runtime. InteropServices

Public Class Form1
Inherits System.Windows. Forms.Form

Public Sub New()
InitializeCompo nent()
End Sub

#Region "Designer Code"
'Form overrides dispose to clean up the component list.
<System.Diagnos tics.DebuggerNo nUserCode()_
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Disp ose()
End If
Finally
MyBase.Dispose( disposing)
End Try
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnos tics.DebuggerSt epThrough()_
Private Sub InitializeCompo nent()
Me.ListBox1 = New System.Windows. Forms.ListBox
Me.SuspendLayou t()
'
'ListBox1
'
Me.ListBox1.Doc k = System.Windows. Forms.DockStyle .Fill
Me.ListBox1.For mattingEnabled = True
Me.ListBox1.Int egralHeight = False
Me.ListBox1.Loc ation = New System.Drawing. Point(0, 0)
Me.ListBox1.Nam e = "ListBox1"
Me.ListBox1.Siz e = New System.Drawing. Size(284, 264)
Me.ListBox1.Tab Index = 0
'
'Form1
'
Me.AutoScaleDim ensions = New System.Drawing. SizeF(6.0!, 13.0!)
Me.AutoScaleMod e = System.Windows. Forms.AutoScale Mode.Font
Me.ClientSize = New System.Drawing. Size(284, 264)
Me.Controls.Add (Me.ListBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout (False)

End Sub
Friend WithEvents ListBox1 As System.Windows. Forms.ListBox
#End Region

Private WithEvents gmh As GlobalMouseHook

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
gmh = New GlobalMouseHook ()

End Sub

Private Sub Form1_FormClose d(ByVal sender As System.Object, ByVal e As
System.Windows. Forms.FormClose dEventArgs) Handles MyBase.FormClos ed
gmh.Dispose()
End Sub

Private Sub gmh_MouseDown(B yVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles gmh.MouseDown
Me.ListBox1.Ite ms.Add(String.F ormat("{0} down at screen coordinate
({1},{2})", e.Button, e.X, e.Y))
End Sub

Private Sub gmh_MouseMove(B yVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles gmh.MouseMove
'Me.ListBox1.It ems.Add("Move")
End Sub

Private Sub gmh_MouseUp(ByV al sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles gmh.MouseUp
Me.ListBox1.Ite ms.Add("Up")
End Sub
End Class
Friend Class GlobalMouseHook
Implements IDisposable

Private hhk As IntPtr = IntPtr.Zero
Private disposedValue As Boolean = False ' To detect redundant
calls

Public Event MouseDown As MouseEventHandl er
Public Event MouseUp As MouseEventHandl er
Public Event MouseMove As MouseEventHandl er

Public Sub New()
Hook()
End Sub

Private Sub Hook()
Dim hInstance As IntPtr = LoadLibrary("Us er32")
hhk = SetWindowsHookE x(WH_MOUSE_LL, AddressOf Me.HookProc,
hInstance, 0)
End Sub

Private Sub Unhook()
UnhookWindowsHo okEx(hhk)
End Sub

Private Function HookProc(ByVal nCode As Integer, ByVal wParam As
UInteger, ByRef lParam As MSLLHOOKSTRUCT) As Integer
If nCode >= 0 Then
Select Case wParam
Case WM_LBUTTONDOWN
RaiseEvent MouseDown(Me, New
MouseEventArgs( MouseButtons.Le ft, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_RBUTTONDOWN
RaiseEvent MouseDown(Me, New
MouseEventArgs( MouseButtons.Ri ght, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_MBUTTONDOWN
RaiseEvent MouseDown(Me, New
MouseEventArgs( MouseButtons.Mi ddle, 0, lParam.pt.x, lParam.pt.y, 0))
Case WM_LBUTTONUP, WM_RBUTTONUP, WM_MBUTTONUP
RaiseEvent MouseUp(Nothing , Nothing)
Case WM_MOUSEMOVE
RaiseEvent MouseMove(Nothi ng, Nothing)
Case WM_MOUSEWHEEL, WM_MOUSEHWHEEL
Case Else
Console.WriteLi ne(wParam)
End Select
End If
Return CallNextHookEx( hhk, nCode, wParam, lParam)
End Function

#Region "API Declarations"
<StructLayout(L ayoutKind.Seque ntial)_
Private Structure API_POINT
Public x As Integer
Public y As Integer
End Structure

<StructLayout(L ayoutKind.Seque ntial)_
Private Structure MSLLHOOKSTRUCT
Public pt As API_POINT
Public mouseData As UInteger
Public flags As UInteger
Public time As UInteger
Public dwExtraInfo As IntPtr
End Structure

Private Const WM_MOUSEWHEEL As UInteger = &H20A
Private Const WM_MOUSEHWHEEL As UInteger = &H20E
Private Const WM_MOUSEMOVE As UInteger = &H200
Private Const WM_LBUTTONDOWN As UInteger = &H201
Private Const WM_LBUTTONUP As UInteger = &H202
Private Const WM_MBUTTONDOWN As UInteger = &H207
Private Const WM_MBUTTONUP As UInteger = &H208
Private Const WM_RBUTTONDOWN As UInteger = &H204
Private Const WM_RBUTTONUP As UInteger = &H205
Private Const WH_MOUSE_LL As Integer = 14

Private Delegate Function LowLevelMouseHo okProc(ByVal nCode As Integer,
ByVal wParam As UInteger, ByRef lParam As MSLLHOOKSTRUCT) As Integer

Private Declare Auto Function LoadLibrary Lib "kernel32" (ByVal
lpFileName As String) As IntPtr
Private Declare Auto Function SetWindowsHookE x Lib "user32.dll " (ByVal
idHook As Integer, ByVal lpfn As LowLevelMouseHo okProc, ByVal hInstance As
IntPtr, ByVal dwThreadId As UInteger) As IntPtr
Private Declare Function CallNextHookEx Lib "user32" (ByVal hhk As
IntPtr, ByVal nCode As Integer, ByVal wParam As UInteger, ByRef lParam As
MSLLHOOKSTRUCT) As Integer
Private Declare Function UnhookWindowsHo okEx Lib "user32" (ByVal hhk As
IntPtr) As Boolean
#End Region

' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValu e Then
If disposing Then
' TODO: free other state (managed objects).
End If

Unhook()
End If
Me.disposedValu e = True
End Sub

#Region " IDisposable Support "
' This code added by Visual Basic to correctly implement the disposable
pattern.
Public Sub Dispose() Implements IDisposable.Dis pose
' Do not change this code. Put cleanup code in Dispose(ByVal
disposing As Boolean) above.
Dispose(True)
GC.SuppressFina lize(Me)
End Sub
#End Region

End Class
Jun 27 '08 #3
Hello Schneider,

From your post, my understanding on this issue is: how to hook the system
mouse down event in VB.NET. If I'm off base, please feel free to let me
know.

There are generally two different types of system hook: local system hook
(set a hook that is specific to a thread and to a hook procedure) and
global system hook (a system hook that is called when the specified
messages are processed by any application on the entire system.). Would you
let me know which type of hook you referred to?

If you meant local system hook, I'd suggest the KB article
http://support.microsoft.com/kb/319524. The WH_MOUSE hook enables you to
monitor mouse messages about to be returned by the GetMessage or
PeekMessage function. You can use the WH_MOUSE hook to monitor mouse input
posted to a message queue. To modify the code in the KB to hook mouse down
event, we can add a Select Case wParam statement in MouseHookProc, and
check if wParam equals WM_RBUTTONDOWN or WM_RBUTTONUP.

If you meant global system hook, There are WH_MOUSE_LL hooks that can be
installed globally. The code in
http://www.colinneller.com/blog/Perm...c95-a322-b9ee5
918a39c.aspx provides an example in VB.NET, which exposes a OnMouseUp event
we can utilize. For more readings about global system hook in .NET, please
refer to the codeproject article:
http://www.codeproject.com/KB/system...ystemhook.aspx
http://www.codeproject.com/KB/cs/globalhook.aspx

Let me know if you have any other concerns or questions.

Regards,
Jialiang Ge (ji****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 27 '08 #4
On Apr 30, 1:04*am, "Cor Ligthert[MVP]" <notmyfirstn... @planet.nl>
wrote:
Tom,

Nice sample, I always am curious why people are using for describing window
messages those UpperCase words.

I never saw any reason for that, however by that so frequent use of that, it
gives the idea that it is needed.

Can you tell what is it, that I am missing?

Or is it just conventional stuff used in past in VB6 and C*?

Cor
It's just a convention. It's easier to use the sdk documentation when
you name them the same :)

--
Tom Shelton
Jun 27 '08 #5
I think I need a system wide hook. I'm reinventing the wheel by building my
own Context Menu. So if someone clicks anywhere while my context menu is
open I need to possibly hide the menu.

Any samples related to the menu would be a plus also.

I'm surprised there is not way to do this with-out using old API calls...

Thanks,
Schneider

"Jialiang Ge [MSFT]" <ji****@online. microsoft.comwr ote in message
news:%2******** ********@TK2MSF TNGHUB02.phx.gb l...
Hello Schneider,

From your post, my understanding on this issue is: how to hook the system
mouse down event in VB.NET. If I'm off base, please feel free to let me
know.

There are generally two different types of system hook: local system hook
(set a hook that is specific to a thread and to a hook procedure) and
global system hook (a system hook that is called when the specified
messages are processed by any application on the entire system.). Would
you
let me know which type of hook you referred to?

If you meant local system hook, I'd suggest the KB article
http://support.microsoft.com/kb/319524. The WH_MOUSE hook enables you to
monitor mouse messages about to be returned by the GetMessage or
PeekMessage function. You can use the WH_MOUSE hook to monitor mouse input
posted to a message queue. To modify the code in the KB to hook mouse down
event, we can add a Select Case wParam statement in MouseHookProc, and
check if wParam equals WM_RBUTTONDOWN or WM_RBUTTONUP.

If you meant global system hook, There are WH_MOUSE_LL hooks that can be
installed globally. The code in
http://www.colinneller.com/blog/Perm...c95-a322-b9ee5
918a39c.aspx provides an example in VB.NET, which exposes a OnMouseUp
event
we can utilize. For more readings about global system hook in .NET, please
refer to the codeproject article:
http://www.codeproject.com/KB/system...ystemhook.aspx
http://www.codeproject.com/KB/cs/globalhook.aspx

Let me know if you have any other concerns or questions.

Regards,
Jialiang Ge (ji****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jun 27 '08 #6
OK using :
http://www.colinneller.com/blog/Perm...e5918a39c.aspx
Could not get Tom's to work...

Works but now when I try to debug the application I get this error in VS
2008:

"The Miscrosoft Visual Studio Remote Debugging Monitor has been closed on
the remote machine."

And the app will not start, It will start outside of the debugger.

Thanks,
Schneider
"Jialiang Ge [MSFT]" <ji****@online. microsoft.comwr ote in message
news:%2******** ********@TK2MSF TNGHUB02.phx.gb l...
Hello Schneider,

From your post, my understanding on this issue is: how to hook the system
mouse down event in VB.NET. If I'm off base, please feel free to let me
know.

There are generally two different types of system hook: local system hook
(set a hook that is specific to a thread and to a hook procedure) and
global system hook (a system hook that is called when the specified
messages are processed by any application on the entire system.). Would
you
let me know which type of hook you referred to?

If you meant local system hook, I'd suggest the KB article
http://support.microsoft.com/kb/319524. The WH_MOUSE hook enables you to
monitor mouse messages about to be returned by the GetMessage or
PeekMessage function. You can use the WH_MOUSE hook to monitor mouse input
posted to a message queue. To modify the code in the KB to hook mouse down
event, we can add a Select Case wParam statement in MouseHookProc, and
check if wParam equals WM_RBUTTONDOWN or WM_RBUTTONUP.

If you meant global system hook, There are WH_MOUSE_LL hooks that can be
installed globally. The code in
http://www.colinneller.com/blog/Perm...c95-a322-b9ee5
918a39c.aspx provides an example in VB.NET, which exposes a OnMouseUp
event
we can utilize. For more readings about global system hook in .NET, please
refer to the codeproject article:
http://www.codeproject.com/KB/system...ystemhook.aspx
http://www.codeproject.com/KB/cs/globalhook.aspx

Let me know if you have any other concerns or questions.

Regards,
Jialiang Ge (ji****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jun 27 '08 #7
On Apr 30, 7:19*pm, "schneider" <eschnei...@com munity.nospamwr ote:
OK using :http://www.colinneller.com/blog/Perm...-f4af-4c95-a32...
Could not get Tom's to work...
Huh? It works fine here. Were you getting an error? What didn't
work....

--
Tom Shelton
Jun 27 '08 #8
On Apr 30, 10:47*pm, "schneider" <eschnei...@com munity.nospamwr ote:
No error, just never raised events. Maybe OS issue? I'm on XP 64
Interesting - since my code is almost identical, at least in the
particulars. I purposely wasn't handling much of the mouse stuff
simply because it was a sample. Unfortunately, I don't have an XP64
system to test on :)

--
Tom Shelton
Jun 27 '08 #9
On Wed, 30 Apr 2008 09:04:40 +0200, "Cor Ligthert[MVP]"
<no************ @planet.nlwrote :
>Nice sample, I always am curious why people are using for describing window
messages those UpperCase words.

I never saw any reason for that, however by that so frequent use of that, it
gives the idea that it is needed.

Can you tell what is it, that I am missing?

Or is it just conventional stuff used in past in VB6 and C*?
You might be interested in this site:
http://www.pinvoke.net/

as well as this article:
http://www.dmst.aueb.gr/dds/pubs/jrn.../html/win.html
esp. the section "Function Names and Naming Conventions".

If you have Visual Studio 6 installed, you might want to take a look
at
c:\Program Files\Microsoft Visual Studio\VC98\Inc lude\WINUSER.H
(or wherever such a file might be found elsewhere on your drive).

Or google for it, e.g.
http://doc.ddart.net/msdn/header/include/winuser.h.html

There are many other header files, but winuser.h along with wingdi.h
are the source of most of the Win32 API constant declarations you
are likely to come across when dealing with user interface programming
in Windows.

The use of all caps + underscores identifies them as Win32 API
constants. Something that comes from outside the safe .Net world.

Something inherently unsafe.

Something to be feared and treated with respect.

Those who need to work with them see no need to rename them just
to comply with .Net programming guidelines. That would just confuse
matters even more.

/Joergen Bech

PS: I take it that the name Dan Appleman means nothing to you?

Jun 27 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
19054
by: Mohammad | last post by:
Can someone explain to me what a hook is? Does it has something to do with a debugger? Thanks
5
7096
by: Logan Mckinley | last post by:
I need to know where the cursor is (x,y) and when it moves even when it is not over my form. I know i can get the current location with: System.Windows.Forms.Cursor.Position.X System.Windows.Forms.Cursor.Position.X But that does not raise an event and using a timer would be to processor intensive. In MFC you would write a mousehook to solve this problem but when i run the C# MouseHook code for from MSDN...
18
3069
by: jrhoads23 | last post by:
Hello, I am trying to find a way to tell if an .NET windows forms Button (System.Windows.Forms.Button) is "depressed" (pushed down). For my application, I can not use a check box control set to button style, I must use a System.Windows.Forms.Button. I can not find a way to tell when it is momentaraly pressed. I tried calling the API SendMessage with the button handle and BM_GETSTATE to get the state of the button. This will only return...
3
8426
by: june | last post by:
Hi, I am coding for an application with dialog window. I need intercept mouse input. I need catch raw input, pretty much everything for WM_INPUT: such as Left/Middle/Right button down/up, srcoll/wheel, pull and drag, device source. I checked SetWindowsHookEx, it seems it can't catch so much infor, only LButton RButton Down/Up? What function should I use or maybe I should ask how to hook Dialog box message Proc? Thanks
5
13121
by: Noozer | last post by:
I'm trying to write a small application that intercepts middle clicks anywhere in the Windows environment. I want to perform different actions, based on the application that the mouse pointer was over at the time of the middl click. How does one insert a hook into Windows for a VB 2005 to act on system mouse clicks? Thx
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.