开发者

Windows CWnd::OnLButtonDown not called as expected on double click

I'm developing an interactive MFC application which displays a 3D object using my own algorithm, essentially using MFC as a framework, but using lots of pDC->Polygon(), pDC->Rectangle(), pDC->DrawText(), etc. calls.

The UI has numerous clickable areas which all work well. However, the onscreen controls for rotating, spinning, etc. the 3D image motivate users to double click, triple click, and beyond.

I'm 99% positive that CWnd::OnLButtonDown() is not called until Windows (or whatever) has decided the operation is not a double click, or when double clicked, but only once. That is a series of clicks results in a notification every second click. The user experience is stuttered rotation. The temporary workaround is to have users move the mouse slightly between clicks—It solves the problem, but is rather unfriendly.

The application does no double click event hooking. Maybe ther开发者_运维技巧e's a way to go further to disable potential double click processing? Or maybe there is a lower-level way to capture the mouse button down?


I think you have it backwards - the first click gets through as a WM_LBUTTONDOWN, the second one gets turned into a double-click.

To prevent a window from generating WM_LBUTTONDBLCLK messages, remove the CS_DBLCLKS style from the window.

This is all explained in the WM_LBUTTONDBLCLK documentation.

Edit: I misspoke, CS_DBLCLKS is a class style, not a window style. I don't think you can remove it, you have to create a new window class that doesn't include it. It's provided by MFC - see this page http://msdn.microsoft.com/en-us/library/a77269ff(VS.80).aspx.


Just to add an answer, this method worked for me:

    WORD dwStyle = GetClassLongPtr(handle, GCL_STYLE);
    dwStyle &= ~CS_DBLCLKS;
    SetClassLongPtr(handle, GCL_STYLE, dwStyle);

You can use these functions to edit a WNDCLASSEX style structure for an specific window removing the double click event and correcting the single click behavior.

GetClassLongPtr
SetClassLongPtr

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜