I've been trying to get a Form Border (title bar) mouse up for a bit now, and it seems like it's broken (I have found numerous other articles that state the same).
I have tested:
Const WM_LBUTTONUP = &H202
Const WM_MBUTTONUP = &H208
Const WM_RBUTTONUP = &H205
Const WM_NCXBUTTONUP = &HAC
Const WM_XBUTTONUP = &H20C
Const WM_MENURBUTTONUP = &H122
Const WM_NCLBUTTONUP = &HA2
Const WM_NCRBUTTONUP = &HA5
Const WM_NCLBUTTONDOWN = &HA1
Const WM_NCMOUSEMOVE = &HA0
quite thoroughly. What I am seeing is that, while WM_NCLBUTTONUP doesn't work, WM_NCLBUTTONDOWN does, and upon release (where I would expect the WM_NCLBUTTONUP), I get a WM_NCMOUSEMOVE instead. The issue being that you also get a WM_NCMOUSEMOVE as expected whenever you move the mouse outside of the client area (aka the form border)..
In a first attempt to overcome this, I have come up with:
Private MouseIsDown As Boolean = False
Protected Overrides Sub WndProc(ByRef m As Message)
Const WM_NCLBUTTONDOWN = &HA1
Const WM_NCMOUSEMOVE = &HA0
If (m.Msg = WM_NCLBUTTONDOWN) Then
MouseIsDown = True
Console.WriteLine("NCLButtonDown")
ElseIf (m.Msg = WM_NCMOUSEMOVE) Then
If MouseIsDown Then
Console.WriteLine("NCMouseMove" + Environment.NewLine + "LParam: " + m.LParam.ToString() + Environment.NewLine + "WParam: " + m.WParam.ToString() + Environment.NewLine + "Res: " + m.Result.ToString())
MouseIsDown = False
Else
Console.WriteLine("Not mouseup")
End If
Else
End If
MyBase.WndProc(m)
End Sub
This seems to be working through initial testing, but I am curious if this would be appropriate, or if there is a message that I am simply missing (I have looked through: http://www.pinvoke.net/default.aspx/Constants.WM quite closely though, and don't see anything else that looks right).