📄 stockcontrolctl.cpp
字号:
// StockControlCtl.cpp : Implementation of the CStockControlCtrl ActiveX Control class.
#include "stdafx.h"
#include "StockControl.h"
#include "StockControlCtl.h"
#include "StockControlPpg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int api_get_jjz_ai_mark(CString str);
IMPLEMENT_DYNCREATE(CStockControlCtrl, COleControl)
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CStockControlCtrl, COleControl)
//{{AFX_MSG_MAP(CStockControlCtrl)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDBLCLK()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONDBLCLK()
ON_WM_RBUTTONUP()
ON_WM_KEYDOWN()
ON_WM_KEYUP()
ON_WM_ACTIVATE()
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CStockControlCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CStockControlCtrl)
DISP_PROPERTY_NOTIFY(CStockControlCtrl, "Action", m_nAction, OnActionChanged, VT_I2)
DISP_FUNCTION(CStockControlCtrl, "LoadKLines", LoadKLines, VT_EMPTY, VTS_BSTR)
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CStockControlCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CStockControlCtrl, COleControl)
//{{AFX_EVENT_MAP(CStockControlCtrl)
// NOTE - ClassWizard will add and remove event map entries
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages
// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CStockControlCtrl, 1)
PROPPAGEID(CStockControlPropPage::guid)
END_PROPPAGEIDS(CStockControlCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CStockControlCtrl, "STOCKCONTROL.StockControlCtrl.1",
0xd810d9c5, 0x475c, 0x4f5d, 0x81, 0x8e, 0xe2, 0x84, 0xb, 0x9c, 0xbb, 0x54)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CStockControlCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DStockControl =
{ 0x1bb07a08, 0x9605, 0x4975, { 0x9b, 0xe0, 0x64, 0x18, 0x21, 0xc1, 0xe9, 0xd5 } };
const IID BASED_CODE IID_DStockControlEvents =
{ 0xfb9af3fb, 0xc2f1, 0x436f, { 0x94, 0x1, 0xef, 0x45, 0xf4, 0x88, 0xb5, 0x72 } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwStockControlOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CStockControlCtrl, IDS_STOCKCONTROL, _dwStockControlOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CStockControlCtrl::CStockControlCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CStockControlCtrl
BOOL CStockControlCtrl::CStockControlCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// TODO: Verify that your control follows apartment-model threading rules.
// Refer to MFC TechNote 64 for more information.
// If your control does not conform to the apartment-model rules, then
// you must modify the code below, changing the 6th parameter from
// afxRegApartmentThreading to 0.
if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_STOCKCONTROL,
IDB_STOCKCONTROL,
afxRegApartmentThreading,
_dwStockControlOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CStockControlCtrl::CStockControlCtrl - Constructor
CStockControlCtrl::CStockControlCtrl()
{
InitializeIIDs(&IID_DStockControl, &IID_DStockControlEvents);
m_pStockView=NULL;
// TODO: Initialize your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CStockControlCtrl::~CStockControlCtrl - Destructor
CStockControlCtrl::~CStockControlCtrl()
{
// TODO: Cleanup your control's instance data here.
// delete m_pKline;
delete m_pStockView;
}
/////////////////////////////////////////////////////////////////////////////
// CStockControlCtrl::OnDraw - Drawing function
void CStockControlCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
// TODO: Replace the following code with your own drawing code.
pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
if(!m_pStockView)
{
m_pKline=new CStockKline;
CRect rc;
GetClientRect(&rc);
int nWidth=rc.Width();
int nHigh=rc.Height();
rc.SetRect(rc.TopLeft().x+20,rc.TopLeft().y+40,rc.BottomRight().x-60,rc.BottomRight().y-40);
nWidth=rc.Width();
nHigh=rc.Height();
//在此装载K线图,设置视图区域
m_pStockView=new CStockView(this,m_pKline,rc);
}
if(m_pStockView)
m_pStockView->OnDraw(pdc);
}
/////////////////////////////////////////////////////////////////////////////
// CStockControlCtrl::DoPropExchange - Persistence support
void CStockControlCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
// TODO: Call PX_ functions for each persistent custom property.
}
/////////////////////////////////////////////////////////////////////////////
// CStockControlCtrl::OnResetState - Reset control to default state
void CStockControlCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange
// TODO: Reset any other control state here.
}
/////////////////////////////////////////////////////////////////////////////
// CStockControlCtrl::AboutBox - Display an "About" box to the user
void CStockControlCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_STOCKCONTROL);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CStockControlCtrl message handlers
/////////////////////////////////////////////////////////////////////////////
// CCadGraphControlCtrl message handlers
//控件视图操作的方法
//如缩放、平移、开窗显示
void CStockControlCtrl::OnActionChanged()
{
// TODO: Add notification handler code
m_pStockView->SetEvent(m_nAction);
SetModifiedFlag();
}
//下面是对一系列的鼠标、键盘消息的重载
void CStockControlCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_pStockView)
m_pStockView->OnLButtonDown(nFlags,point);
COleControl::OnLButtonDown(nFlags, point);
}
void CStockControlCtrl::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_pStockView)
m_pStockView->OnLButtonUp(nFlags,point);
COleControl::OnLButtonUp(nFlags, point);
}
void CStockControlCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_pStockView)
m_pStockView->OnLButtonDblClk(nFlags,point);
COleControl::OnLButtonDblClk(nFlags, point);
}
void CStockControlCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_pStockView)
m_pStockView->OnMouseMove(nFlags,point);
COleControl::OnMouseMove(nFlags, point);
}
void CStockControlCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_pStockView)
m_pStockView->OnRButtonDown(nFlags,point);
COleControl::OnRButtonDown(nFlags, point);
}
void CStockControlCtrl::OnRButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_pStockView)
m_pStockView->OnRButtonDblClk(nFlags,point);
COleControl::OnRButtonDblClk(nFlags, point);
}
void CStockControlCtrl::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_pStockView)
m_pStockView->OnRButtonUp(nFlags,point);
COleControl::OnRButtonUp(nFlags, point);
}
void CStockControlCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(m_pStockView)
m_pStockView->OnKeyDown(nChar,nRepCnt,nFlags);
COleControl::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CStockControlCtrl::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(m_pStockView)
m_pStockView->OnKeyUp(nChar,nRepCnt,nFlags);
COleControl::OnKeyUp(nChar, nRepCnt, nFlags);
}
void CStockControlCtrl::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
COleControl::OnActivate(nState, pWndOther, bMinimized);
// TODO: Add your message handler code here
}
//用户自定义函数,在此对线的各个节点的参数进行赋值
//其数据源可以是文件、数据库、网络数据包
//在此的示范程序是以自定义的文件格式提供
BOOL CStockControlCtrl::LoadKLine(CString strFileName)
{
CString buffer;
CStdioFile* stfile = new CStdioFile(strFileName,CFile::modeRead);
while(stfile->ReadString(buffer) != FALSE)
{
buffer.TrimLeft("(");
buffer.TrimRight(")");
int no = buffer.Find(" ");
CString _date = buffer.Left(no);
buffer = buffer.Right(buffer.GetLength() - no-1);
no = buffer.Find(" ");
CString _open = buffer.Left(no);
buffer = buffer.Right(buffer.GetLength() - no-1);
no = buffer.Find(" ");
CString _high = buffer.Left(no);
buffer = buffer.Right(buffer.GetLength() - no-1);
no = buffer.Find(" ");
CString _low = buffer.Left(no);
buffer = buffer.Right(buffer.GetLength() - no-1);
no = buffer.Find(" ");
// CString _close = buffer.Left(no);
CString _close = buffer;
buffer = buffer.Right(buffer.GetLength() - no-1);
no = buffer.Find(" ");
CString _kl = buffer.Left(no);
buffer = buffer.Right(buffer.GetLength() - no-1);
no = buffer.Find(" ");
CString _ks = buffer.Left(no);
buffer = buffer.Right(buffer.GetLength() - no-1);
no = buffer.Find(" ");
CString _km = buffer.Left(no);
buffer = buffer.Right(buffer.GetLength() - no-1);
no = buffer.Find(" ");
CString _km1 = buffer.Left(no);
buffer = buffer.Right(buffer.GetLength() - no-1);
no = buffer.Find(" ");
CString _km2 = buffer.Left(no);
buffer = buffer.Right(buffer.GetLength() - no-1);
no = buffer.Find(" ");
CString _ai0 = buffer.Left(no);
buffer = buffer.Right(buffer.GetLength() - no-1);
no = buffer.Find(" ");
CString _ai1 = buffer.Left(no);
int i_ai0 = api_get_jjz_ai_mark(_ai0);
int i_ai1 = api_get_jjz_ai_mark(_ai1);
int ai_flag = i_ai0|i_ai1;
CScn *pScn=m_pStockView->GetScn();
m_pKline->AddKlineNode(pScn,atoi(_date),atof(_open)/10000,atof(_high)/10000,atof(_low)/10000,atof(_close)/10000,
atof(_kl),atof(_ks),atof(_km),atof(_km1),atof(_km2),ai_flag);
}
delete stfile;
return TRUE;
}
int api_get_jjz_ai_mark(CString str)
{
CString _ai0 = str;
_ai0.MakeUpper();
int i_ai0 = 0x0000;
if(_ai0.Compare("AIBUY_L") == 0)
i_ai0 = JJZ_AIBUY_L;
else if(_ai0.Compare("AIBUY_S")== 0)
i_ai0 = JJZ_AIBUY_S;
else if(_ai0.Compare("AIBUY_W")== 0)
i_ai0 = JJZ_AIBUY_W;
else if(_ai0.Compare("AISEL_M")== 0)
i_ai0 = JJZ_AISEL_M;
else if(_ai0.Compare("AIDN")== 0)
i_ai0 = JJZ_AIDN;
else if(_ai0.Compare("AIUP")== 0)
i_ai0 = JJZ_AIUP;
else if(_ai0.Compare("AIDN_S")== 0)
i_ai0 = JJZ_AIDN_S;
else if(_ai0.Compare("AIUP_S")== 0)
i_ai0 = JJZ_AIUP_S;
else if(_ai0.Compare("AISEL_L")== 0)
i_ai0 = JJZ_AISEL_L;
else if(_ai0.Compare("AISEL_S")== 0)
i_ai0 = JJZ_AISEL_S;
else if(_ai0.Compare("WARN")== 0)
i_ai0 = JJZ_AIWARN;
return i_ai0;
}
//控件的打开K线图的方法
void CStockControlCtrl::LoadKLines(LPCTSTR sFileName)
{
// TODO: Add your dispatch handler code here
// LoadKLine("E:\\Paper\\Data\\jjz_data.txt");
LoadKLine(sFileName);
Invalidate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -