/****************************************************************************
* ===========================================================================
*
* 文件名: mousehandle.h
* 描述:
*
* 版本: 1.0
* 创建时间: 2013-4-5 11:22:5
* 编译环境: Visual Studio 2005
*
* 作者: 张永昌
* 单位: 华中师范大学计算机科学系
*
* ===========================================================================
*****************************************************************************/
#ifndef MOUSEHANDLE_H_
#define MOUSEHANDLE_H_
#ifndef MESSAGE_TEST
#define MESSAGE_TEST
#endif
class IMouseListener
{
public:
virtual void MouseDown(int nX, int nY) = 0;
virtual void MouseUp(int nX, int nY) = 0;
virtual void MouseDbClick(int nX, int nY) = 0;
virtual void MouseMove(int nX, int nY) = 0;
virtual ~IMouseListener();
};
class IEnventHandle
{
public:
virtual void Click(int nX, int nY) = 0;
virtual void DbClick(int nX, int nY) = 0;
virtual ~IEnventHandle();
};
#endif
#include "stdafx.h"
#include "mousehandle.h"
IMouseListener::~IMouseListener()
{
}
IEnventHandle::~IEnventHandle()
{
}
/****************************************************************************
* ===========================================================================
*
* 文件名: mousehandleimp.h
* 描述:
*
* 版本: 1.0
* 创建时间: 2013-4-6 21:32:1
* 编译环境: Visual Studio 2005
*
* 作者: 张永昌
* 单位: 华中师范大学计算机科学系
*
* ===========================================================================
*****************************************************************************/
#ifndef MOUSEHANDLEIMP_H_
#define MOUSEHANDLEIMP_H_
#include "mousehandle.h"
class MouseListener : public IMouseListener
{
public:
MouseListener(IEnventHandle *pEnventHandle);
// Interface for mouse
public:
virtual void MouseDown(int nX, int nY);
virtual void MouseUp(int nX, int nY);
virtual void MouseDbClick(int nX, int nY);
virtual void MouseMove(int nX, int nY);
public:
virtual ~MouseListener();
private:
// Internal mouse thing type
typedef enum _eMouseThing
{
CLICKTHING = 0,
DBCLICKTHING = 1
}eMouseThing;
eMouseThing m_MouseThing;
IEnventHandle *m_pEnventHandle;
// Point buffer
int m_nCachePointX;
int m_nCachePointY;
};
class ControlPointHandle : public IEnventHandle
{
public:
ControlPointHandle();
// Interface for MouseListener
public:
virtual void Click(int nX, int nY);
virtual void DbClick(int nX, int nY);
virtual ~ControlPointHandle();
private:
typedef enum _eSelectState
{
NOTBEGIN = 0,
BEGIN = 1,
END = 2
}eSelectState;
eSelectState m_SelectState;
};
#endif
#include "stdafx.h"
#include "mousehandleimp.h"
#include "controlpointimp.h"
MouseListener::MouseListener(IEnventHandle *pEnventHandle)
{
m_pEnventHandle = pEnventHandle;
}
void MouseListener::MouseDown(int nX, int nY)
{
m_nCachePointX = nX;
m_nCachePointY = nY;
}
void MouseListener::MouseUp(int nX, int nY)
{
MSG msg;
DWORD dwBegin = GetTickCount();
DWORD dwClickInterval = 0;
while (true)
{
if (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (msg.message == WM_LBUTTONDBLCLK)
{
m_MouseThing = DBCLICKTHING;
break;
}
}
dwClickInterval = GetTickCount() - dwBegin;
if (dwClickInterval > GetDoubleClickTime())
{
m_MouseThing = CLICKTHING;
m_pEnventHandle->Click(m_nCachePointX, m_nCachePointY);
break;
}
else
{
continue;
}
}
}
void MouseListener::MouseDbClick(int nX, int nY)
{
MSG msg;
DWORD dwBegin = GetTickCount();
DWORD dwClickInterval = 0;
while (true)
{
if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_LBUTTONUP && m_MouseThing == DBCLICKTHING)
{
m_pEnventHandle->DbClick(m_nCachePointX, m_nCachePointY);
break;
}
}
dwClickInterval = GetTickCount() - dwBegin;
if (dwClickInterval > GetDoubleClickTime())
{
m_MouseThing = CLICKTHING;
break;
}
else
{
continue;
}
}
m_MouseThing = CLICKTHING;
}
void MouseListener::MouseMove(int nX, int nY)
{
}
MouseListener::~MouseListener()
{
}
ControlPointHandle::ControlPointHandle()
{
}
ControlPointHandle::~ControlPointHandle()
{
}
void ControlPointHandle::Click(int nX, int nY)
{
CString sTemp;
sTemp.Format(_T("Click\n"));
TRACE(sTemp);
if (NOTBEGIN == m_SelectState)
{
m_SelectState = BEGIN;
}
else if (BEGIN == m_SelectState)
{
m_SelectState = BEGIN;
}
}
void ControlPointHandle::DbClick(int nX, int nY)
{
CString sTemp;
sTemp.Format(_T("DbClick\n"));
TRACE(sTemp);
if (BEGIN == m_SelectState)
{
m_SelectState = NOTBEGIN;
}
}