策略为王源代码扩展系列-SListView.cpp:增加底部科创版标签

Published

策略为王源代码扩展系列-SListView.cpp:增加底部科创版标签

step 1:增加底部标签定义

G:\stock\TskingVS2019\src\Client\StkUI\View\SListView.cpp

#define	SL_WORKTAB_CLASS	0
#define	SL_WORKTAB_A		1
#define SL_WORKTAB_SMALL	2 // extend 创业版 by freeman
#define SL_WORKTAB_MSMALL	3
#define SL_WORKTAB_STARMARKET  	4 // extend 科创版 by freeman
#define	SL_WORKTAB_SHB		5
#define	SL_WORKTAB_SZNB		6
#define	SL_WORKTAB_BOND		7
#define	SL_WORKTAB_FUND		8
#define SL_WORKTAB_RIGHT	9
#define	SL_WORKTAB_SELF		10
#define	SL_WORKTAB_GROUP	11
#define	SL_WORKTAB_DOMAIN	12

step 2:初始化底部标签数组

标签的显示顺序由定义的SL_WORKTAB_SMALL的数字决定,实际为数组的索引号。

int CSListView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
strName = _T("中小板");
	pItem = new CTSKTabManagerItem();
	pItem->SetCaption("中小板");
	AddItem(SL_WORKTAB_MSMALL, pItem);

	strName = _T("创业版");
	pItem = new CTSKTabManagerItem();
	pItem->SetCaption("创业版");
	AddItem(SL_WORKTAB_SMALL, pItem); //创业版 extend by freeman

	strName = _T("科创板");
	pItem = new CTSKTabManagerItem();
	pItem->SetCaption("科创板");
	AddItem(SL_WORKTAB_STARMARKET, pItem); //科创版 extend by freeman


}

step 3:添加点击底部标签时要显示的股票列表

//股票列表底部WORKTAB by freeman 
BOOL CSListView::OnBeforeItemClick(CTSKTabManagerItem* pItem)
{

if (!pItem) return FALSE;

	int nCur = pItem->GetIndex();
	CRect	rect = pItem->GetRect();
	CMenu	menu;
	switch(nCur)
	{
	case SL_WORKTAB_CLASS:
		if (menu.LoadMenu(IDR_MENU_SLISTBARCLASS))
		{
			CMenu* pPopupMenu = menu.GetSubMenu(0);
			if (pPopupMenu)
				pPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON , rect.left/*+3*/, rect.top-30, AfxGetMainFrame());
		}
		break;
	case SL_WORKTAB_A:
		SetCurrentStatus(CStockContainer::typeA, NULL, -1);
		break;
	case SL_WORKTAB_MSMALL:
		SetCurrentStatus(CStockContainer::typeClassMsmall, NULL, -1);
		break;
    //科创版 extend by freeman
	case SL_WORKTAB_STARMARKET:
		SetCurrentStatus(CStockContainer::typeClassStarMarket, NULL, -1);
		break;


}

step 4:股票容器中增加对应的科创版类型

src/Client/StkLib/Include/Container.h

enum StockTypes {
		typeNone		=	0x00,
		typeMin			=	0x01,
		typeIndex		=	0x01,//指数
		typeStrategy	=	0x02,
		typeGroup		=	0x03,//板块
		typeDomain		=	0x04,//板块
		typeAll			=	0x05,
		typeA			=	0x06,//A股
		typeBond		=	0x07,
		typeFund		=	0x08,
		typeClassShaa	=	0x09,//上海A股
		typeClassShab	=	0x0A,//上海B股
		typeClassSzna	=	0x0B,//深证A股
		typeClassSznb	=	0x0C,//深证B股
		typeClassShabond=	0x0D,
		typeClassSznbond=	0x0E,
		typeClassMsmall	=	0x0F,//中小板
		typeRight		=	0x10,//权证
		typeClassStarMarket = 0x11,//科创板 extend by freeman
		//typeMax			=	0x10
		typeMax        = 0x11 //changed by freeman
	};

 

2.增加ETF基金类型

Step 1:首先添加基金类型typeFund ,typeFund =0x08 来自src/Client/StkLib/Include/Container.h

src/Client/StkLib/Include/Stock.h

enum StockType {
		typeNone		=	0x00,
		typeFund        =   0x08,   //  基金  custom extend by freeman
		typeshIndex		=	0x10,	//	上海指数
		typeshA			=	0x11,	//	上海A股
		typeshB			=	0x12,	//	上海B股

 

Step 2:然后在读取股票代码表时,设置股票代码 属于哪个市场,哪个板块,要将基金代码添加到Container

src/Client/StkLib/Src/DzhProvider.cpp 

int LoadCodeTable1(CStockContainer& container, LPCTSTR lpszFileName, DWORD dwMar

 

1.读取股票代码

2.设置股票代码 属于哪个市场,哪个板块-根据股票市场和股票代码设置股票类型 

info.SetTypeAndMarket(dwMarket, block.StockCode);//根据股票市场和股票代码设置股票类型 

//自定义扩展的设置股票类型和股票代码 add by freeman
void CStockInfo::SetTypeAndMarket(DWORD dwMarket, const char* szCode)
{
	long	type = CStock::typeNone;
	m_dwMarket = dwMarket;
	//上海市场
	if (CStock::marketSHSE == dwMarket)
	{
		if (strncmp(m_szCode, "000", 3) == 0)	// 上海指数
		{
			type = CStock::typeshIndex;			dwMarket = CStock::marketSHSE;
		}
		else if (strcmp(m_szCode, "688001") >= 0 && strcmp(m_szCode, "689999") <= 0)	// 科创版
	
		{
			type = CStock::typeshStarMarket;			dwMarket = CStock::marketSHSE;
		}
		else if (strncmp(m_szCode, "60", 2) == 0)	// 上海A股
		{
			type = CStock::typeshA;			dwMarket = CStock::marketSHSE;
		}
	}
	else if (CStock::marketSZSE == dwMarket)   //深圳市场
	{
		if (strcmp(m_szCode, "000001") >= 0 && strcmp(m_szCode, "000999") <= 0)		// 深圳A股
		{
			type = CStock::typeszA;			dwMarket = CStock::marketSZSE;
		}
		else if (strcmp(m_szCode, "002001") >= 0 && strcmp(m_szCode, "002999") <= 0)	// 深圳中小企业
		{
			type = CStock::typeszMsmall;			dwMarket = CStock::marketSZSE;
		}
		else if (strcmp(m_szCode, "300001") >= 0 && strcmp(m_szCode, "301999") <= 0)	// 深圳创业板
		{
			type = CStock::typeszSmall;			dwMarket = CStock::marketSZSE;
		}
		else if (strncmp(m_szCode, "399", 3) == 0)	// 添加399*** 深圳指数判断  add by freeman 2019/06/08
		{
			type = CStock::typeszIndex;			dwMarket = CStock::marketSZSE;
		}

	}

	m_type = type;
	m_dwMarket = dwMarket;
}

 

 

3.加入股票容器

 

if ((strncmp(info.GetStockCode(), "60", 2) == 0) || (strncmp(info.GetStockCode(), "000", 3) == 0) || (strncmp(info.GetStockCode(), "001", 3) == 0) || (strncmp(info.GetStockCode(), "300", 3) == 0) || (strncmp(info.GetStockCode(), "002", 3) == 0)
			|| (strncmp(info.GetStockCode(), "399", 3) == 0) || (strncmp(info.GetStockCode(), "688", 3) == 0)
			||((strcmp(info.GetStockCode(), "159000") >= 0 && strcmp(info.GetStockCode(), "159999") <= 0)) || ((strcmp(info.GetStockCode(), "510000") >= 0 && strcmp(info.GetStockCode(), "519999") <= 0)) )
		{
			container.Add(info);
			nCount++;

 

 

Step 3:最后添加增加根据代码判断,设置为基金类型

src/Client/StkLib/Src/Stock.cpp 

void CStockInfo::ResolveTypeAndMarket()

//--- custom extend ETF 基金 by freeman 20200327--------
		else if (strcmp(m_szCode, "159000") >= 0 && strcmp(m_szCode, "159999") <= 0)	// 上海基金 ETF
		{	
			type = CStock::typeFund;			dwMarket = CStock::marketSHSE;
		}
		else if (strcmp(m_szCode, "510000") >= 0 && strcmp(m_szCode, "519999") <= 0)	// 深圳基金 ETF
		{
			type = CStock::typeFund;				dwMarket = CStock::marketSZSE;
		}
		//--- custom extend end ETF 基金 by freeman --------