VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code is a great way to create a toolbar that hides just above the desktop until the cursor is

by Bryan King (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 15th March 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code is a great way to create a toolbar that hides just above the desktop until the cursor is positioned near the top of the screen which

API Declarations



'the codes to read the screen size and
'GetCursorPos were found on the internet.
'I forget where but if it is your code, please email me and
'I will add credit for your work.

'This code is a great way to create a toolbar that hides
'just above the desktop until the cursor is positioned near
'the top of the screen which makes the toolbar drop down.
'Moving the cursor off the form makes the form hide itself again.
'With a little work and understanding, this
'can be modified to have the form hide to the right or left
'of the desktop instead of the top. As far as I know, you can use
'this code any way you want to, it's free.

'The code in the Timer1 event handler was created by me.
'It took a lot of trial and error, and some math, but it works.
'If you find this code useful or have questions please email me:
'[email protected]
'Also, if you know of an easier way to do this, please email me.

'general declarations
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Rate This code is a great way to create a toolbar that hides just above the desktop until the cursor is



'Form1, Timer1, Timer2, Label1, Command1
Private Sub Command1_Click()
 Me.Top = 0 - Me.Height 'hide the form just out of sight above the desktop
                        'out of sight until needed.

 MsgBox "Hi" 'replace with your code
 'This can also be used to shell external programs
End Sub

Private Sub Timer1_Timer()
 'declare the variable.
 Dim ptAPI As POINTAPI
 
 'pass the cursor position to the new variable.
 GetCursorPos ptAPI
 
 'if the cursor is within 5 twips of the top of the screen.
 If ptAPI.Y < 5 Then
 
    'bring the form down so that the top of
    'the form aligns with the top of the screen.
    Me.Top = ScreenTop
    
 'if the cursor leaves the form, then hide the form
 'above the desktop again.
 'The Val(ptAPI.Y * 15) code was necessary because the variable ptAPI.Y
 'is given the cursor position in pixels and I was using twips when
 'calculating the Height and Width of my forms.
 'So Val(ptAPI.Y * 15) simply converts the cursor position from
 'pixels to twips since the sizes are different in pixels than
 'they are in twips. The entire program needs to work by the
 'same set of rules.
 ElseIf Val(ptAPI.Y * 15) > Me.Height Then 'check to see if the cursor goes below the form
    Me.Top = 0 - Me.Height  'hide the form until needed.
 ElseIf Val(ptAPI.X * 15) < Me.Left Then 'check to see if the cursor goes to the left of the form
    Me.Top = 0 - Me.Height  'hide the form until needed.
 ElseIf Val(ptAPI.X * 15) > Me.Left + Me.Width Then 'check to see if the cursor goes to the right of the form
    Me.Top = 0 - Me.Height  'hide the form until needed.
 End If
End Sub

Private Sub Form_Load()
 'begin code to read the screen size
 Dim SX As Long
 Dim SY As Long
 SX = Screen.Width / Screen.TwipsPerPixelX
 SY = Screen.Height / Screen.TwipsPerPixelY
 'end code to read the screen size
 
 Me.Left = (Screen.Width - Me.Width) / 2 'center the form horizontally on the screen
 Me.Top = 0 - Me.Height 'hide the form just out of sight above the desktop
                        'out of sight until needed.
 
 'put the current time into Label1
 Label1.Caption = Format(Now, "h:mm:ss  am/pm")
End Sub

Private Sub Timer2_Timer()
 'update the current time into Label1
 Label1.Caption = Format(Now, "h:mm:ss  am/pm")
End Sub

Download this snippet    Add to My Saved Code

This code is a great way to create a toolbar that hides just above the desktop until the cursor is Comments

No comments have been posted about This code is a great way to create a toolbar that hides just above the desktop until the cursor is . Why not be the first to post a comment about This code is a great way to create a toolbar that hides just above the desktop until the cursor is .

Post your comment

Subject:
Message:
0/1000 characters