Vb2005 - ReleaseCapture


Might anyone have working VB2005 code for ReleaseCapture?
[63 byte] By [ReneeC] at [2007-12-16]
# 1
Can you provide more information? What is ReleaseCapture?
DavidM.Kean at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Consider the old pre-Office 2003 short cut bar. Any form that does not have a menu bar will not be grabbable with a mouse.
With the the pre-Office 2003 short cut bar, you could

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 Module1

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 Then

bMouseSelectKeyDownOnBar = True

If Not bBarShapeBar Then

ReleaseCapture()

status=SendMessage (Handle.ToInt32, WM_NCLBUTTONDOWN, HTCAPTION, 0)

End If

Else

bMouseCtxtKeyDownOnBar = True

CtxMnu.Top = e.Y

CtxMnu.Left = e.X

CtxMnu.Visible = True

End If

Else ' select button is

If e.Button.Right Then bMouseSelectKeyDownOnBar = True

CtxMnu.Visible = True

End If

End Sub


It doesn't work meaning nothing happens. The return status of send message is 0.
ReneeC at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

I just found a "Capture" Property for forms....

It doesn't seem to be working either......

ReneeC at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4
After a lot of playing with this and looking at many different methods, I decided that following would work best for me.

I 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 System.Windows.forms

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 TimerEventProcessor

TimerD.Interval = 25

End Sub

Private Sub TimerEventProcessor(ByVal myObject As Object, _

ByVal myEventArgs As EventArgs)

Dim status As Long

status = 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.MouseDown

TimerD.Enabled = True

End Sub

Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp

TimerD.Enabled = False

End Sub

End Class

ReneeC at 2007-9-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...