March 4th, 2010

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?

Nothing.

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),
                         GetSystemMetrics(SM_CYDRAG));
    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.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.