home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / source / chap22 / movmouse.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-24  |  1.8 KB  |  63 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   2280
  5.    ClientLeft      =   3105
  6.    ClientTop       =   7080
  7.    ClientWidth     =   5145
  8.    Height          =   2685
  9.    Left            =   3045
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   2280
  12.    ScaleWidth      =   5145
  13.    Top             =   6735
  14.    Width           =   5265
  15.    Begin VB.CommandButton Command2 
  16.       Caption         =   "Command2"
  17.       Height          =   495
  18.       Left            =   2520
  19.       TabIndex        =   1
  20.       Top             =   960
  21.       Width           =   1215
  22.    End
  23.    Begin VB.CommandButton Command1 
  24.       Caption         =   "Command1"
  25.       Height          =   495
  26.       Left            =   840
  27.       TabIndex        =   0
  28.       Top             =   960
  29.       Width           =   1215
  30.    End
  31. Attribute VB_Name = "Form1"
  32. Attribute VB_Creatable = False
  33. Attribute VB_Exposed = False
  34. Private Type POINTAPI
  35.         x As Long
  36.         y As Long
  37. End Type
  38. Private Type RECT
  39.         left As Long
  40.         top As Long
  41.         Right As Long
  42.         Bottom As Long
  43. End Type
  44. Private Declare Function SetCursorPos Lib "user32" _
  45.     (ByVal x As Long, ByVal y As Long) As Long
  46. Private Declare Function GetWindowRect Lib "user32" _
  47.     (ByVal hwnd As Long, lpRect As RECT) As Long
  48. Dim p As POINTAPI
  49. Dim r As RECT
  50. Dim rWidth As Long, rHeight As Long
  51. Private Sub Command1_Click()
  52.     GetWindowRect Command2.hwnd, r
  53.     rWidth = r.Right - r.left
  54.     rHeight = r.Bottom - r.top
  55.     SetCursorPos r.left + (rWidth / 2), r.top + (rHeight / 2)
  56. End Sub
  57. Private Sub Command2_Click()
  58.     GetWindowRect Command1.hwnd, r
  59.     rWidth = r.Right - r.left
  60.     rHeight = r.Bottom - r.top
  61.     SetCursorPos r.left + (rWidth / 2), r.top + (rHeight / 2)
  62. End Sub
  63.