Solved

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

Posted on 2004-09-22
5
239 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

752 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