Pages

Banner 468

Senin, 01 Desember 2008

MENGETAHUI CAPTION CONTROL DI WINDOWS ATAU FORM

 
-buat project baru
-tambah kan form dengan nama form1
-tambahkan label dengan nama lblState
-tambahkan timer dengan nama timer1 ,intervalnya=1
-copykan script ini ke form



Private Type POINTAPI
x As Long
y As Long
End Type
'Copy right vb-bego.com

Const HWND_TOP As Integer = 0
Const HWND_BOTTOM As Integer = 1
Const HWND_TOPMOST As Integer = -1
Const HWND_NOTOPMOST As Integer = -2
Const SWP_NOSIZE As Integer = 1
Const SWP_NOMOVE As Integer = 2

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, ByVal hWndAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal xy As Long, ByVal uflags As Long) As Integer
Private Declare Function AccessibleObjectFromPoint Lib "oleacc" (ByVal x As Long, ByVal y As Long, ppoleAcc As Object, pvarElement As Variant) As Long

Dim objAccessible As Object

Private Sub Form_Load()
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, (SWP_NOSIZE Or SWP_NOMOVE)
End Sub

Private Sub lblState_Change()
If Trim(lblState) = "" Then
Me.Visible = False
Else
Me.Visible = True
End If
End Sub

Private Sub Timer1_Timer()
Dim p As POINTAPI
Dim v As Variant
Dim sName As String

GetCursorPos p

AccessibleObjectFromPoint p.x, p.y, objAccessible, v

sName = ""
On Error Resume Next
sName = objAccessible.accName(v)
If Trim(sName) = "" Then
sName = objAccessible.accvalue(v)
End If
On Error GoTo 0
Me.ZOrder
Me.Left = (p.x * Screen.TwipsPerPixelX) + 250
Me.Top = (p.y * Screen.TwipsPerPixelY) + 100

Me.lblState.Caption = sName
Me.Width = Me.lblState.Width + 200
Me.Height = Me.lblState.Height + 70

End Sub