写了个用通达信收盘数据展示k线的小程序,用的cedric moonen的开源控件

加入了十字光标,选中的日期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;  
pStatic = (CStatic*)GetDlgItem(IDC_MSG);  
// CChartCandlestickSerie *pStickSerie =(CChartCandlestickSerie *) m_ChartCtrl.GetSerie(0);
if(pStickSerie != NULL)
{
int cnt = pStickSerie->GetPointsCount();
for(int i = 0; i < cnt ; i++)
{
SChartCandlestickPoint stickPt = pStickSerie->GetPoint(i);
if(stickPt.Low > pa->y || stickPt.High < pa->x)continue;
if(stickPt.XVal > pa->x+0.2|| stickPt.XVal < pa->x-0.2)continue;
s.Format("最低 = %.2f,最高 = %.2f,开盘 = %.2f,收盘 = %.2f",stickPt.Low,stickPt.High,stickPt.Open,stickPt.Close);
break;
}
pStatic->SetWindowText(s); 
}else
{
s.Format("没有数据!");
pStatic->SetWindowText(s); 
}
return 1;  

}  

源代码 https://download.csdn.net/download/wang9213/10438807

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值