VC++处理鼠标拖拽中鼠标随意点击引起的误操作

来源:互联网 发布:php fpm 重启 编辑:程序博客网 时间:2024/06/06 14:04

在鼠标拖拽时,经常会出现由于随意点击而引起的误操作。需要对这种误操作进行“去抖动”操作。考虑读取鼠标左键松开消息。进行对比。如果有左键松开消息,认为误操作。采取以下方式处理。

//确信要拖动,而不是随便点击
 //按下左键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.

原创粉丝点击