Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 247
  • Last Modified:

Show form when Mouse moves to the top of the Desktop vb6

Id like to show a form when the mouse is moved to the top of the desktop

and then hide the form when the mouse moves  outside the form.


thanks experts


0
Jimmyx1000
Asked:
Jimmyx1000
1 Solution
 
Erick37Commented:
8 open questions - some of which you have not even posted comments after receiving help.
0
 
Jimmyx1000Author Commented:
ooopppps.

Sorted
0
 
Michael_DCommented:
And why you are asking same question twice?
0
 
ajanthonyCommented:
Create a standard exe, add a timer to form1, and add a standard module

In the form, paste...

------------------


Private Sub Timer1_Timer()
    Dim mouseposition As POINTAPI
   
    GetCursorPos mouseposition
       
       
    'if the window is invisible, check the mouse pointer location
    If Me.Visible = False Then
        'if the Y coord is 0 (ie top of screen), display the window, and stop the timer
        If mouseposition.Y = 0 Then
            Me.Visible = True
            PutCursorInWindow Me.hWnd, 100, 100
            Timer1.Enabled = False
            Exit Sub
        End If
   
    Else
        'if the mouse leaves the window, restart the timer, and hide the window.
        If IsCursorInWindow(Me.hWnd) = False Then
            Me.Visible = False
            Timer1.Enabled = True
        End If
    End If

End Sub

Private Sub Form_Load()
    'setup the timer, hide the form
    Me.Visible = False
    Timer1.Interval = 10
    Timer1.Enabled = True
End Sub

------------------

And in a module

-----------------

Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Type POINTAPI
    X As Long
    Y As Long
End Type

Public Function IsCursorInWindow(ByVal hWnd As Long) As Boolean
   
    Dim lpRect As RECT
    Dim lpMousePosition As POINTAPI
   
    GetWindowRect hWnd, lpRect
    GetCursorPos lpMousePosition
   
    IsCursorInWindow = (((lpRect.Left < lpMousePosition.X) And (lpMousePosition.X < lpRect.Right)) And ((lpRect.Top < lpMousePosition.Y) And (lpMousePosition.Y < lpRect.Bottom)))
End Function

Public Sub PutCursorInWindow(ByVal hWnd As Long, intXOffset As Integer, intYOffset As Integer)
    Dim lpRect As RECT
   
    GetWindowRect hWnd, lpRect
    SetCursorPos lpRect.Left + intXOffset, lpRect.Top + intYOffset
   
End Sub

-----------------

its pretty self explanatory.  Hope this helps.

- Alex
0
 
ajanthonyCommented:
I knew id make a mistake on my first ever post!  Sorry!

Paste this into the form instead...

------

Private Sub Timer1_Timer()
    Dim mouseposition As POINTAPI
   
    GetCursorPos mouseposition
       
       
    'if the window is invisible, check the mouse pointer location
    If Me.Visible = False Then
        'if the Y coord is 0 (ie top of screen), display the window
        If mouseposition.Y = 0 Then
            Me.Visible = True
            PutCursorInWindow Me.hWnd, 100, 100
            Exit Sub
        End If
   
    Else
        'if the mouse leaves the window, and hide the window.
        If IsCursorInWindow(Me.hWnd) = False Then
            Me.Visible = False
        End If
    End If

End Sub

Private Sub Form_Load()
    'setup the timer, hide the form
    Me.Visible = False
    Timer1.Interval = 10
    Timer1.Enabled = True
End Sub
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now