Vb2005 - ReleaseCapture
Might anyone have working VB2005 code for ReleaseCapture?
1.) Hold down the left mouse key on the form and move the form on screen while the left mouse is heldown.
I have vb2005 code that worked in vbnet. It does not work in vb2005.
My code looks like this:
API Declarations and Constants: Module
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Integer, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Declare Function ReleaseCapture Lib "user32" () As Integer 'used to drag a form around that has no title bar Public Const WM_NCLBUTTONDOWN = &HA1 'Used with indicate that the drag is In a title bar. Public Const HTCAPTION = 2.Code:
Private Sub FrmTaskBar_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
Dim status As Long
LastSelectCursorPos = e.Location
If Not My.Computer.Mouse.ButtonsSwapped Then If e.Button = Windows.Forms.MouseButtons.Left ThenbMouseSelectKeyDownOnBar =
True If Not bBarShapeBar ThenReleaseCapture()
status=SendMessage (Handle.ToInt32, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End If ElsebMouseCtxtKeyDownOnBar =
TrueCtxMnu.Top = e.Y
CtxMnu.Left = e.X
CtxMnu.Visible =
True End If Else ' select button is If e.Button.Right Then bMouseSelectKeyDownOnBar = TrueCtxMnu.Visible =
True End If End SubI did not use the vb2005 cursor.position because it's a shared method and requires a lot of agony.
As much as I dislike it I resorted to an API routine GetCursorPos and a keydown sampling interval of 20 milliseconds. It works very well.
For those of you familiar with api programming there are a couple of important notes here:
1.) The PointAPI structure has been redefined
2.) GetCursorPos returns an integer instead of a long.
No Marshalling is required.
Imports
Public
Class Form1 Structure POINTAPI Dim X As Integer Dim Y As Integer End Structure Protected pt As POINTAPI Protected pt1 As Point Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Integer Protected TimerD As New System.Windows.Forms.Timer() Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load AddHandler TimerD.Tick, AddressOf TimerEventProcessorTimerD.Interval = 25
End Sub Private Sub TimerEventProcessor(ByVal myObject As Object, _ ByVal myEventArgs As EventArgs) Dim status As Longstatus = GetCursorPos(pt)
pt1.X = pt.X
pt1.Y = pt.Y - 10
Me.Location = pt1 End Sub Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDownTimerD.Enabled =
True End Sub Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUpTimerD.Enabled =
False End SubEnd
Class