Private Declare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Integer
Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal aBOOL As Integer) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private lngTASKBARHWND As Long
Private intISTASKBARENABLED As Long
Private lHwnd As Long '开始按钮句柄
Public Sub DisableTaskBar() '禁用
Dim EWindow As Long
lngTASKBARHWND = FindWindow("Shell_traywnd", "")
If lngTASKBARHWND <> 0 Then
EWindow = IsWindowEnabled(lngTASKBARHWND)
If EWindow = 1 Then intISTASKBARENABLED = EnableWindow(lngTASKBARHWND, 0)
End If
lHwnd = FindWindowEx(lngTASKBARHWND, 0&, "Button", vbNullString)
Call EnableWindow(lHwnd, 0)
End Sub
Public Sub EnableTaskBar() '启用
If intISTASKBARENABLED = 0 Then intISTASKBARENABLED = EnableWindow(lngTASKBARHWND, 1)
EnableWindow lHwnd, 1
End Sub
以上代码在WINXP下测试成功,但是在WIN7下无法禁用“开始”按钮。你不妨换个思路,就是根据任务栏的句柄,使用GetWindowRect 获取其位置以及窗口范围,根据这个范围来限定鼠标活动范围。