为什么在xp环境在vb下用F5运行可以限制鼠标,而生成EXE文件后就不能限制鼠标移动范围那?
我先在模块中这样定义:
Public Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Declare Function SwapMouseButton Lib "user32" (ByVal bSwap As Long) As Long '决定是否互换鼠标左右键的功能
'交换按钮
'bswap为True时正常,为False时,互换
Public Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long '控制鼠标指针的可视性
'隐藏指针
'bShow为False时隐藏,为True时复原
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long '获取鼠标指针的当前位置
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long '设置指针的位置
Public Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long '判断窗口内以客户区坐标表示的一个点的屏幕坐标
Public Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long '将指针限制到指定区域。ClipCursorBynum是一个别名,允许我们清除以前设置的指针剪切区域
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '自己理解为调用库文件"kernel32.dll"的Sleep方法
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) '模拟一次鼠标事件
Public Sub clipto(toctl As Object) '自定义函数作用是:
On Error Resume Next
Dim tmprect As RECT
Dim pt As POINTAPI
With toctl
If TypeOf toctl Is Form Then
tmprect.Left = (.Left \ Screen.TwipsPerPixelX)
tmprect.Top = (.Top \ Screen.TwipsPerPixelY)
tmprect.Right = (.Left + .Width) \ Screen.TwipsPerPixelX
tmprect.Bottom = (.Top + .Height) \ Screen.TwipsPerPixelY
ElseIf TypeOf toctl Is Screen Then
tmprect.Left = 0
tmprect.Top = 0
tmprect.Right = (.Width \ Screen.TwipsPerPixelX)
tmprect.Bottom = (.Height \ Screen.TwipsPerPixelY)
Else
pt.x = 0
Call ClientToScreen(.hwnd, pt)
tmprect.Left = pt.x
tmprect.Top = pt.y
pt.x = .Width
pt.y = .Height
Call ClientToScreen(.hwnd, pt)
tmprect.Bottom = pt.y
tmprect.Right = pt.x
End If
End With
Call ClipCursor(tmprect)
End Sub
然后在程序中引用:
Dim s As Integer
Dim f As Integer
Dim xx, yy As Long
Dim pnt As POINTAPI
pnt.x = 0
pnt.y = 0
Me.Left = (Screen.Width - Me.Width) \ 2
Me.Top = (Screen.Height - Me.Height) \ 2
Call ClientToScreen(Me.hwnd, pnt)
xx = pnt.x + (Me.Width \ 2)
yy = pnt.y + (Me.Height \ 2)
Call SetCursorPos(xx, yy)
clipto Loads ' 把鼠标的活动范围缩小到loads范围内
s = 50
f = 50
SetWindowPos hwnd, -1, 0, 0, 0, 0, 3
生成的EXE文件在2000下也可以限制鼠标的移动,但是在XP下同样的EXE文件(而在vb下用F5运行是可以限制鼠标移动!!)就不能限制鼠标的移动了,为什么?
Public Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Declare Function SwapMouseButton Lib "user32" (ByVal bSwap As Long) As Long '决定是否互换鼠标左右键的功能
'交换按钮
'bswap为True时正常,为False时,互换
Public Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As Long '控制鼠标指针的可视性
'隐藏指针
'bShow为False时隐藏,为True时复原
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long '获取鼠标指针的当前位置
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long '设置指针的位置
Public Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long '判断窗口内以客户区坐标表示的一个点的屏幕坐标
Public Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long '将指针限制到指定区域。ClipCursorBynum是一个别名,允许我们清除以前设置的指针剪切区域
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '自己理解为调用库文件"kernel32.dll"的Sleep方法
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) '模拟一次鼠标事件
Public Sub clipto(toctl As Object) '自定义函数作用是:
On Error Resume Next
Dim tmprect As RECT
Dim pt As POINTAPI
With toctl
If TypeOf toctl Is Form Then
tmprect.Left = (.Left \ Screen.TwipsPerPixelX)
tmprect.Top = (.Top \ Screen.TwipsPerPixelY)
tmprect.Right = (.Left + .Width) \ Screen.TwipsPerPixelX
tmprect.Bottom = (.Top + .Height) \ Screen.TwipsPerPixelY
ElseIf TypeOf toctl Is Screen Then
tmprect.Left = 0
tmprect.Top = 0
tmprect.Right = (.Width \ Screen.TwipsPerPixelX)
tmprect.Bottom = (.Height \ Screen.TwipsPerPixelY)
Else
pt.x = 0
Call ClientToScreen(.hwnd, pt)
tmprect.Left = pt.x
tmprect.Top = pt.y
pt.x = .Width
pt.y = .Height
Call ClientToScreen(.hwnd, pt)
tmprect.Bottom = pt.y
tmprect.Right = pt.x
End If
End With
Call ClipCursor(tmprect)
End Sub
然后在程序中引用:
Dim s As Integer
Dim f As Integer
Dim xx, yy As Long
Dim pnt As POINTAPI
pnt.x = 0
pnt.y = 0
Me.Left = (Screen.Width - Me.Width) \ 2
Me.Top = (Screen.Height - Me.Height) \ 2
Call ClientToScreen(Me.hwnd, pnt)
xx = pnt.x + (Me.Width \ 2)
yy = pnt.y + (Me.Height \ 2)
Call SetCursorPos(xx, yy)
clipto Loads ' 把鼠标的活动范围缩小到loads范围内
s = 50
f = 50
SetWindowPos hwnd, -1, 0, 0, 0, 0, 3
生成的EXE文件在2000下也可以限制鼠标的移动,但是在XP下同样的EXE文件(而在vb下用F5运行是可以限制鼠标移动!!)就不能限制鼠标的移动了,为什么?
...全文
相关推荐
VB程序设计第1章PPT教案学习.pptx
VB的退出: - 用户可以通过菜单的“文件”->“退出”,点击标题栏的关闭按钮,或者使用快捷键Alt+F4来退出VB开发环境。4.
QBasic 7完美版揭秘:从DOSBox到QB64的怀旧编程指南
在编程启蒙的长河中,BASIC语言以其简洁直观的语法,成为无数开发者的第一块敲门砖。从早期的QBasic到功能更全面的QuickBasic,再到鲜为人知的QuickBasic Extended(即俗称的“QBasic 7完美版”),这条技术脉络见证了DOS时代编程工具的演进。理解其身份由来与运行原理,不仅能解开版本号的谜团,更能体会早期图形编程与结构化设计的核心思想。借助DOSBox模拟器,我们可以在现代系统中还原当年的蓝色界面,运行画圆、正弦动画等经典示例,直观感受直接操作显存与控制循环的底层魅力。而对追
8.4 SmartCheck调试工具.pdf
**加载程序**:使用SmartCheck打开目标程序,如String.exe。2. **启动调试**:通过菜单`Program > Start`、按F5键或点击工具栏上的相应按钮来启动调试过程。
2012江苏职称计算机IT信息化考试操作题(WindowsXP).pdf
切换鼠标左右键功能在Windows XP中,可以通过控制面板来改变鼠标左右键的功能。
Delphi7开发基础教程
- 需要有CD-ROM驱动器、VGA或更高性能的显示器以及鼠标等外设。- **软件要求**: - 支持的操作系统包括Microsoft Windows 98、2000、XP等。


API
