策略为王源代码扩展系列-K线图(1)-键盘精灵增加K线91-96快捷键功能

Published

 

摘要:首先定义了一个字符串数组,用于在键盘精灵里显示快捷键。然后定义的对应的应该发送的消息。

仿通达信,增加91-96快捷键功能。

一、快捷键原理分析

定义的快捷键的序号,这是为后面建立数组用的

G:\stock\TskingVS2019\src\Client\StkLib\Include\AfxCore.h

//组合键功能定义 by freeman
#define		ACCE_MIN	1
#define		ACCE_01		1	// 热键F1
#define		ACCE_02		2	// 热键F2
#define		ACCE_03		3	// 热键F3
#define		ACCE_04		4	// 热键F4
#define		ACCE_05		5	// 热键F5
#define		ACCE_06		6	// 热键F6
#define		ACCE_07		7	// 热键F7
#define		ACCE_08		8	// 热键F8
#define		ACCE_09		9	// 热键F9
#define		ACCE_10		10	// 热键F10
#define		ACCE_1		11	// 上A报价
#define		ACCE_2		12	// 上B报价
#define		ACCE_3		13	// 深A报价
#define		ACCE_4		14	// 深B报价
#define		ACCE_5		15	// 上债报价
#define		ACCE_6		16	// 深债报价
#define		ACCE_61		17	// 上A涨跌
#define		ACCE_62		18	// 上B涨跌
#define		ACCE_63		19	// 深A涨跌
#define		ACCE_64		20	// 深B涨跌
#define		ACCE_65		21	// 上债涨跌
#define		ACCE_66		22	// 深债涨跌
#define		ACCE_71		23	// 上证信息
#define		ACCE_72		24	// 深证信息
#define		ACCE_73		25	// 券商信息
#define		ACCE_81		26	// 上A综合
#define		ACCE_82		27	// 上B综合
#define		ACCE_83		28	// 深A综合
#define		ACCE_84		29	// 深B综合
#define		ACCE_85		30	// 上债综合
#define		ACCE_86		31	// 深债综合
#define		ACCE_LBDK	32	// 显示分时行情量比多空指标
#define		ACCE_MMLD	33	// 显示分时行情买卖力道指标
#define		ACCE_MAX	33
STKLIB_API	CSPString	AfxGetAccelerator( UINT nAcce, int nCharLeft = 8 );	// 给定快捷键编号,返回快捷键及其中文名称

定义一个数字,StkLib:注释,键盘精灵显示热键定义

G:\stock\TskingVS2019\src\Client\StkLib\Src\Strings.cpp

//////////////////////////////////////////////////////////////////////////////////
// 快捷键
// 给定快捷键唯一编号,返回快捷键及其中文名称
//键盘精灵显示热键定义 by freeman
CSPString	AfxGetAccelerator( UINT nAcce, int nCharLeft )
{
	static	CSPString	acce_names[ACCE_MAX+1];
	SP_ASSERT( ACCE_MAX >= 0 );
	
	if( acce_names[0].GetLength() <= 0 )
	{
		// acce_names
		acce_names[0]			=	"ACCENames";

#ifdef	CLKLAN_ENGLISH_US
		// 快捷键
		acce_names[ACCE_01]		=	"01      Hot Key F1";
		acce_names[ACCE_02]		=	"02      Hot Key F2";
		acce_names[ACCE_03]		=	"03      Hot Key F3";
		acce_names[ACCE_04]		=	"04      Hot Key F4";
		acce_names[ACCE_05]		=	"05      Hot Key F5";
		acce_names[ACCE_06]		=	"06      Hot Key F6";
		acce_names[ACCE_07]		=	"07      Hot Key F7";
		acce_names[ACCE_08]		=	"08      Hot Key F8";
		acce_names[ACCE_09]		=	"09      Hot Key F9";
		acce_names[ACCE_10]		=	"10      Hot Key F10";
		acce_names[ACCE_1]		=	"1       Shanghai A Shares List";
		acce_names[ACCE_2]		=	"2       Shanghai B Shares List";
		acce_names[ACCE_3]		=	"3       Shenzhen A Shares List";
		acce_names[ACCE_4]		=	"4       Shenzhen B Shares List";
		acce_names[ACCE_5]		=	"5       Shanghai Bond List";
		acce_names[ACCE_6]		=	"6       Shenzhen Bond List";
		acce_names[ACCE_61]		=	"61      Shanghai A Shares Change";
		acce_names[ACCE_62]		=	"62      Shanghai B Shares Change";
		acce_names[ACCE_63]		=	"63      Shenzhen A Shares Change";
		acce_names[ACCE_64]		=	"64      Shenzhen B Shares Change";
		acce_names[ACCE_65]		=	"65      Shanghai Bond Change";
		acce_names[ACCE_66]		=	"66      Shenzhen Bond Change";
		acce_names[ACCE_71]		=	"71      Shanghai Info.";
		acce_names[ACCE_72]		=	"72      Shenzhen Info.";
		acce_names[ACCE_73]		=	"73      Stockjobber Info.";
		acce_names[ACCE_81]		=	"81      Shanghai A Shares Sort";
		acce_names[ACCE_82]		=	"82      Shanghai B Shares Sort";
		acce_names[ACCE_83]		=	"83      Shenzhen A Shares Sort";
		acce_names[ACCE_84]		=	"84      Shenzhen B Shares Sort";
		acce_names[ACCE_85]		=	"85      Shanghai Bond Sort";
		acce_names[ACCE_86]		=	"86      Shenzhen Bond Sort";
		acce_names[ACCE_LBDK]	=	"LBDK    Volume Ratio";
		acce_names[ACCE_MMLD]	=	"MMLD    Consign Ratio";
#else
		// 快捷键
		acce_names[ACCE_01]		=	"01      热键F1";
		acce_names[ACCE_02]		=	"02      热键F2";
		acce_names[ACCE_03]		=	"03      热键F3";
		acce_names[ACCE_04]		=	"04      热键F4";
		acce_names[ACCE_05]		=	"05      热键F5";
		acce_names[ACCE_06]		=	"06      热键F6";
		acce_names[ACCE_07]		=	"07      热键F7";
		acce_names[ACCE_08]		=	"08      热键F8";
		acce_names[ACCE_09]		=	"09      热键F9";
		acce_names[ACCE_10]		=	"10      热键F10";
		acce_names[ACCE_1]		=	"1       上A报价";
		acce_names[ACCE_2]		=	"2       上B报价";
		acce_names[ACCE_3]		=	"3       深A报价";
		acce_names[ACCE_4]		=	"4       深B报价";
		acce_names[ACCE_5]		=	"5       上债报价";
		acce_names[ACCE_6]		=	"6       深债报价";
		acce_names[ACCE_61]		=	"61      上A涨跌";
		acce_names[ACCE_62]		=	"62      上B涨跌";
		acce_names[ACCE_63]		=	"63      深A涨跌";
		acce_names[ACCE_64]		=	"64      深B涨跌";
		acce_names[ACCE_65]		=	"65      上债涨跌";
		acce_names[ACCE_66]		=	"66      深债涨跌";
		acce_names[ACCE_71]		=	"71      上证信息";
		acce_names[ACCE_72]		=	"72      深证信息";
		acce_names[ACCE_73]		=	"73      券商信息";
		acce_names[ACCE_81]		=	"81      上A综合";
		acce_names[ACCE_82]		=	"82      上B综合";
		acce_names[ACCE_83]		=	"83      深A综合";
		acce_names[ACCE_84]		=	"84      深B综合";
		acce_names[ACCE_85]		=	"85      上债综合";
		acce_names[ACCE_86]		=	"86      深债综合";
		acce_names[ACCE_LBDK]	=	"LBDK    量比(多空)";
		acce_names[ACCE_MMLD]	=	"MMLD    买卖力道(涨跌率)";
#endif
	}
	
	if( nAcce >= ACCE_MIN && nAcce <= ACCE_MAX )
	{
		if( 8 == nCharLeft )
			return	acce_names[nAcce];
		
		CSPString	strResult	=	acce_names[nAcce];
		int nIndex = strResult.Find( ' ' );
		if( -1 != nIndex )
			strResult	=	strResult.Left(nIndex) + strResult.Mid(8);
		return strResult;
	}
	return "";
}

按下键盘精灵的快捷键,通过发送模拟点击对应菜单项的消息来实现

G:\stock\TskingVS2019\src\Client\StkUI\AfxCore.cpp

// 快捷键
//按下键盘精灵的快捷键,则发送对应的消息 by freeman
void AfxExecuteAccelerator( UINT nAcce )
{
	HWND	hWnd	=	AfxGetMainFrame()->GetSafeHwnd();
	switch( nAcce )
	{
	case ACCE_01:		// 热键F1
		::PostMessage( hWnd, WM_COMMAND, ID_REALTIME_REPORTDETAIL, 0 );
		break;
	case ACCE_02:		// 热键F2
		::PostMessage( hWnd, WM_COMMAND, ID_VIEW_SLIST, 0 );
		break;
	case ACCE_03:		// 热键F3
		::PostMessage( hWnd, WM_COMMAND, ID_REALTIME_VIEWSZZS, 0 );
		break;
	case ACCE_04:		// 热键F4
		::PostMessage( hWnd, WM_COMMAND, ID_REALTIME_VIEWSZNCZ, 0 );
		break;
	case ACCE_05:		// 热键F5
		{
			CView * pView = AfxGetStaticDoc()->GetActiveView();
			if( pView && pView->IsKindOf( RUNTIME_CLASS(CGraphView) ) )
				::PostMessage( hWnd, WM_COMMAND, ID_VIEW_REALTIME, 0 );
			else
				::PostMessage( hWnd, WM_COMMAND, ID_VIEW_GRAPH, 0 );
		}
		break;
	case ACCE_06:		// 热键F6
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_GROUPSELF, 0 );
		break;
	case ACCE_07:		// 热键F7
		::PostMessage( hWnd, WM_COMMAND, ID_VIEW_MULTISORT, 0 );
		break;
	case ACCE_08:		// 热键F8
		break;
	case ACCE_09:		// 热键F9
		break;
	case ACCE_10:		// 热键F10
		::PostMessage( hWnd, WM_COMMAND, ID_VIEW_F10, 0 );
		break;
	case ACCE_1:		// 上A报价
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SHAA, 0 );
		break;
	case ACCE_2:		// 上B报价
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SHAB, 0 );
		break;
	case ACCE_3:		// 深A报价
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SZNA, 0 );
		break;
	case ACCE_4:		// 深B报价
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SZNB, 0 );
		break;
	case ACCE_5:		// 上债报价
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SHABOND, 0 );
		break;
	case ACCE_6:		// 深债报价
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SZNBOND, 0 );
		break;
	case ACCE_61:		// 上A涨跌
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SHAASORTDP, 0 );
		break;
	case ACCE_62:		// 上B涨跌
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SHABSORTDP, 0 );
		break;
	case ACCE_63:		// 深A涨跌
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SZNASORTDP, 0 );
		break;
	case ACCE_64:		// 深B涨跌
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SZNBSORTDP, 0 );
		break;
	case ACCE_65:		// 上债涨跌
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SHABONDSORTDP, 0 );
		break;
	case ACCE_66:		// 深债涨跌
		::PostMessage( hWnd, WM_COMMAND, ID_SLIST_SZNBONDSORTDP, 0 );
		break;
	case ACCE_71:		// 上证信息
		break;
	case ACCE_72:		// 深证信息
		break;
	case ACCE_73:		// 券商信息
		break;
	case ACCE_81:		// 上A综合
		::PostMessage( hWnd, WM_COMMAND, ID_REALTIME_MSSZAG, 0 );
		break;
	case ACCE_82:		// 上B综合
		::PostMessage( hWnd, WM_COMMAND, ID_REALTIME_MSSZBG, 0 );
		break;
	case ACCE_83:		// 深A综合
		::PostMessage( hWnd, WM_COMMAND, ID_REALTIME_MSSZNAG, 0 );
		break;
	case ACCE_84:		// 深B综合
		::PostMessage( hWnd, WM_COMMAND, ID_REALTIME_MSSZNBG, 0 );
		break;
	case ACCE_85:		// 上债综合
		::PostMessage( hWnd, WM_COMMAND, ID_REALTIME_MSSZZQ, 0 );
		break;
	case ACCE_86:		// 深债综合
		::PostMessage( hWnd, WM_COMMAND, ID_REALTIME_MSSZNZQ, 0 );
		break;
	case ACCE_LBDK:		// 量比多空
		::PostMessage( hWnd, WM_COMMAND, ID_REALTIME_LBDK, 0 );
		break;
	case ACCE_MMLD:		// 买卖力道
		::PostMessage( hWnd, WM_COMMAND, ID_REALTIME_MMLD, 0 );
		break;
	default:
		ASSERT( FALSE );
	}
}
	//::PostMessage(hWnd, WM_COMMAND, ID_VIEW_PWEEK, 0);
		SendMessage(hWnd, WM_COMMAND, ID_VIEW_PWEEK, 0);//改为用SendMessage发送模拟点击菜单项消息,用PostMessage发送股票代码老变化

二、周期线快捷键添加

(一)首先从主菜单找选择周期时发送的消息是什么

  POPUP "周期选择(&P)"
        BEGIN
            MENUITEM "日线(&D)",                      ID_VIEW_PDAY
            MENUITEM "周线(&W)",                      ID_VIEW_PWEEK
            MENUITEM "月线(&M)",                      ID_VIEW_PMONTH
            MENUITEM "五分钟线(&5)",                    ID_VIEW_PMIN5
            MENUITEM "十五分钟线(&1)",                   ID_VIEW_PMIN15
            MENUITEM "三十分钟线(&3)",                   ID_VIEW_PMIN30
            MENUITEM "六十分钟线(&6)",                   ID_VIEW_PMIN60
        END

 

选择不同的K线图周期,则发送对应的消息

可以看出,发送的对应消息是ID_VIEW_PMIN5等

G:\stock\TskingVS2019\src\Client\StkUI\MainFrm.cpp

//K线图周期发送消息函数 by freeman
#define	SWITCH_SHOW_GRAPH_COMMAND(nID, nIDLast)				\
		AfxSwitchToStaticView(RUNTIME_CLASS(CGraphView));		\
		::PostMessage(AfxGetGraphView()->GetSafeHwnd(), WM_COMMAND, nID, nIDLast);

#define	UPDATE_GRAPH_CMDUI(pCmdUI, updateFunc)				\
		CGraphView * pGraphView = AfxGetGraphView();			\
		if (pGraphView)										\
			pGraphView->updateFunc(pCmdUI);						\
		else													\
			pCmdUI->Enable(TRUE);

// K线图周期
//选择不同的K线图周期,则发送对应的消息 by freeman
void CMainFrame::OnViewPday()	{	SWITCH_SHOW_GRAPH_COMMAND(ID_VIEW_PDAY, 0);	}
void CMainFrame::OnUpdateViewPday(CCmdUI* pCmdUI)	{	UPDATE_GRAPH_CMDUI(pCmdUI,OnUpdateViewPday);	}
void CMainFrame::OnViewPweek()	{	SWITCH_SHOW_GRAPH_COMMAND(ID_VIEW_PWEEK, 0);	}  //1
void CMainFrame::OnUpdateViewPweek(CCmdUI* pCmdUI)	{	UPDATE_GRAPH_CMDUI(pCmdUI,OnUpdateViewPweek);	}  //1
void CMainFrame::OnViewPmonth()	{	SWITCH_SHOW_GRAPH_COMMAND(ID_VIEW_PMONTH, 0);	}
void CMainFrame::OnUpdateViewPmonth(CCmdUI* pCmdUI)	{	UPDATE_GRAPH_CMDUI(pCmdUI,OnUpdateViewPmonth);	}
void CMainFrame::OnViewPmin5()	{	SWITCH_SHOW_GRAPH_COMMAND(ID_VIEW_PMIN5, 0);	}
void CMainFrame::OnUpdateViewPmin5(CCmdUI* pCmdUI)	{	UPDATE_GRAPH_CMDUI(pCmdUI,OnUpdateViewPmin5);	}
void CMainFrame::OnViewPmin15()	{	SWITCH_SHOW_GRAPH_COMMAND(ID_VIEW_PMIN15, 0);	}
void CMainFrame::OnUpdateViewPmin15(CCmdUI* pCmdUI)	{	UPDATE_GRAPH_CMDUI(pCmdUI,OnUpdateViewPmin15);	}
void CMainFrame::OnViewPmin30()	{	SWITCH_SHOW_GRAPH_COMMAND(ID_VIEW_PMIN30, 0);	}
void CMainFrame::OnUpdateViewPmin30(CCmdUI* pCmdUI)	{	UPDATE_GRAPH_CMDUI(pCmdUI,OnUpdateViewPmin30);	}
void CMainFrame::OnViewPmin60()	{	SWITCH_SHOW_GRAPH_COMMAND(ID_VIEW_PMIN60, 0);	}
void CMainFrame::OnUpdateViewPmin60(CCmdUI* pCmdUI)	{	UPDATE_GRAPH_CMDUI(pCmdUI,OnUpdateViewPmin60);	}

经测试,把81代码发送的消息改为ID_VIEW_PWEEK,运行OK。

接收消息

BEGIN_MESSAGE_MAP(CGraphView, CView)
	//{{AFX_MSG_MAP(CGraphView)
	ON_WM_CREATE()
	ON_WM_WINDOWPOSCHANGED()
	ON_WM_DESTROY()
	ON_WM_ERASEBKGND()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDBLCLK()
	//ON_WM_SETCURSOR() //extend by feeman
	ON_WM_KEYDOWN()
	ON_COMMAND(ID_VIEW_PDAY, OnViewPday)   
	ON_COMMAND(ID_VIEW_PWEEK, OnViewPweek)  //接收周线消息

三、添加91等快捷键

step 1:StkLib:添加周期线快捷键,定义常量

src/Client/StkLib/Include/AfxCore.h

//*****add by freeman 扩展周期快捷键

#define		ACCE_MAX	41 //更改数组长度值
#define		ACCE_91		34	// 1分钟K线图 
#define		ACCE_92		35	// 5分钟K线图
#define		ACCE_93		36	// 15分钟K线图 
#define		ACCE_94		37	// 30分钟K线图
#define		ACCE_95		38	// 60分钟K线图 
#define		ACCE_96		39	// 日K线图
#define		ACCE_97		40	// 周K线图 
#define		ACCE_98		41	// 月K线图

//*****add end

step 2:StkLib:添加周期线快捷键,定义数组

此处的定义会在键盘精灵里显示出来。

src/Client/StkLib/Src/Strings.cpp

		acce_names[ACCE_91] = "91      1分钟";
		acce_names[ACCE_92] = "92      5分钟";
		acce_names[ACCE_93] = "93      15分钟";
		acce_names[ACCE_94] = "94      30分钟";
		acce_names[ACCE_95] = "96      60分钟";
		acce_names[ACCE_96] = "96      日K线";
		acce_names[ACCE_97] = "97      周K线";
		acce_names[ACCE_98] = "98      月K线";
		//*******add end******

 

step 3:StkUI:添加周期线快捷键,定义快捷键发送的消息

src/Client/StkUI/AfxCore.cpp

	//*****add by freeman 扩展周期快捷键********
	case ACCE_91:		// 1分钟K线图 ACCE_91 找不到?
	case ACCE_91:		// 1分钟K线图 
		::PostMessage(hWnd, WM_COMMAND, ID_VIEW_PMIN5, 0);
		break;
	case ACCE_92:		// 5分钟K线图
		::PostMessage(hWnd, WM_COMMAND, ID_VIEW_PMIN5, 0);
		break;
	case ACCE_93:		// 15分钟K线图 ?
		::PostMessage(hWnd, WM_COMMAND, ID_VIEW_PMIN15, 0);
		break;
	case ACCE_94:		// 30分钟K线图
		::PostMessage(hWnd, WM_COMMAND, ID_VIEW_PMIN30, 0);
		break;
	case ACCE_95:		// 60分钟K线图 
		::PostMessage(hWnd, WM_COMMAND, ID_VIEW_PMIN60, 0);
		break;
	case ACCE_96:		// 日K线图
		::PostMessage(hWnd, WM_COMMAND, ID_VIEW_PDAY, 0);
		break;
	case ACCE_97:		// 周K线图 
		::PostMessage(hWnd, WM_COMMAND, ID_VIEW_PWEEK, 0);
		break;
	case ACCE_98:		// 月K线图
		::PostMessage(hWnd, WM_COMMAND, ID_VIEW_PMONTH, 0);
		break;
		//*******add end******