Solved

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

Posted on 2004-09-22
5
236 Views
Last Modified: 2010-05-02
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
Comment
Question by:Jimmyx1000
5 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 12127449
8 open questions - some of which you have not even posted comments after receiving help.
0
 

Author Comment

by:Jimmyx1000
ID: 12127507
ooopppps.

Sorted
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 12127993
And why you are asking same question twice?
0
 
LVL 1

Accepted Solution

by:
ajanthony earned 500 total points
ID: 12152113
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
 
LVL 1

Expert Comment

by:ajanthony
ID: 12152131
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now