下面是把鼠标锁定在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
--------------------------------------------------------------------------------------------------

解决方案 »

  1.   

    - - 
    看不出来有什么实际作用啊?ALT+TAB . 行么?
      

  2.   

    设定魔兽窗口化的时候,需要用程式调用API:SetWindowPos 设定其窗口置顶为HWND_TOPMOST,这样魔兽窗口被激活获取焦点的时候也不会被任务栏遮盖了(因为任务栏是HWND_TOPMOST的)
      

  3.   

    能不能先把rtCustomForm和rectRect合并后再ClipCursor呢
      

  4.   

    UPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUPUP
      

  5.   

    谁能帮我解释一下这段代码.
    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
      

  6.   

    【VB声明】
      Private Declare Function GetClientRect Lib "user32" Alias "GetClientRect" (ByVal hwnd As Long, lpRect As RECT) As Long【说明】
      返回指定窗口客户区矩形的大小 【返回值】
      Long,非零表示成功,零表示失败。会设置GetLastError 【备注】
      lpRect的左侧及顶部区域肯定会被这个函数设为零【参数表】
      hwnd -----------  Long,欲计算大小的目标窗口  lpRect ---------  RECT,指定一个矩形,用客户区域的大小载入(以像素为单位)
      

  7.   

    Public Sub LockMouse()
        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
      

  8.   

    然后弄个timer
    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