在鼠标拖拽时,经常会出现由于随意点击而引起的误操作。需要对这种误操作进行“去抖动”操作。考虑读取鼠标左键松开消息。进行对比。如果有左键松开消息,认为误操作。采取以下方式处理。
//确信要拖动,而不是随便点击
//按下左键250ms则认为要拖动
Sleep(250);
MSG msg;
::PeekMessage(
&msg,
GetSafeHwnd(),
WM_LBUTTONUP,
WM_LBUTTONUP,
PM_NOREMOVE
);
//随意点击而已,返回
if( msg.message==WM_LBUTTONUP )
return;
The PeekMessage function dispatches incoming sent messages, checks the thread message queue for a posted message, and retrieves the message (if any exist). BOOL PeekMessage(
LPMSG lpMsg, // message information
HWND hWnd, // handle to window
UINT wMsgFilterMin, // first message
UINT wMsgFilterMax, // last message
UINT wRemoveMsg // removal options
);
CWnd::GetSafeHwnd
This method obtains the window handle for a window. It returns NULL if the CWnd is not attached to a window or if it is used with a null CWnd pointer.