19. april 2004 - 14:13Der er
4 kommentarer og 1 løsning
Event til Form når musen er væk?
Jeg er igang med en lille genvejsbar som skal sidde i toppen af windows, og kun fylde caption baren, jeg har fundet ud af at skjule den ved klik på knap, og alt det der. Det er endog lykkedes mig at atgøre sådan at den "fader" ud og "glider" op ved klik og modsat ved klik.
Men mit problem at jeg gerne vil have at den skal skjule sig når musen ikke er over form, og dukke op når musen er over formen igen.
Kort sagt: Event ved MouseOut, og event ved MouseOver.
Jeg ved at VB6 ikke har MouseOut og MouseOver, men jeg ved også at det kan omgåes, men mit spørgsmålerså hvordan.
Private Type POINTAPI X As Long Y As Long End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, _ ByVal yPoint As Long) As Long
Public Function MouseOver(ByVal lhwnd As Long) As Boolean Dim TPA As POINTAPI Call GetCursorPos(TPA) If WindowFromPoint(TPA.X, TPA.Y) = lhwnd Then MouseOver = True Else MouseOver = False End If End Function
Private Sub Form_Load() Timer1.Interval = 100 '<- millisekunder End Sub
Private Sub Timer1_Timer() Me.Caption = MouseOver(Me.hWnd) End Sub '------------------------------ Form1 ------------------------------
Jeg har fundet noget ligende, fra en tysker.... og det virker perfekt....
jeg ved lægger hermed den anden kode jeg fandt... jeg har sagt den ligner din på en prik =)
'----General declarations----- Option Explicit
' Benyttede API-Deklaration Private Declare Function GetCursorPos Lib "user32" ( _ lpPoint As POINTAPI) As Long
Private Declare Function PtInRect Lib "user32" ( _ lpRect As RECT, _ ByVal x As Long, _ ByVal y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" ( _ ByVal hwnd As Long, lpRect As RECT) As Long
Private Type POINTAPI x As Long y As Long End Type
Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type
'-----form1------ Private Sub Form_load(); MouseWatcher.Interval = 50 MouseWatcher.Enabled = True End Sub '-----
Private Sub MouseWatcher_Timer() Dim P As POINTAPI Dim R As RECT
' Aktuel musepoistion GetCursorPos P
' Formens position GetWindowRect Me.hwnd, R
' Befinder musen sig inden for formen? If PtInRect(R, P.x, P.y) = 0 Then 'MouseOut TimeTest = TimeTest + 1 If TimeTest > 50 Then UpWard = True Timer1.Enabled = True TimeTest = 0 End If Else 'MouseOver UpWard = False Timer1.Enabled = True End If
Private Type POINTAPI X As Long Y As Long End Type
Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Function MouseOver(ByVal lhwnd As Long) As Boolean Dim TPA As POINTAPI Dim TRC As RECT Call GetCursorPos(TPA) Call GetWindowRect(lhwnd, TRC) With TRC If (TPA.X < .Right) And (TPA.X > .Left) And _ (TPA.Y < .Bottom) And (TPA.Y > .Top) Then MouseOver = True Else MouseOver = False End If End With End Function
Private Sub Form_Load() Timer1.Interval = 100 '<- millisekunder End Sub
Private Sub Timer1_Timer() Me.Caption = MouseOver(Me.hwnd) End Sub '------------------------------ Form1 ------------------------------
og tak for point :)
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.