Home All Groups Group Topic Archive Search About

Problems with vbCtrlMask

Author
29 Jan 2006 4:58 PM
MatthewBrown
I would like to determine if CTRL is pressed to activate a form move.

CTRLClick is a set option.
The movement works fine when CTRLClick = 0, but not when CTRLClick = 1.

I searched and found the Shift = vbCtrlMask thing, but that doesn't
work.


Please help:


'For window dragging
(http://groups.google.com/group/microsoft.public.vb.general.discussion/browse_thread/thread/1a6101384e44a017/078e00c3bacb5370?hl=en#078e00c3bacb5370)

If CTRLClick = 1 Then


    If Button = vbLeftButton And Shift = vbCtrlMask Then

     ReleaseCapture
      SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
    End If

ElseIf CTRLClick = 0 Then 'just a left-click, no keys

    If Button = vbLeftButton Then

        ReleaseCapture
        SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
    End If

End If




Thanks!

Author
29 Jan 2006 6:13 PM
Mike D Sutton
>I would like to determine if CTRL is pressed to activate a form move.
>
> CTRLClick is a set option.
> The movement works fine when CTRLClick = 0, but not when CTRLClick = 1.
>
> I searched and found the Shift = vbCtrlMask thing, but that doesn't
> work.

You shouldn't compare the value directly since it's a bit-flag rather than a
value, you want something like:

***
If (Shift And vbShiftMask) Then
    ' Shift is down
End If

If (Shift And vbCtrlMask) Then
    ' Ctrl is down
End If

If (Shift And vbAltMask) Then
    ' Alt is down
End If
***

Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
29 Jan 2006 6:16 PM
Tom Esh
On 29 Jan 2006 08:58:57 -0800, MatthewBr***@gmail.com wrote:

>...
>    If Button = vbLeftButton And Shift = vbCtrlMask Then

Because the Shift param may contain multiple mask flags you need to
use the And bit-wise operator to test for an individual flag.
(Note the same is actually true of the Button param as well, though
typically you'd not want to do anything if more than one mouse button
were down.)

If Button = vbLeftButton Then
    If (Shift And vbCtrlMask) = vbCtrlMask Then

    End If
End If


-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
Author
29 Jan 2006 7:14 PM
MatthewBrown
Thanks! Final and functional:

'For window dragging
(http://groups.google.com/group/microsoft.public.vb.general.discussion/browse_thread/thread/1a6101384e44a017/078e00c3bacb5370?hl=en#078e00c3bacb5370)
If Button = vbLeftButton Then
    If CTRLClick = True Then

        If (Shift And vbCtrlMask) = vbCtrlMask Then

            ReleaseCapture
            SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
        End If

    ElseIf CTRLClick = False Then 'just a left-click, no keys

        ReleaseCapture
        SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
    End If

End If



For future reference, (Shift And vbCtrlMask) and VBCtrlMask both = 2
when active.
Author
3 Feb 2006 3:04 AM
Bob O`Bob
MatthewBr***@gmail.com wrote:

>         If (Shift And vbCtrlMask) = vbCtrlMask Then
>
>             ReleaseCapture
>             SendMessage Me.hWnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&
>         End If
>

since the flag is a single bit, it should be safe and slightly more efficient to simplify:

     If (Shift And vbCtrlMask) Then




    Bob