Hallo zusammen,
wer kann mir eventuell sagen, wie ich eine Form als ganzes abfragen kann.
Beispiel: ich habe eine Form die ich transparent darstelle, sowie man mit der Maus die Form berührt wird sie als nicht [u]transparent dargestellt.
Funktioniert ganz gut, nun kommt aber das Problem, beim verlassen soll wieder die Transparenz hergestellt werden, funktioniert soweit auch, aber wenn ich mit der Maus auf ein Control innerhalb der Form komme, dann wird dieses als verlassen der Form regiestriert.([u]Dies ist mein Problem, vielleicht weiß hier jemand einen Rat)
Hier mal mein Code:
Private Declare Function GetParent Lib "user32.dll" ( _
ByVal hwnd As Long) As Long
Private Declare Function WindowFromPoint Lib "user32.dll" ( _
ByVal xPoint As Long, _
ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32.dll" ( _
lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function SetLayeredWindowAttributes Lib "user32.dll" _
(ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long
Private Declare Function GetWL Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWL Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNL As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const WS_L = &H80000
Private Const GW_E = -20
Private Const LWA_1 = &H2
Private Const LWA_2 = &H1
Public Function SetTrans(ByRef tForm As Form, _
ByVal iTrans As Byte, Optional ByVal iTune As Boolean = True) As Boolean
On Error Resume Next
Dim LWL As Long
Err = 0
If iTune Then
LWL = GetWL(tForm.hwnd, GW_E)
LWL = LWL Or WS_L
SetWL tForm.hwnd, GW_E, LWL
End If
SetLayeredWindowAttributes tForm.hwnd, RGB(255, 0, 255), iTrans, LWA_1 Or _
LWA_2
SetTrans = Err = 0
End Function
Function GetParentHandle(ByVal Handle As Long) As Long
On Error Resume Next
GetParentHandle = Handle
Handle = GetParent(Handle)
If Handle = 0 Then Exit Function
If Handle = hwnd Then Exit Function
GetParentHandle = GetParentHandle(Handle)
End Function
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
Me.Show
SetTrans Me, 150, True ' Transparenz der Form festlegen (Wert zwischen
' 0=unsichtbar und 255=sichtbar)
End Sub
Private Sub Timer1_Timer()
Dim C As POINTAPI, lRet As Long, lHandle As Long
lRet = GetCursorPos(C)
lHandle = WindowFromPoint(C.X, C.Y)
If Not GetParentHandle(lHandle) = hwnd Then
SetTrans Me, 90, True ' Transparenz der Form festlegen
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y _
As Single)
SetTrans Me, 255, True ' Transparenz der Form festlegen
End Sub |