下面是把鼠标锁定在WAR III内的代码.
但是如果当魔兽窗口化的时候.魔兽游戏窗口在任务栏的下面.
再锁定鼠标.把鼠标移动下来的时候会点到任务栏.
--------------------------------------------------------------------------------------------------
'把鼠标锁定在魔兽内
IsWork = Not IsWork If IsWork Then
Dim pt As POINTAPI, hWindow As Long
hWindow = FindWindow("Warcraft III", vbNullString) Call GetClientRect(hWindow, rtCustomForm)
With rtCustomForm
pt.x = .Left: pt.y = .top '转换左上角坐标为屏幕坐标
Call ClientToScreen(hWindow, pt)
.Left = pt.x: .top = pt.y
pt.x = .Right: pt.y = .Bottom '转换右下角坐标为屏幕坐标
Call ClientToScreen(hWindow, pt)
.Right = pt.x: .Bottom = pt.y
End With
Call ClipCursor(rtCustomForm)
Form1.Caption = Form1.Caption
Else
Call ClipCursor(ByVal 0&)
Form1.Caption = Form1.Caption
End If
--------------------------------------------------------------------------------------------------用下面这段代码.是可以把鼠标锁定在任务栏上面的.
请问这两段代码要怎么才可以合起来使用呢?
--------------------------------------------------------------------------------------------------
'把鼠标锁定在任务栏上方
Dim rectRect As RECT
rectRect.Left = 0
rectRect.top = 0
rectRect.Right = Screen.Width / 15
rectRect.Bottom = Screen.Height / 15 - GetTrayHeight
ClipCursor rectRect
--------------------------------------------------------------------------------------------------
但是如果当魔兽窗口化的时候.魔兽游戏窗口在任务栏的下面.
再锁定鼠标.把鼠标移动下来的时候会点到任务栏.
--------------------------------------------------------------------------------------------------
'把鼠标锁定在魔兽内
IsWork = Not IsWork If IsWork Then
Dim pt As POINTAPI, hWindow As Long
hWindow = FindWindow("Warcraft III", vbNullString) Call GetClientRect(hWindow, rtCustomForm)
With rtCustomForm
pt.x = .Left: pt.y = .top '转换左上角坐标为屏幕坐标
Call ClientToScreen(hWindow, pt)
.Left = pt.x: .top = pt.y
pt.x = .Right: pt.y = .Bottom '转换右下角坐标为屏幕坐标
Call ClientToScreen(hWindow, pt)
.Right = pt.x: .Bottom = pt.y
End With
Call ClipCursor(rtCustomForm)
Form1.Caption = Form1.Caption
Else
Call ClipCursor(ByVal 0&)
Form1.Caption = Form1.Caption
End If
--------------------------------------------------------------------------------------------------用下面这段代码.是可以把鼠标锁定在任务栏上面的.
请问这两段代码要怎么才可以合起来使用呢?
--------------------------------------------------------------------------------------------------
'把鼠标锁定在任务栏上方
Dim rectRect As RECT
rectRect.Left = 0
rectRect.top = 0
rectRect.Right = Screen.Width / 15
rectRect.Bottom = Screen.Height / 15 - GetTrayHeight
ClipCursor rectRect
--------------------------------------------------------------------------------------------------
看不出来有什么实际作用啊?ALT+TAB . 行么?
Call GetClientRect(hWindow, rtCustomForm)With rtCustomForm
pt.x = .Left: pt.y = .top '转换左上角坐标为屏幕坐标
Call ClientToScreen(hWindow, pt)
.Left = pt.x: .top = pt.ypt.x = .Right: pt.y = .Bottom '转换右下角坐标为屏幕坐标
Call ClientToScreen(hWindow, pt)
.Right = pt.x: .Bottom = pt.y
End With
Call ClipCursor(rtCustomForm)
Form1.Caption = Form1.Caption
Else
Call ClipCursor(ByVal 0&)
Form1.Caption = Form1.Caption
End If
Private Declare Function GetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As Long, lpRect As RECT) As Long【说明】
返回指定窗口客户区矩形的大小 【返回值】
Long,非零表示成功,零表示失败。会设置GetLastError 【备注】
lpRect的左侧及顶部区域肯定会被这个函数设为零【参数表】
hwnd ----------- Long,欲计算大小的目标窗口 lpRect --------- RECT,指定一个矩形,用客户区域的大小载入(以像素为单位)
Dim tyWC As RECT, tyWind As RECT
Dim frameW As Long, titleH As Long
Dim hWcHand As Long
If Not WarRun Then Exit Sub
hWcHand = GetForegroundWindow
Call GetWindowRect(hWcHand, tyWC) '获得魔兽的窗口位置
Call GetClientRect(hWcHand, tyWind) '获得魔兽窗口客户区,Left,Top 都被置0,也就是矩形被移到左上角
'下面构建客户区的RECT,结果放在 tyWC 里面
frameW = (tyWC.Right - tyWC.Left - tyWind.Right) / 2
titleH = tyWC.Bottom - tyWC.Top - tyWind.Bottom - 2 * frameW
With tyWC
.Top = .Top + frameW + titleH
.Bottom = .Bottom - frameW
.Left = .Left + frameW
.Right = .Right - frameW
End With Call ClipCursor(tyWC)
End SubPublic Sub UnLockMouse()
Dim tyWC As RECT
With tyWC
.Left = 0
.Top = 0
.Right = Screen.Width
.Bottom = Screen.Height
End With
Call ClipCursor(tyWC)
End Sub
Private Sub WarTimer_Timer()
Dim hwndForeground As Long ',hwndWC As Long hwndWC = FindWindow("Warcraft III", "Warcraft III")
hwndForeground = GetForegroundWindow If hwndWC = 0 Then
InfoLab.Caption = "魔兽没开启,等待中..."
If MouseChk.Value Then Call UnLockMouse
If WarRun Then
WarRun = False
End If
Else
If hwndWC = hwndForeground Then
If WarRun = False Then
WarRun = True
InfoLab.Caption = "hWnd=0x" & Hex(hwndWC) & ", √" & "[前置]"
If MouseChk.Value Then Call LockMouse
End If
Else
InfoLab.Caption = "hWnd=0x" & Hex(hwndWC) & ",等待窗口激活..."
If MouseChk.Value Then Call UnLockMouse
If WarRun Then
WarRun = False
End If
End If
End IfEnd Sub