VB icon

Real Window Snap to

Email
Submitted on: 1/6/2015 11:24:00 PM
By: DoWnLoHo (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: VB 5.0, VB 6.0
Views: 844
 
     This code produces a snap to effect exactly like Winamp. Uses POINTAPI type and GetCursorPos API. It gets the current x and y does a few calculations and snaps-to the screen edge. It does take into account for the taskbar but that may need some tweaking.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Real Window Snap to
' Description:This code produces a snap to effect exactly like Winamp.
Uses POINTAPI type and GetCursorPos API. 
It gets the current x and y does a few calculations and snaps-to the screen edge. 
It does take into account for the taskbar but that may need some tweaking.
' By: DoWnLoHo (from psc cd)
'**************************************

'Note** This meant to be saved as a form
'Copy below this line; paste into notepad; Save as frmSnapto.frm
VERSION 5.00
Begin VB.Form frmSnapTo 
BorderStyle =0 'None
Caption ="Form1"
ClientHeight=1335
ClientLeft =0
ClientTop=0
ClientWidth =3660
LinkTopic="Form1"
ScaleHeight =1335
ScaleWidth =3660
ShowInTaskbar=0'False
StartUpPosition =3 'Windows Default
Begin VB.Timer tmrPos 
 Enabled =0'False
 Interval=1
 Left=120
 Top =360
End
Begin VB.Label lblTop 
 BackColor=&H000000FF&
 Caption ="Caption"
 Height =255
 Left=0
 TabIndex=0
 Top =0
 Width=3720
End
End
Attribute VB_Name = "frmSnapTo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Dim iX As Integer, iY As Integer
Private Sub lblTop_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
iX% = X: iY% = Y
tmrPos.Enabled = True
End Sub
Private Sub lblTop_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
tmrPos.Enabled = False
End Sub
Private Sub tmrPos_Timer()
Dim ptPos As POINTAPI
 Call GetCursorPos(ptPos)
 lblTop.Caption = ptPos.X & " - " & ptPos.Y
If ptPos.Y - ((lblTop.Top + iY%) / Screen.TwipsPerPixelY) <= 20 Then ptPos.Y = 0 + ((lblTop.Top + iY%) / Screen.TwipsPerPixelY)
If ptPos.X - ((lblTop.Left + iX%) / Screen.TwipsPerPixelX) <= 20 Then ptPos.X = 0 + ((lblTop.Left + iX%) / Screen.TwipsPerPixelX)
If ptPos.Y - ((lblTop.Top + iY%) / Screen.TwipsPerPixelY) >= (Screen.Height - Me.Height - 400) / Screen.TwipsPerPixelY - 20 Then
ptPos.Y = (Screen.Height - Me.Height + iY% - 400) / Screen.TwipsPerPixelY
End If
If ptPos.X - ((lblTop.Left + iX%) / Screen.TwipsPerPixelX) >= (Screen.Width - Me.Width) / Screen.TwipsPerPixelX - 20 Then
ptPos.X = (Screen.Width - Me.Width + iX%) / Screen.TwipsPerPixelX
End If
Me.Top = (ptPos.Y * Screen.TwipsPerPixelY) - lblTop.Top - iY%
Me.Left = (ptPos.X * Screen.TwipsPerPixelX) - lblTop.Left - iX%
End Sub


Other 13 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.