I am trying to implement Pointer Input Messages
to replace regular mouse message in a window. I'm doing this to have a better support of stylus input in my program. Everything works fine except for double-click.
I didn't process pointer message before, so these pointer messages posted by stylus driver were just passed to DefWindowProc
and DefWindowProc
just generated mouse input like WM_LBUTTONDBLCLK
.
Unlike mouse message WM_LBUTTONDBLCLK
, there is no pointer message that would explicitly tell you it's a double click. I understand their intention of designing a concise group of messages and make everything else in a clean single structure. POINTER_PEN_INFO is that struct which contains all information associated with the current message. I thought I could find anything there, maybe some flags to indicate that a WM_POINTERDOWN
message should be treated as a double click, but nothing is there as well.
Is there anything I missed? If not, what else could I do to detect a double-click? I could only find some antiquated documents that was written for Window XP on MSDN. I'm programming on Windows 10, Win32 API programming with C++.
Thank you!
You can do this by tracking clicks and comparing each click to the last in the same way that Windows does.
Pseudo-code:
POINT ptLastClickPos;
DWORD dwLastClickTime;
if (uMsg == WM_POINTERDOWN)
{
DWORD dwClickTime = GetMessageTime();
POINT ptClickPos = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
if (dwLastClickTime + GetDoubleClickTime() > dwClickTime
&& abs(ptLastClickPos.x - ptClickPos.x) < GetSystemMetrics(SM_CXDOUBLECLK)
&& abs(ptLastClickPos.y - ptClickPos.y) < GetSystemMetrics(SM_CYDOUBLECLK))
{
// double-click!
}
else
{
dwLastClickTime = dwClickTime;
ptLastClickPos = ptClickPos;
}
}