home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Mouse_Sens20941612172007.psc / frmMain.frm < prev    next >
Text File  |  2007-12-17  |  13KB  |  420 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMain 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Azza's Mouse Profile Manager"
  5.    ClientHeight    =   1440
  6.    ClientLeft      =   150
  7.    ClientTop       =   540
  8.    ClientWidth     =   4680
  9.    Icon            =   "frmMain.frx":0000
  10.    KeyPreview      =   -1  'True
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   1440
  15.    ScaleWidth      =   4680
  16.    ShowInTaskbar   =   0   'False
  17.    StartUpPosition =   3  'Windows Default
  18.    WindowState     =   1  'Minimized
  19.    Begin VB.PictureBox PictureHelp 
  20.       Appearance      =   0  'Flat
  21.       AutoSize        =   -1  'True
  22.       BackColor       =   &H80000000&
  23.       BorderStyle     =   0  'None
  24.       ForeColor       =   &H80000008&
  25.       Height          =   360
  26.       Left            =   4200
  27.       Picture         =   "frmMain.frx":E968
  28.       ScaleHeight     =   360
  29.       ScaleWidth      =   360
  30.       TabIndex        =   3
  31.       Top             =   960
  32.       Width           =   360
  33.    End
  34.    Begin VB.Timer TimerUpdateMenu 
  35.       Enabled         =   0   'False
  36.       Interval        =   50
  37.       Left            =   2640
  38.       Top             =   960
  39.    End
  40.    Begin VB.HScrollBar HScrollMouseSpeed 
  41.       Height          =   375
  42.       Left            =   1320
  43.       Max             =   20
  44.       TabIndex        =   1
  45.       Top             =   480
  46.       Width           =   3255
  47.    End
  48.    Begin VB.ComboBox ComboUsers 
  49.       Height          =   315
  50.       ItemData        =   "frmMain.frx":F052
  51.       Left            =   1320
  52.       List            =   "frmMain.frx":F059
  53.       TabIndex        =   0
  54.       Top             =   120
  55.       Width           =   3255
  56.    End
  57.    Begin VB.Label Label2 
  58.       Alignment       =   1  'Right Justify
  59.       AutoSize        =   -1  'True
  60.       Caption         =   "Mouse Speed:"
  61.       Height          =   195
  62.       Left            =   120
  63.       TabIndex        =   5
  64.       Top             =   600
  65.       Width           =   1035
  66.    End
  67.    Begin VB.Label Label1 
  68.       Alignment       =   1  'Right Justify
  69.       AutoSize        =   -1  'True
  70.       Caption         =   "User:"
  71.       Height          =   195
  72.       Left            =   120
  73.       TabIndex        =   4
  74.       Top             =   150
  75.       Width           =   375
  76.    End
  77.    Begin VB.Label LabelStatus 
  78.       Height          =   375
  79.       Left            =   0
  80.       TabIndex        =   2
  81.       Top             =   960
  82.       Width           =   4575
  83.    End
  84.    Begin VB.Menu Popup 
  85.       Caption         =   "Popup"
  86.       Visible         =   0   'False
  87.       Begin VB.Menu Users 
  88.          Caption         =   "Users"
  89.          Index           =   0
  90.       End
  91.       Begin VB.Menu Break 
  92.          Caption         =   "-"
  93.       End
  94.       Begin VB.Menu Help 
  95.          Caption         =   "Help"
  96.       End
  97.       Begin VB.Menu Exit 
  98.          Caption         =   "Exit"
  99.       End
  100.    End
  101. End
  102. Attribute VB_Name = "frmMain"
  103. Attribute VB_GlobalNameSpace = False
  104. Attribute VB_Creatable = False
  105. Attribute VB_PredeclaredId = True
  106. Attribute VB_Exposed = False
  107. 'Small program to set mouse speed profiles for different users
  108. 'My kids and I want different mouse speeds when we use the computer - thought this might be a decent solution
  109.  
  110. 'uses Message Alerter (http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=4503&lngWId=1)
  111. 'to handle tray icon functions.
  112.  
  113. 'mouse set/get speed API declarations
  114. Private Declare Function SystemParametersInfo Lib "user32" Alias _
  115.     "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, _
  116.     ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
  117. Const SPI_SETMOUSESPEED = 113
  118. Const SPI_GETMOUSESPEED = 112
  119.  
  120. 'listbox/combobox search API declarations
  121. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal _
  122.     hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
  123.     lParam As Any) As Long
  124. Const LB_FINDSTRING = &H18F
  125. Const LB_FINDSTRINGEXACT = &H1A2
  126. Const CB_FINDSTRING = &H14C
  127. Const CB_FINDSTRINGEXACT = &H158
  128.  
  129. 'API's for getting taskbar size
  130. 'from http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=23892&lngWId=1
  131. Private Const SPI_GETWORKAREA = 48
  132. Private Type RECT
  133.     Left As Long
  134.     Top As Long
  135.     Right As Long
  136.     Bottom As Long
  137. End Type
  138.  
  139. 'trayicon variables
  140. Public IconObject As Object
  141.  
  142. Private Sub SetMouseSpeed(lngSpeed As Long)
  143.     'mouse speed range 0-20
  144.     If lngSpeed < 0 Then
  145.         lngSpeed = 0
  146.     ElseIf lngSpeed > 20 Then
  147.         lngSpeed = 20
  148.     End If
  149.  
  150.     SystemParametersInfo SPI_SETMOUSESPEED, 0, ByVal lngSpeed, 0
  151. End Sub
  152.  
  153. Private Function GetMouseSpeed() As Long
  154.     Dim Speed As Long
  155.     ' note that Speed is passed ByRef
  156.     SystemParametersInfo SPI_GETMOUSESPEED, 0, Speed, 0
  157.     GetMouseSpeed = Speed
  158. End Function
  159.  
  160.  
  161. Private Sub ComboUsers_LostFocus()
  162.     Dim lngIndex As Long
  163.  
  164.     'check if we have this user name
  165.     lngIndex = ListBoxFindString(ComboUsers, ComboUsers.Text)
  166.     If lngIndex = -1 Then
  167.         'add user to popup menu
  168.         RemoveStatusFromMenu
  169.         Load Users(Users.Count)
  170.         Users(Users.Count - 1).Caption = ComboUsers.Text
  171.         
  172.         'add new user
  173.         ComboUsers.AddItem ComboUsers.Text
  174.  
  175.         'add default value for new user
  176.         HScrollMouseSpeed.Value = 10
  177.         UpdateUserSpeed ComboUsers.Text, HScrollMouseSpeed.Value
  178.         
  179.  
  180.         UpdateStatus ComboUsers.Text
  181.     Else
  182.         'go to selected user
  183.         ComboUsers.ListIndex = lngIndex
  184.     End If
  185.     
  186.     'remember currently selected user
  187.     SaveSetting "Azza's Mouse Settings", "Current", "User", ComboUsers.Text
  188.     
  189.     UpdateStatus ComboUsers.Text
  190. End Sub
  191.  
  192. Private Sub ComboUsers_Click()
  193.     SelectUser ComboUsers.Text
  194.  
  195.     'set this user as default
  196.     SaveSetting "Azza's Mouse Settings", "Current", "User", ComboUsers.Text
  197. End Sub
  198.  
  199. Private Sub Help_Click()
  200.     Dim strText As String
  201.     
  202.     strText = "Azza's Mouse Manager" & vbNewLine & vbNewLine & _
  203.     "A simple program to allow easy selection between mouse speed profiles for different users." & vbNewLine & _
  204.     "Left-Click on the traybar icon to open the main screen." & vbNewLine & _
  205.     "For each user profile, simply type a user name into the selection box, and then select an associated mouse speed." & vbNewLine & _
  206.     "Press <Delete> to remove a user." & vbNewLine & vbNewLine & _
  207.     "For easy profile selection, right-click on the traybar icon."
  208.     
  209.     MsgBox strText
  210. End Sub
  211.  
  212. Private Sub Exit_Click()
  213.     Unload Me
  214. End Sub
  215.  
  216. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  217.     Dim lngIndex As Long
  218.     
  219.     If KeyCode = 46 Then
  220.         'indicated to delete user
  221.                            
  222.         'don't allow deletion of default user
  223.         If ComboUsers.Text <> "<default>" Then
  224.  
  225.             'make sure combobox entry is valid
  226.             lngIndex = ListBoxFindString(ComboUsers, ComboUsers.Text)
  227.             If lngIndex <> -1 Then
  228.                 DeleteSetting "Azza's Mouse Settings", "User", ComboUsers.Text
  229.                 ComboUsers.RemoveItem (lngIndex)
  230.                 
  231.                 'select default as new user
  232.                 ComboUsers.ListIndex = 0
  233.             End If
  234.         End If
  235.     End If
  236. End Sub
  237.  
  238. Private Sub Form_Load()
  239.     Dim strCurrentUser As String
  240.     Dim varSettings As Variant
  241.     
  242.     Me.Left = -100000
  243.     
  244.     'set trayicon
  245.     Set IconObject = frmMain.Icon
  246.     AddIcon frmMain, IconObject.Handle, IconObject, "Azza's Mouse Manager"
  247.  
  248.     
  249.     'get list of users
  250.     varSettings = GetAllSettings("Azza's Mouse Settings", "User")
  251.     'populate user list to combo box
  252.     If IsEmpty(varSettings) = False Then
  253.     For i = 0 To UBound(varSettings)
  254.         If varSettings(i, 0) <> "<default>" Then
  255.             ComboUsers.AddItem varSettings(i, 0)
  256.         End If
  257.  
  258.         'add user to menu
  259.         If i > 0 Then
  260.             Load Users(i)
  261.         End If
  262.         Users(i).Caption = varSettings(i, 0)
  263.     Next i
  264.     End If
  265.     
  266.     'get current user
  267.     strCurrentUser = GetSetting("Azza's Mouse Settings", "Current", "User", "<default>")
  268.     If ListBoxFindString(ComboUsers, strCurrentUser) = -1 Then
  269.         'last user not found - user default
  270.         strCurrentUser = "<default>"
  271.     End If
  272.     
  273.     'setup user
  274.     SelectUser strCurrentUser
  275.         
  276.     ComboUsers.ListIndex = ListBoxFindString(ComboUsers, strCurrentUser)
  277.  
  278.     UpdateStatus strCurrentUser
  279.     
  280.     Me.Hide
  281. End Sub
  282.  
  283. Private Sub SelectUser(strCurrentUser As String)
  284.     Dim lngSpeed As Long
  285.     
  286.     'get mouse speed for current user
  287.     lngSpeed = Val(GetSetting("Azza's Mouse Settings", "User", strCurrentUser, -1))
  288.     If lngSpeed = -1 Then
  289.         'no setting saved - probably first time program loaded
  290.         
  291.         'get current mouse speed
  292.         lngSpeed = GetMouseSpeed
  293.         
  294.         'save <default> setting with current mouse speed
  295.         UpdateUserSpeed strCurrentUser, lngSpeed
  296.  
  297.     End If
  298.         
  299.     'set scroll bar to user mouse speed
  300.     HScrollMouseSpeed.Value = lngSpeed
  301.     
  302.     UpdateStatus strCurrentUser
  303. End Sub
  304.  
  305. Private Sub UpdateUserSpeed(strUserName As String, lngUserSpeed As Long)
  306.     'remember mouse speed setting for this user
  307.     SaveSetting "Azza's Mouse Settings", "User", strUserName, lngUserSpeed
  308. End Sub
  309.  
  310. Private Sub Form_Unload(Cancel As Integer)
  311.     'clean up trayicon
  312.     delIcon IconObject.Handle
  313.     delIcon frmMain.Icon.Handle
  314. End Sub
  315.  
  316. Private Sub HScrollMouseSpeed_Change()
  317.     SetMouseSpeed HScrollMouseSpeed.Value
  318.     
  319.     UpdateStatus ComboUsers.Text
  320. End Sub
  321.  
  322. Private Sub HScrollMouseSpeed_Scroll()
  323.     SetMouseSpeed HScrollMouseSpeed.Value
  324.     
  325.     'remember mouse speed for this user
  326.     UpdateUserSpeed ComboUsers.Text, HScrollMouseSpeed.Value
  327.     
  328.     UpdateStatus ComboUsers.Text
  329. End Sub
  330.  
  331. Private Sub UpdateStatus(strUser As String)
  332.     LabelStatus.Caption = "User: " & strUser & "   Current Speed: " & (HScrollMouseSpeed.Value * 5) & "%"
  333.  
  334.     TimerUpdateMenu.Enabled = True
  335. End Sub
  336.  
  337. Private Sub OutputStatusToMenu()
  338.     'update status in menu
  339.     RemoveStatusFromMenu
  340.  
  341.     'add status message to menu
  342.     Load Users(Users.Count)
  343.     Users(Users.Count - 1).Caption = "-"
  344.     Load Users(Users.Count)
  345.     Users(Users.Count - 1).Caption = LabelStatus.Caption
  346. End Sub
  347.  
  348. Private Sub RemoveStatusFromMenu()
  349.     'looks for and removes status from menu
  350.     
  351.     'look for seperator - the current status will be below seperator
  352.     For i = Users.Count - 1 To 0 Step -1
  353.         If Users.Item(i).Caption = "-" Then
  354.             Do Until Users.Count - 1 < i
  355.                 'seperator found - delete all from here on
  356.                 Unload Users.Item(Users.Count - 1)
  357.             Loop
  358.             Exit For
  359.         End If
  360.     Next i
  361. End Sub
  362.  
  363. 'use SendMessage to search ListBox/ComboBox
  364. 'from http://www.devx.com/vb2themax/Tip/19121
  365. Function ListBoxFindString(ctrl As Control, ByVal search As String, _
  366.     Optional startIndex As Long = -1, Optional ExactMatch As Boolean) As Long
  367.     Dim uMsg As Long
  368.     If TypeOf ctrl Is ListBox Then
  369.         uMsg = IIf(ExactMatch, LB_FINDSTRINGEXACT, LB_FINDSTRING)
  370.     ElseIf TypeOf ctrl Is ComboBox Then
  371.         uMsg = IIf(ExactMatch, CB_FINDSTRINGEXACT, CB_FINDSTRING)
  372.     Else
  373.         Exit Function
  374.     End If
  375.     ListBoxFindString = SendMessage(ctrl.hwnd, uMsg, startIndex, ByVal search)
  376. End Function
  377.  
  378. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  379.     Static Message As Long
  380.     Message = X / Screen.TwipsPerPixelX
  381.     Select Case Message
  382.         Case WM_LBUTTONUP:
  383.             'show whole interface - bottom right
  384.             Me.WindowState = vbNormal
  385.             Me.Left = Screen.Width - Me.Width
  386.             Me.Top = Screen.Height - Me.Height - GetTaskbarHeight
  387.             Me.Show
  388.         Case WM_RBUTTONUP:
  389.             'show user list
  390.             Me.Hide
  391.             Me.PopupMenu Popup
  392.  
  393.     End Select
  394. End Sub
  395.  
  396. Public Function GetTaskbarHeight() As Integer
  397.     Dim lRes As Long
  398.     Dim rectVal As RECT
  399.     
  400.     lRes = SystemParametersInfo(SPI_GETWORKAREA, 0, rectVal, 0)
  401.     GetTaskbarHeight = ((Screen.Height / Screen.TwipsPerPixelX) - rectVal.Bottom) * Screen.TwipsPerPixelX
  402. End Function
  403.  
  404. Private Sub PictureHelp_Click()
  405.     Help_Click
  406. End Sub
  407.  
  408. Private Sub TimerUpdateMenu_Timer()
  409.     TimerUpdateMenu.Enabled = False
  410.     OutputStatusToMenu
  411. End Sub
  412.  
  413. Private Sub Users_Click(Index As Integer)
  414.     SelectUser Users.Item(Index).Caption
  415.  
  416.     'set this user as default
  417.     SaveSetting "Azza's Mouse Settings", "Current", "User", Users.Item(Index).Caption
  418.  
  419. End Sub
  420.