Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long
Public myHwnd As Long
Public Function EnumWindowsProc1(ByVal hwnd As Long, ByVal lParam _
As Long) As Boolean
Dim sTitle As String, Ret As Long
Ret = GetWindowTextLength(hwnd)
sTitle = Space(Ret)
GetWindowText hwnd, sTitle, Ret + 1
If sTitle <> "" And IsWindowVisible(hwnd) <> 0 And hwnd <> myHwnd Then
Debug.Print sTitle
EnableWindow hwnd, 0
End If
EnumWindowsProc1 = True
End Function
Public Function EnumWindowsProc2(ByVal hwnd As Long, ByVal lParam _
As Long) As Boolean
Dim sTitle As String, Ret As Long
Ret = GetWindowTextLength(hwnd)
sTitle = Space(Ret)
GetWindowText hwnd, sTitle, Ret + 1
If sTitle <> "" And IsWindowVisible(hwnd) <> 0 And hwnd <> myHwnd Then
Debug.Print sTitle
EnableWindow hwnd, 1
End If
EnumWindowsProc2 = True
End Function
窗体中:
Private Sub Command1_Click() '禁止措作其他窗口
EnumWindows AddressOf EnumWindowsProc1, 0&
End Sub
Private Sub Command2_Click() '恢复
EnumWindows AddressOf EnumWindowsProc2, 0&
End Sub
Private Sub Form_Load() '记录本窗口hwnd避免把自己也给搞得不响应了
myHwnd = Me.hwnd
End Sub
功能2(使屏幕变暗):
''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function PatBlt Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, ByVal lpRect As Long, ByVal bErase As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal aBitmap As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Sub Dull() '使屏幕变暗
Dim aDC As Long, aBitmap As Long, aBrush As Long, aDesktopWnd As Long
Dim lWidth5 As Long, lHeight As Long, bBit(1 To 16) As Byte