Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll")> _Private Shared Function ChildWindowFromPoint(ByVal hWndParent As IntPtr, ByVal Point As Point) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True)> _Private Shared Function GetForegroundWindow() As IntPtr
End Function
<DllImport("user32.dll")> _Private Shared Function IsWindowEnabled(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Declare Function EnableWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal fEnable As Integer) As Integer
<DllImport("user32.dll", SetLastError:=True)> _Private Shared Function ScreenToClient(ByVal hWnd As IntPtr, ByRef lpPoint As Point) As Boolean
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim p As Point = MousePosition
Dim hWnd, hWndChild As IntPtr
hWnd = GetForegroundWindow()
ScreenToClient(hWnd, p)
hWndChild = ChildWindowFromPoint(hWnd, p)
If Not IsWindowEnabled(hWndChild) Then
EnableWindow(hWndChild, 1)
End If '更多.net源码和教程,来自[乐博网 www.lob.cn]
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
Timer1.Enabled = CheckBox1.Checked
End Sub
End Class