• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    怎樣利用VB限制鼠標移動

    發布: 2007-7-14 20:28 | 作者: 佚名    | 來源: 網絡轉載     | 查看: 45次 | 進入軟件測試論壇討論

    領測軟件測試網   本文介紹如何限制鼠標在窗口的指定范圍內移動。這個技術在需要防止用戶鼠標在指定區域內活動時非常
    有用。例如在一個射擊游戲中,需要限制鼠標在射擊區內移動。
    操作步驟
    1、建立一個新工程項目,缺省建立窗體FORM1
    2、添加一個新模體
    3、粘貼下面代碼到新模體

    Option ExplicitDeclare Function ClipCursor Lib "user32" (lpRect As Any) As Long
    Declare Function ClipCursorClear Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long) As Long
    Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type
    Type POINTAPI
    X As Long
    Y As Long
    End Type
    Public RetValue As Long
    Public ClipMode As Boolean


    Public Sub SetCursor(ClipObject As Object, Setting As Boolean)
    ' used to clip the cursor into the viewport and
    ' turn off the default windows cursor


    Dim CurrentPoint As POINTAPI
    Dim ClipRect As RECT


    If Setting = False Then
    ' set clip state back to normal
    RetValue = ClipCursorClear(0)
    Exit Sub
    End If


    ' set current position
    With CurrentPoint
    ..X = 0
    ..Y = 0
    End With
    ' find position on the screen (not the window)
    RetValue = ClientToScreen(ClipObject.hwnd, CurrentPoint)
    ' designate clip area
    With ClipRect
    ..Top = CurrentPoint.Y
    ..Left = CurrentPoint.X
    ..Right = .Left + ClipObject.ScaleWidth
    ..Bottom = .Top + ClipObject.ScaleHeight
    End With ' clip it
    RetValue = ClipCursor(ClipRect)


    End Sub


    4、添加一個圖片框控件(PICTURE1)到窗體(FORM1)
    5、設置PICTURE1的尺寸和FORM1的一樣大
    6、在PICTURE1的CLICK事件中添加以下代碼:


    Private Sub Picture1_Click()
    ClipMode = Not ClipMode
    SetCursor Picture1, ClipMode
    End Sub


    7、保存工程項目
    8、運行程序。在圖片框單擊鼠標,鼠標將被包含在圖片框控件的區域內。要釋放限制狀態只需再次單擊鼠標。
    注意:如果釋放限制狀態失敗,鼠標將被永久限制,只能用重新啟動機器來解決。
    另一個限制鼠標活動范圍的方法是關閉鼠標,用其他圖象代替光標,例如手槍。

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>