K线已经绘制成功,下面要做一个分析软件的简单框架。新建三个VIEW。
第一个为CDataView,显示交易数据
第二个为CFormulaView,显示公式,将用到TA-LIB库文件
第三个为CKlineView,显示K线图
将窗口分成三份,左侧上方为CKlineView,下方为CFormulaView,右侧为CDataView
新建一个MFC MDI程序。
在ChildFrm.cpp中加入切分窗口程序
- BOOL CChildFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
- CCreateContext* pContext)
- {
- CRect rect ;
- GetClientRect(rect);
- m_wndSplitter1.CreateStatic(this,1,2);
- m_wndSplitter1.CreateView(0,1,RUNTIME_CLASS(CDataView),CSize(0,0),pContext);
- m_wndSplitter2.CreateStatic(&m_wndSplitter1,2,1,
- WS_CHILD|WS_VISIBLE,m_wndSplitter1.IdFromRowCol(0,0));
- m_wndSplitter1.SetColumnInfo(0,750,200);
- m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(CKlineView),CSize(0,450),pContext);
- m_wndSplitter2.CreateView(1,0,RUNTIME_CLASS(CFormulaView),CSize(0,0),pContext);
- return TRUE;
- }
下一步将重绘三个视图的OnDraw函数形成完整的分析软件示例,数据将用工商银行601398的月线来进行测试。
为了对照,将工商银行的BMP图形读到View中来。读BMP的方法如下
- HBITMAP hbmp=
- (HBITMAP)LoadImage(NULL,"d://blog//601318.bmp",IMAGE_BITMAP,0,
- 0,LR_CREATEDIBSECTION|LR_LOADFROMFILE);
- CBitmap cbmp;
- cbmp.Attach(hbmp);
- BITMAP bmp;
- cbmp.GetBitmap(&bmp);
- cbmp.Detach();
- UINT * pData = new UINT[bmp.bmWidth * bmp.bmHeight];
- BITMAPINFO bmpInfo;
- bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bmpInfo.bmiHeader.biWidth = bmp.bmWidth;
- bmpInfo.bmiHeader.biHeight = -bmp.bmHeight;
- bmpInfo.bmiHeader.biPlanes = 1;
- bmpInfo.bmiHeader.biCompression = BI_RGB;
- bmpInfo.bmiHeader.biBitCount = 32;
- GetDIBits(pDC->m_hDC,hbmp,0,bmp.bmHeight,pData,&bmpInfo,DIB_RGB_COLORS);
- UINT color, r, g, b;
- for(int i = 0; i < bmp.bmWidth * bmp.bmHeight; i++)
- {
- color = pData[i];
- b = color<<8>>24;
- g = color<<16>>24;
- r = color<<24>>24;
- r = 0;
- pData[i] = RGB(r,g,b);
- }
- SetDIBits(pDC->m_hDC, hbmp,0, bmp.bmHeight, pData,&bmpInfo, DIB_RGB_COLORS);
- CDC dcmem;
- dcmem.CreateCompatibleDC(pDC);
- HGDIOBJ hold=::SelectObject(dcmem.m_hDC,hbmp);
- pDC->BitBlt(0,0,bmp.bmWidth,bmp.bmHeight,&dcmem,0,0,SRCCOPY);
- ::SelectObject(dcmem.m_hDC,hold);
- delete pData;
- DeleteObject(hbmp);