What happens if I drag the mouse by exactly the amount specified by SM_CXDRAG?

The drag sensitivity is specified by the system metrics SM_CXDRAG and SM_CYDRAG. What happens if I drag the mouse by exactly the amount specified by these two parameters?


These parameters control the drag insensitivity of the mouse. If your mouse motion is less than or equal to this amount, then nothing happens. This is spelled out in the documentation for GetSystemMetrics:

The number of pixels on either side of a mouse-down point that the mouse pointer can move before a drag operation begins.

It's how far the mouse can move before the system detects a drag. In code, the algorithm is as follows:

BOOL ShouldStartDragging(POINT ptStart, POINT ptCur)
    RECT rc = { ptStart.x, ptStart.y, ptStart.x, ptStart.y };
    InflateRect(&rc, GetSystemMetrics(SM_CXDRAG),
    return !PtInRect(&rc, ptCur);

Some people appear to have read a bit too much into the fluffy description of this setting. I wrote the text to be vague so I wouldn't have to go into annoyingly precise details. It specifies how far the mouse must move, but I didn't say exactly how. Otherwise, the text (which is pretty full already) would have had to say something unwieldy like "Drag sensitivity specifies the distance (in pixels) beyond which the mouse must move with the button held down..." I did say that "the icon will begin dragging when you have moved the mouse the necessary distance." This was my way of saying, "The test icon shows you what happens. Just fiddle with the setting until the test icon behaves the way you like."

In retrospect, I could've simply changed the word must to can.

Comments (17)
  1. Nawak says:

    To be fair, the blog you linked also states that the behaviour is dependent on the drag direction: two directions behaving like you said and two like he thought. I think that’s what pushed him into thinking too much about it.

    Let me also take the opportunity of this post to thank you (and others?) for TweakUI.

  2. mh says:

    I would guess that’s because the mouse-delta is zero-based, increasing in the right and down directions, but you’d need to know the inner workings of InflateRect and PtInRect to confirm that.

  3. Anonymous says:

    mh: Except that the behavior really is symmetrical as far as I can tell, so the only remaining explanation is a bug in TweakUI’s test icon – merely the opposite bug of what he thought it was – it moving immediately when dragging down/right with the value set to 1 is the bug.

    (I can’t verify whether TweakUI actually behaves as described because for some unfathomable reason it refuses to run on Windows 7, and when compatibility mode is set it refuses to run on WOW64. I can’t think of anything it actually does for which either of these things could cause problems.)

    [I can. -Raymond]
  4. AC says:

    Ok, so this setting exists because most people don’t have pixel perfect control of their mouse in the first place. Then why would someone need to configure it with one pixel precision??

    Although interesting, my answer to the question in the title would have been "who cares"?

  5. mikeb says:

    > my answer to the question in the title would have been "who cares"?

    A: Jason Doucette

  6. Rick C says:

    [I can. -Raymond]

    Can what?  Verify or think?

    [… think of things it does which can cause problems when run outside of its target OS. -Raymond]
  7. Ivo says:

    GSerg: According to http://msdn.microsoft.com/en-us/library/ms724385(VS.85).aspx, SM_CXDRAG is distance measured from the click point, and SM_CXDOUBLECLK is the width of the double-click rectangle (so the distance is half of that). I guess that’s where the confusion is coming from.

  8. WndSks says:

    @Rick C: Since Raymond wrote TweakUI I’m sure he would KNOW

  9. ac says:


    int(x – 1/2) = x – 1


    int(y – 1/2) = y – 1


    int(x + 1/2) = x


    int(y + 1/2) = y

    spot the difference?

  10. GSerg says:

    Then we have a bug in MSDN.

    This article: http://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.dragsize.aspx

    states that DragSize (which is SM_CXDRAG x SM_CYDRAG, no conversion here) is a rectangle *within* which dragging will not start. So dragging will start when mouse moves SM_CXDRAG/2 pixels according to them. And a code example can be found here: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dodragdrop.aspx , where this line of code is worth noting:

    dragBoxFromMouseDown = new Rectangle(new Point(e.X – (dragSize.Width /2),  e.Y – (dragSize.Height /2)), dragSize);

  11. Falcon says:

    From MSDN: "The InflateRect function adds dx units to the left and right ends of the rectangle and dy units to the top and bottom."

    Aided by this blog post and observed behaviour, I interpret this as:

    lprc->left -= dx;

    lprc->top -= dy;

    lprc->right += dx;

    lprc->bottom += dy;

    From the MSDN page about the RECT structure:


    By convention, the right and bottom edges of the rectangle are normally considered exclusive. In other words, the pixel whose coordinates are ( right, bottom ) lies immediately outside of the the rectangle. For example, when RECT is passed to the FillRect function, the rectangle is filled up to, but not including, the right column and bottom row of pixels. This structure is identical to the RECTL structure."

  12. x^2+y^2=z^2 says:

    Then depends if you move the mouse up/left or right/down?

    And it should use a sphere instead of rectangle.

  13. 640k says:

    > @Rick C: Since Raymond wrote TweakUI I’m sure he would KNOW

    No, the program prevents itself from running because he DONT know what can happen and dont want to be liable if it does something stupid which corrupts 64-bit windows.

    You could run in in “xp mode” though.

    [I know that Tweak UI will not work. -Raymond]
  14. Wang-Lo says:

    @x^2+y^2=z^2: "And it should use a sphere instead of rectangle."

    Or perhaps a cylinder.  Depending, I guess, on whether you want to be able to trigger dragging by picking the mouse up off the pad…


  15. Ben says:

    May I suggest that the MSDN text be revised to read as something along the lines of: "The minimum number of pixels from a mouse-down point that the mouse pointer must be displaced before a drag operation begins."? This leaves considerably less room for erroneous interpretation than the phrase presently employed.

  16. Alberto Martinez says:

    After reading the “I can” comment (showing that the social skills of a thermonuclear device can be funny :-), I realized with horror that the current version of Tweak UI is only for Windows XP.

    Do you have any intention of release a new version for Vista/7? I have been using Tweak UI for about ten years and I’m find it very useful for things like disabling auto insert on external drives (heck, even my girlfriend use it).

    I know that there are more tweak tools or that I could edit the Registry, but I feel a lot more confident using and recommending a tool written by Raymond Chen himself, because I know that *he really knows* how to tweak Windows properly.

    Anyway, many thanks for Tweak UI.

    [I wrote a Vista version but it wasn’t released because it violated the policy of “no unsupported downloads.” Sorry, everybody. -Raymond]
  17. Mike Dunn says:

    I think this boils down to a difference in parsing. One could parse "the mouse must move 5 pixels before starting a drag operation," as: a) the mouse will move 5 pixels, then b) a drag operation will start. That is, "X before Y" means "X will happen, then Y will happen." Not "X will happen, then some additional fraction of X will happen, then Y will happen."

    This isn’t meant to be supreme nitpicking, just pointing out how someone could arrive at a different interpretation of that text in TweakUI.

Comments are closed.

Skip to main content