Private Declare Function SetSystemParametersInfo Lib "user32" Alias _
"SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, _
ByVal lpvParam As Integer, ByVal fuWinIni As Integer) As Integer
Private Declare Function GetSystemParametersInfo Lib "user32" Alias _
"SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, _
ByRef lpvParam As Integer, ByVal fuWinIni As Integer) As Integer
Dim tracking As Boolean
GetSystemParametersInfo(SPI_GETACTIVEWINDOWTRACKING, 0, tracking, 0)
MessageBox.Show("tracking = " & tracking)
Dim newState As Boolean = True ' True = On, False = Off
SetSystemParametersInfo(SPI_SETACTIVEWINDOWTRACKING, 0, newState, 0)
SetSystemParametersInfo(SPI_SETACTIVEWNDTRKTIMEOUT, 0, 350, 0)
Public Class XMouse
Private Const SPI_GETACTIVEWINDOWTRACKING As Integer = &H1000
Private Const SPI_SETACTIVEWINDOWTRACKING As Integer = &H1001
Private Const SPI_GETACTIVEWNDTRKTIMEOUT As Integer = &H2002
Private Const SPI_SETACTIVEWNDTRKTIMEOUT As Integer = &H2003
Private Const SPI_GETACTIVEWNDTRKZORDER As Integer = &H100C
Private Const SPI_SETACTIVEWNDTRKZORDER As Integer = &H100D
Private Const SPIF_SENDCHANGE As Integer = &H2
Private Const SPIF_UPDATEINIFILE As Integer = &H1
' Used for Retrieving values, note though "ByRef" for lpvParam!
Private Declare Function GetSystemParametersInfo Lib "user32" Alias _
"SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, _
ByRef lpvParam As Integer, ByVal fuWinIni As Integer) As Integer
' Used for Setting values, note though "ByVal" for lpvParam!
Private Declare Function SetSystemParametersInfo Lib "user32" Alias _
"SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer, _
ByVal lpvParam As Integer, ByVal fuWinIni As Integer) As Integer
Public Class XSettings
Public IsTracking As Boolean
Public DelayInMilliseconds As Integer
Public BringToFront As Boolean
Public Sub New()
End Sub
Public Sub New(ByVal IsTracking As Boolean, ByVal DelayInMilliseconds As Integer, ByVal BringToFront As Boolean)
Me.IsTracking = IsTracking
Me.DelayInMilliseconds = DelayInMilliseconds
Me.BringToFront = BringToFront
End Sub
Public Overrides Function ToString() As String
Return "IsTracking = " & IsTracking & ", DelayInMilliseconds = " & DelayInMilliseconds & ", BringToFront = " & BringToFront
End Function
End Class
Public Shared Property IsTracking() As Boolean
Get
Dim tracking As Boolean
GetSystemParametersInfo(SPI_GETACTIVEWINDOWTRACKING, 0, tracking, 0)
Return tracking
End Get
Set(value As Boolean)
SetSystemParametersInfo(SPI_SETACTIVEWINDOWTRACKING, 0, value, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE)
End Set
End Property
Public Shared Property DelayInMilliseconds() As Integer
Get
Dim timeout As Integer
GetSystemParametersInfo(SPI_GETACTIVEWNDTRKTIMEOUT, 0, timeout, 0)
Return timeout
End Get
Set(value As Integer)
If value >= 0 AndAlso value <= 2000 Then
SetSystemParametersInfo(SPI_SETACTIVEWNDTRKTIMEOUT, 0, value, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE)
End If
End Set
End Property
Public Shared Property BringToFront() As Boolean
Get
Dim raise As Boolean
GetSystemParametersInfo(SPI_GETACTIVEWNDTRKZORDER, 0, raise, 0)
Return raise
End Get
Set(value As Boolean)
SetSystemParametersInfo(SPI_SETACTIVEWNDTRKZORDER, 0, value, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE)
End Set
End Property
Public Shared Property Settings() As XSettings
Get
Dim values As New XSettings
values.IsTracking = XMouse.IsTracking
values.DelayInMilliseconds = XMouse.DelayInMilliseconds
values.BringToFront = XMouse.BringToFront
Return values
End Get
Set(value As XSettings)
XMouse.IsTracking = value.IsTracking
XMouse.DelayInMilliseconds = value.DelayInMilliseconds
XMouse.BringToFront = value.BringToFront
End Set
End Property
End Class
XMouse.IsTracking = True ' Turn it on
XMouse.IsTracking = False ' Turn it off
Private Sub ContextMenuStrip1_Opening(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
XMouseActiveTrackingToolStripMenuItem.Checked = XMouse.IsTracking
End Sub
XMouse.DelayInMilliseconds = 350
XMouse.BringToFront = True ' Turn it on
XMouse.BringToFront = False ' Turn it off
Public Class Form1
Private Const WM_SETTINGCHANGE As Integer = &H1A
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case WM_SETTINGCHANGE
Me.RefreshSettings()
End Select
MyBase.WndProc(m)
End Sub
Private Sub RefreshSettings()
Dim xSettings As XMouse.XSettings = XMouse.Settings
Me.cbActiveTracking.Checked = xSettings.IsTracking
Me.nudDelay.Value = xSettings.DelayInMilliseconds
Me.cbBringToFront.Checked = xSettings.BringToFront
End Sub
End Class
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)