// 下面的代码应该可以对所有标准控件都能激活了。
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function ChildWindowFromPoint Lib "user32" (ByVal hWndParent As Long, ByVal xpt As Long, ByVal ypt As Long) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const HWND_NOTOPMOST = -2
Private Const HWND_TOPMOST = -1
Private Sub Command1_Click()
If Timer1.Enabled = False Then
Timer1.Enabled = True SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Else
Timer1.Enabled = False SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim pt As POINTAPI GetCursorPos pt
hWindow = WindowFromPoint(pt.x, pt.y) ScreenToClient hWindow, pt
Text1.Text = "x:" & pt.x & " - " & "y:" & pt.y
hChildWindow = ChildWindowFromPoint(hWindow, pt.x, pt.y)
Text2.Text = hChildWindow
If IsWindowEnabled(hChildWindow) = 0 Then EnableWindow hChildWindow, True
End If
End Sub