|| 您现在的位置: 天下无挂网 >> 外挂文章 >> 程序编程技术 >> 外挂文章正文
:: 用户登录 ::

 
:: 专 题 栏 目 ::
:: 最新热门 ::
  • 没有热门外挂文章
  • :: 相关文章 ::
    没有相关外挂文章

    锁定鼠标在指定区域
    作者:不详 文章来源:不详 点击数: 更新时间:2005-8-21

    用API函数可以将鼠标锁定在窗体内,或锁定在一个可接受焦点的控件内。
      在窗体放置两个命令按钮Command1和Command2,分别用来执行鼠标锁定在图片框内和锁定在窗体内;再放置一个图片框。将下面代码复制到窗体代码窗口内。
    Option Explicit
    Private Sub Command1_Click()
    '将鼠标限制在PictureBox中
    RestrictToControl Picture1
    CenterOnControl Picture1
    End Sub

    Private Sub Command2_Click()
    '将鼠标限制在窗体中
    RestrictToForm Me
    CenterOnForm Me
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    '结束程序
    Release
    End Sub

    Private Sub Picture1_Click()
    '单击图片框释放鼠标
    Release
    End Sub

      下面是代码处理模块部分,可将其保存为一个.bas文件,也可以插入到一个现有的模块代码中。模块中的代码是通用的,可以配合你的任意一个应用程序,只需要按上面主程序代码那样调用即可。
    Option Explicit
    Private Type RECT
    left As Long
    top As Long
    right As Long
    bottom As Long
    End Type
    Private Declare Function SetCursorPos Lib "user32" _
    (ByVal x As Long, ByVal y As Long) As Long
    Private Declare Function ClipCursor Lib "user32" _
    (lpRect As Any) As Long
    Private Declare Function GetWindowRect Lib "user32" _
    (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function GetSystemMetrics Lib "user32" _
    (ByVal nIndex As Long) As Long
    Private Const SM_CYCAPTION = 4
    Private Const SM_CXFRAME = 32
    Private Const SM_CYFRAME = 33

    Public Sub Release()
    Call ClipCursor(ByVal vbNullString)
    End Sub

    Public Sub RestrictToControl(cntl As Control)
    Dim r As RECT
    On Error Resume Next
    Call GetWindowRect((cntl.hwnd), r)
    If Err.Number = 0 Then
    Call RestrictToRect(r)
    End If
    End Sub

    Public Sub CenterOnControl(cntl As Control)
    Dim r As RECT
    On Error Resume Next
    Call GetWindowRect((cntl.hwnd), r)
    If Err.Number = 0 Then
    CenterOnRect r
    End If
    End Sub

    Public Sub RestrictToForm(frm As Form)
    Dim r As RECT
    Call GetClientScrnRect(frm, r)
    Call RestrictToRect(r)
    End Sub

    Public Sub CenterOnForm(frm As Form)
    Dim r As RECT
    Call GetClientScrnRect(frm, r)
    Call CenterOnRect(r)
    End Sub

    Private Sub RestrictToRect(lpRect As RECT)
    Call ClipCursor(lpRect)
    End Sub

    Private Sub CenterOnRect(lpRect As RECT)
    Call SetCursorPos(lpRect.left + (lpRect.right - lpRect.left) \ 2, _
    lpRect.top + (lpRect.bottom - lpRect.top) \ 2)
    End Sub

    Private Sub GetClientScrnRect(frm As Form, rC As RECT)
    Dim x As Integer
    Dim y As Integer
    Call GetWindowRect((frm.hwnd), rC)
    x = GetSystemMetrics(SM_CXFRAME)
    y = GetSystemMetrics(SM_CYFRAME)
    rC.left = rC.left + x
    rC.right = rC.right - x
    rC.top = rC.top + y + GetSystemMetrics(SM_CYCAPTION)
    rC.bottom = rC.bottom - y
    End Sub

    外挂文章录入:admin    责任编辑:admin 
  • 上一篇外挂文章:

  • 下一篇外挂文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口

    点击申请点击申请点击申请点击申请点击申请点击申请
    点击申请点击申请点击申请点击申请点击申请点击申请点击申请

    版权所有 Copyright? 2004-2008 天下无挂科技网 网站维护:GHOST
    网站域名:http://www.watxwg.com
    客服邮箱:txwgwa@163.com
    客服电话:13810978321
    客服 Q Q:12439470