Solved

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

Posted on 2004-09-22
5
235 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
Comment Utility
8 open questions - some of which you have not even posted comments after receiving help.
0
 

Author Comment

by:Jimmyx1000
Comment Utility
ooopppps.

Sorted
0
 
LVL 13

Expert Comment

by:Michael_D
Comment Utility
And why you are asking same question twice?
0
 
LVL 1

Accepted Solution

by:
ajanthony earned 500 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 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

11 Experts available now in Live!

Get 1:1 Help Now