策略为王源代码分析-主菜单-智能选股(SelectorView.cpp)

Published

1.智能选股的菜单点击事件

1.1 智能选股的菜单ID

IDR_MENU_MAINBARVIEW MENU 
BEGIN
    POPUP "View"
    BEGIN
        MENUITEM "向导(&W)",                      ID_VIEW_WIZARD
        MENUITEM "策略(&S)\tF11",                 ID_VIEW_SIMU
        MENUITEM "股票列表(&L)\tF2",                ID_VIEW_SLIST
        MENUITEM "分时行情图(&R)",                   ID_VIEW_REALTIME
        MENUITEM "综合排名图(&M)",                   ID_VIEW_MULTISORT
        MENUITEM "技术分析图(&G)\tF5",               ID_VIEW_GRAPH
        MENUITEM "基本资料(&B)\tF10",               ID_VIEW_BASE
        MENUITEM "在线资讯(&M)",                    ID_VIEW_INFO
        MENUITEM "智能选股(&E)",                    ID_VIEW_SELECTOR
    END
END

 

1.2.智能选股id 对应的消息函数

ON_COMMAND(ID_VIEW_SELECTOR, OnViewSelector)
	ON_UPDATE_COMMAND_UI(ID_VIEW_SELECTOR, OnUpdateViewSelector)

 

void CMainFrame::OnUpdateViewSelector(CCmdUI* pCmdUI) 
{
	CView * pView = AfxGetStaticDoc()->GetActiveView();
	pCmdUI->SetCheck(pView && pView->IsKindOf(RUNTIME_CLASS(CSelectorView)));
}

1.3.智能选股id被点击后切换到视图

G:\stock\TskingVS2019\src\Client\StkUI\View\SelectorView.h

void CMainFrame::OnViewSelector() 
{
	AfxSwitchToStaticView(RUNTIME_CLASS(CSelectorView));
}

void CMainFrame::OnUpdateViewSelector(CCmdUI* pCmdUI) 
{
	CView * pView = AfxGetStaticDoc()->GetActiveView();
	pCmdUI->SetCheck(pView && pView->IsKindOf(RUNTIME_CLASS(CSelectorView)));
}

stkui.rc

/////////////////////////////////////////////////////////////////////////////
//
// 智能选股对话框定义 by freeman
//
IDD_SELECTOR_FORM DIALOGEX 0, 0, 476, 244
STYLE DS_SETFONT | WS_CHILD | WS_BORDER
FONT 9, "宋体", 0, 0, 0x1
BEGIN
    COMBOBOX        IDC_STOCKGROUP,75,15,80,102,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
    COMBOBOX        IDC_KTYPE,204,15,69,96,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
    COMBOBOX        IDC_TECH,326,15,112,96,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
    PUSHBUTTON      "智能选股...",IDC_RUNSELECTOR,335,32,90,16,BS_FLAT
    CONTROL         "Custom1",IDC_GRID,"MFCGridCtrl",WS_BORDER | WS_TABSTOP,37,50,400,187
    LTEXT           "股票范围",IDC_STATIC,39,17,33,8
    LTEXT           "K线类型",IDC_STATIC,169,18,31,8
    LTEXT           "技术指标",IDC_STATIC,289,19,34,8
    CONTROL         "Progress1",IDC_PROGRESS,"msctls_progress32",PBS_SMOOTH,37,34,214,10,WS_EX_STATICEDGE
    LTEXT           "无选中股票。",IDC_STATIC_INFO,261,35,68,8
END

智能选股界面的条件初始初始化

StkUI\View\SelectorView.h

首先定义了股票范围、K线类型、技术指标三个对话框变量,分别由三个对话框提供。

public:
	//{{AFX_DATA(CSelectorView)
	enum { IDD = IDD_SELECTOR_FORM };
	CStatic	m_staticInfo;
	CProgressCtrl	m_progress;
	CButton		m_btnRunSelector;
	CTechComboBox	m_cmbTech; //技术指标类型,由StkUI\ParamDlg\SetParamDlg.h提供的CTechComboBox类实现
	CKTypeComboBox	m_cmbKType; //K线类型,由StkUI\ParamDlg\SetParamDlg.h提供的CKTypeComboBox类实现
	CDomainComboBox	m_cmbStockGroup;//股票范围,由StkUI\Dialog\SetGroupDlg.h
	//}}AFX_DATA

然后对股票范围、K线类型、技术指标三个对话框变量数据初始化

StkUI\View\SelectorView.cpp

void CSelectorView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	InitializeGrid( );

	m_staticInfo.SetWindowPos( NULL, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE );
	m_progress.SetWindowPos( NULL, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE );

	LOGFONT lf;
	memset( &lf, 0, sizeof(lf) );
	AfxGetProfile().GetFontSListView( &lf );
	SetFont( &lf );

	//初始化股票选择范围。如智能选股
	m_cmbStockGroup.InitStrings( TRUE, TRUE, AfxGetGroupContainer( ) );
	m_cmbStockGroup.SetCurSel( 0 );
	m_cmbStockGroup.SelectGroupAll( );

	//初始化K线类型选择框
	m_cmbKType.InitializeDay( );
	//各项技术指标种类选择框初始化。如智能选股
	m_cmbTech.Initialize();
}

 

 

2.智能选股的运行和结果显示

2.1 智能选股的运行

定义了一个变量m_container用于存放结果。

CStockContainer	m_container;

点击”智能选股...“按钮后,运行时合符条件的股票存入变量m_container中。

// run selector
	for( int i=0; i<cntn.GetSize(); i++ )
	{
....
	if( ITS_NOTHING != its )
		{
			//对应列标题:股票信息:股票名称、股票代码等
			m_container.Add( info );
			//对应列标题:买卖信号:如强势买进
			m_signals.Add( its );
			//对应列标题:说明:如多头强势、空头强势等。
			m_reasons.Add( itsc );
		}
		delete pTech;
	}

	// display result
	OnUpdate( NULL, UPDATE_HINT_SELECTORVIEW, NULL );

.....

 

调用OnUpdate( NULL, UPDATE_HINT_SELECTORVIEW, NULL );刷新视图

 

 

 

2.2.智能选股的结果显示

在OnUpdate( NULL, UPDATE_HINT_SELECTORVIEW, NULL );显示结果。