加入了十字光标,选中的日期k线数据在右侧表现 自定义光标监听类 并发坐标消息
#define MESSAGE_UPDATEPOS WM_USER+002
struct pointlf
{
double x;
double y;
};
class CCustomCursorListener : public CChartCursorListener
{
public:
void OnCursorMoved(CChartCursor *pCursor, double xValue, double yValue)
{
pointlf pt;
pt.x = xValue;
pt.y = yValue;
SendMessage(m_hwnd,MESSAGE_UPDATEPOS,DWORD(&pt),0);
// Do something with the string...
}
double x,y;
void GetHwnd(HWND hwnd)
{
m_hwnd = hwnd;
}
HWND m_hwnd;
};
在控件面板初始化代码中加入
CChartCrossHairCursor* pCrossHair = m_ChartCtrl.CreateCrossHairCursor();
HWND hWnd = this->GetSafeHwnd();
m_pCursorListener = new CCustomCursorListener;
m_pCursorListener->GetHwnd(hWnd);
pCrossHair->RegisterListener(m_pCursorListener);
注册监听事件
控件头文件中加入
afx_msg LRESULT OnUpdateData(WPARAM wp,LPARAM lp);
头文件中用到的变量
CChartCtrl m_ChartCtrl;
CCustomCursorListener* m_pCursorListener;
CChartCandlestickSerie *pStickSerie;
cpp中加入
BEGIN_MESSAGE_MAP(CStocknoteDlg, CDialog)
//{{AFX_MSG_MAP(CStocknoteDlg)
ON_MESSAGE(MESSAGE_UPDATEPOS,OnUpdateData)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
LRESULT CStocknoteDlg::OnUpdateData(WPARAM wp,LPARAM lp)
{
CString s;
pointlf* pa =(pointlf*)wp;
CStatic* pStatic;}
源代码 https://download.csdn.net/download/wang9213/10438807