Solved

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

Posted on 2004-09-22
5
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

636 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