step 1.未RealTimeView:添加鼠标移动事件消息处理
添加
src/Client/StkUI/View/RealTimeView.h
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
/****extend 鼠标移动 by freeman****/
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
/**************************************/
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnRealtimePrev();
afx_msg void OnRealtimeNext();
添加ON_WM_MOUSEMOVE()消息和对应的处理函数OnMouseMove()
src/Client/StkUI/View/RealTimeView.cpp
BEGIN_MESSAGE_MAP(CRealTimeView, CView)
//{{AFX_MSG_MAP(CRealTimeView)
ON_WM_CREATE()
ON_WM_WINDOWPOSCHANGED()
ON_WM_DESTROY()
ON_WM_TIMER()
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDBLCLK()
ON_WM_KEYDOWN()
/*add by freeman*/
/**** extend 鼠标移动 by freeman ****/
ON_WM_MOUSEMOVE()
/**************************************/
ON_COMMAND(ID_REALTIME_PREV, OnRealtimePrev)
ON_COMMAND(ID_REALTIME_NEXT, OnRealtimeNext)
ON_COMMAND(ID_REALTIME_LEFT, OnRealtimeLeft)
@@ -620,6 +620,16 @@ void CRealTimeView::OnLButtonDblClk(UINT nFlags, CPoint point)
CView::OnLButtonDblClk(nFlags, point);
}
/**** extend 鼠标移动 by freeman ****/
void CRealTimeView::OnMouseMove(UINT nFlags, CPoint point)
{
//m_graph.OnMouseMove(nFlags, point);
CView::OnMouseMove(nFlags, point);
}
/**************************************/
//处理键盘事件
void CRealTimeView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
step 2:在RealTime:添加鼠标移动事件处理函数,供RealTimeView调用
定义函数
src/Client/StkUI/View/RealTime.h
void Move( int nMove, BOOL bShiftPressed, BOOL bCtrlPressed );
void OnLButtonDown( UINT nFlags, CPoint point, BOOL bShiftPressed, BOOL bCtrlPressed );
void OnLButtonDblClk( UINT nFlags, CPoint point );
/**** extend 鼠标移动 by freeman ****/
void OnMouseMove(UINT nFlags, CPoint point);
void DrawBorderMovingLine(CDC* pDC, CPoint point, BOOL bAddOrRemove);
CPoint m_ptLastMovingLine; // 记录鼠标移动线位置
/**************************************/
void ResetIndexCurrent( int nIndexCurrent = -1 );
//////////////////////////////////////////////////////////
src/Client/StkUI/View/RealTime.cpp
}
}
/**** extend 鼠标移动 by freeman ****/
void CRealTime::OnMouseMove(UINT nFlags, CPoint point)
{
if (CRealTime::modePriceLine == m_nDrawMode)
{
// Selection
int nIndexClick = -1;
CRect rect(m_rectPrice.left, m_rectPrice.top, m_rectPrice.right, m_rectAll.bottom - m_nMarginBottom);
if (rect.PtInRect(point))
{
DWORD dwSeconds = CSPTime::GetTradeSecondsOfOneDay();
for (int nIndex = 0; nIndex < m_CurStock.GetMinute().GetSize(); nIndex++)
{
CRect rectLine = rect;
DWORD sec = CSPTime(m_CurStock.GetMinute()[nIndex].m_time).ToStockTimeSecOrder();
DWORD secL = sec - 100, secR = sec + 100;
if (nIndex > 0)
secL = CSPTime(m_CurStock.GetMinute()[nIndex - 1].m_time).ToStockTimeSecOrder();
if (nIndex < m_CurStock.GetMinute().GetSize() - 1)
secR = CSPTime(m_CurStock.GetMinute()[nIndex + 1].m_time).ToStockTimeSecOrder();
rectLine.left = (int)(rect.left + rect.Width() * (secL + sec) * 0.5 / dwSeconds);
rectLine.right = (int)(rect.left + rect.Width() * (sec + secR) * 0.5 / dwSeconds);
if (rectLine.PtInRect(point))
{
nIndexClick = nIndex;
break;
}
}
}
MoveTo(nIndexClick, false, false);
}
}
/**************************************/
step 3:当鼠标在RealTimeView移动时,调用 RealTime类中的CRealTime::OnMouseMove(UINT nFlags, CPoint point) 函数显示光标
src/Client/StkUI/View/RealTimeView.cpp
/**** extend 鼠标移动 by freeman ****/
void CRealTimeView::OnMouseMove(UINT nFlags, CPoint point)
{
//m_graph.OnMouseMove(nFlags, point);
m_realtime[0].OnMouseMove(nFlags, point);
CView::OnMouseMove(nFlags, point);
}
/**************************************/