📄 simuview.cpp.svn-base
字号:
// SimuView.cpp : implementation of the CSimuView class
//
#include "stdafx.h"
#include "../StaticDoc.h"
#include "SimuView.h"
#include "Simulation.h"
#include "../ParamDlg/SetParamDlg.h"
#include "../Dialog/SimuAdvancedDlg.h"
#include "../Dialog/SimuRealOp.h"
#include <io.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSimuView
#define SIMUVIEW_TIMER_WARNING 1
IMPLEMENT_DYNCREATE(CSimuView, CFormView)
BEGIN_MESSAGE_MAP(CSimuView, CFormView)
//{{AFX_MSG_MAP(CSimuView)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_SETFOCUS()
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_SETPRPT, OnSetprpt)
ON_BN_CLICKED(IDC_SELECTSTK, OnSelectstk)
ON_BN_CLICKED(IDC_SETRULE, OnSetrule)
ON_BN_CLICKED(IDC_SETRATE, OnSetrate)
ON_BN_CLICKED(IDC_REPORT, OnReport)
ON_BN_CLICKED(IDC_REALOP, OnRealOp)
ON_BN_CLICKED(IDC_START, OnStart)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_NOTIFY(DTN_CLOSEUP, IDC_TIME_BEGIN, OnCloseupTimeBegin)
ON_NOTIFY(DTN_CLOSEUP, IDC_TIME_END, OnCloseupTimeEnd)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_ADVANCED, OnAdvanced)
//}}AFX_MSG_MAP
// Standard printing commands
ON_MESSAGE(WM_USER_GETVIEWTITLE, OnGetViewTitle)
ON_MESSAGE(WM_USER_GETVIEWCMDID, OnGetViewCmdid)
ON_MESSAGE(WM_USER_CANCLOSEVIEW, OnCanCloseView)
ON_MESSAGE(WM_USER_COLORCHANGE, OnColorChange)
ON_MESSAGE(WM_USER_SIMULATION_YIELD, OnSimulationYield)
ON_MESSAGE(WM_USER_SIMULATION_PROGRESS, OnSimulationProgress)
ON_MESSAGE(WM_USER_SIMULATION_END, OnSimulationEnd)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSimuView construction/destruction
CSimuView::CSimuView()
: CFormView(CSimuView::IDD)
{
//{{AFX_DATA_INIT(CSimuView)
m_strBuyMulti = _T("");
m_tmBegin = 0;
m_tmEnd = 0;
m_nStartAmount = 0;
m_strSellMulti = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
m_pStrategy = NULL;
m_nStartAmount = 100;
m_bDisableAllControls = FALSE;
}
CSimuView::~CSimuView()
{
}
/***
初始化主数据类型ComboBox
*/
BOOL CSimuView::InitComboMaindataType( )
{
m_comboMaindataType.ResetContent();
int mdtype, nIndex, nSel = CB_ERR;
for( mdtype = CKData::mdtypeMin; mdtype <= CKData::mdtypeMax; mdtype ++ )
{
nIndex = m_comboMaindataType.AddString( AfxGetMaindataTypeString(mdtype) );
m_comboMaindataType.SetItemData( nIndex, mdtype );
if( CKData::mdtypeClose == mdtype )
nSel = nIndex;
}
m_comboMaindataType.SetCurSel( nSel );
return TRUE;
}
/***
初始化买入逻辑选择ComboBox
*/
BOOL CSimuView::InitComboBuyLogic( )
{
m_comboBuyLogic.ResetContent();
int nLogic, nIndex, nSel = CB_ERR;
for( nLogic = COpParam::logicMin; nLogic <= COpParam::logicMax; nLogic ++ )
{
nIndex = m_comboBuyLogic.AddString( AfxGetLogicString(nLogic) );
m_comboBuyLogic.SetItemData( nIndex, nLogic );
if( COpParam::logicAnd == nLogic )
nSel = nIndex;
}
m_comboBuyLogic.SetCurSel( nSel );
return TRUE;
}
/***
初始化买入信号ComboBox
*/
BOOL CSimuView::InitComboBuyLimit( )
{
return ( m_comboBuyLimit.Initialize( )
&& m_comboBuyLimit.Select( ITSG_BUY ) );
}
/***
初始化卖出逻辑ComboBox
*/
BOOL CSimuView::InitComboSellLogic( )
{
m_comboSellLogic.ResetContent();
int nLogic, nIndex, nSel = CB_ERR;
for( nLogic = COpParam::logicMin; nLogic <= COpParam::logicMax; nLogic ++ )
{
nIndex = m_comboSellLogic.AddString( AfxGetLogicString(nLogic) );
m_comboSellLogic.SetItemData( nIndex, nLogic );
if( COpParam::logicOr == nLogic )
nSel = nIndex;
}
m_comboSellLogic.SetCurSel( nSel );
return TRUE;
}
/***
初始化卖出信号ComboBox
*/
BOOL CSimuView::InitComboSellLimit( )
{
return ( m_comboSellLimit.Initialize()
&& m_comboSellLimit.Select( ITSG_SELL ) );
}
/***
初始化操作仓位ComboBox
*/
BOOL CSimuView::InitComboStoreDiv( )
{
m_comboStoreDiv.ResetContent();
int nStoreDiv, nIndex, nSel = CB_ERR;
for( nStoreDiv = COpParam::storedivMin; nStoreDiv <= COpParam::storedivMax; nStoreDiv ++ )
{
nIndex = m_comboStoreDiv.AddString( AfxGetStoreDivString(nStoreDiv) );
m_comboStoreDiv.SetItemData( nIndex, nStoreDiv );
if( COpParam::storedivThird == nStoreDiv )
nSel = nIndex;
}
m_comboStoreDiv.SetCurSel( nSel );
return TRUE;
}
/***
根据当前状态,使不能修改的控件变灰
*/
BOOL CSimuView::EnableControls( )
{
if( !::IsWindow(m_btnStart.GetSafeHwnd())
|| !::IsWindow(m_btnSetPrpt.GetSafeHwnd())
|| !::IsWindow(m_btnSelectStk.GetSafeHwnd())
|| !::IsWindow(m_btnSetRate.GetSafeHwnd())
|| !::IsWindow(m_btnSetRule.GetSafeHwnd())
|| !::IsWindow(m_btnReport.GetSafeHwnd())
|| !::IsWindow(m_btnRealOp.GetSafeHwnd()) )
return FALSE;
CStrategy * pStrategy = GetStrategy( );
BOOL bEnable = TRUE;
CString strBtnStart;
if( NULL == pStrategy )
{
bEnable = FALSE;
strBtnStart.LoadString( IDS_SIMUVIEW_START );
m_btnStart.SetWindowText( strBtnStart );
m_btnStart.EnableWindow( FALSE );
m_btnStop.EnableWindow( FALSE );
m_staticYield.SetWindowPos( NULL, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE );
m_staticYield2.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 );
CString strWarning;
strWarning.LoadString( IDS_SIMUVIEW_MSGNOSTRATEGY );
m_staticWarning.SetWindowText( strWarning );
}
else if( pStrategy->SimuIsStatusInit() )
{
bEnable = TRUE;
strBtnStart.LoadString( IDS_SIMUVIEW_START );
m_btnStart.SetWindowText( strBtnStart );
m_btnStart.EnableWindow( TRUE );
m_btnStop.EnableWindow( FALSE );
m_staticYield.SetWindowPos( NULL, 0, 0, 0, 0, SWP_HIDEWINDOW | SWP_NOMOVE | SWP_NOSIZE );
m_staticYield2.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 );
}
else if( pStrategy->SimuIsStatusRunning() )
{
bEnable = FALSE;
strBtnStart.LoadString( IDS_SIMUVIEW_PAUSE );
m_btnStart.SetWindowText( strBtnStart );
m_btnStart.EnableWindow( TRUE );
m_btnStop.EnableWindow( TRUE );
m_staticYield.SetWindowPos( NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
m_staticYield2.SetWindowPos( NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
m_progress.SetWindowPos( NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
}
else if( pStrategy->SimuIsStatusPaused() )
{
bEnable = FALSE;
strBtnStart.LoadString( IDS_SIMUVIEW_CONTINUE );
m_btnStart.SetWindowText( strBtnStart );
m_btnStart.EnableWindow( TRUE );
m_btnStop.EnableWindow( TRUE );
m_staticYield.SetWindowPos( NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
m_staticYield2.SetWindowPos( NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
m_progress.SetWindowPos( NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
}
else
{
bEnable = TRUE;
strBtnStart.LoadString( IDS_SIMUVIEW_START );
m_btnStart.SetWindowText( strBtnStart );
m_btnStart.EnableWindow( TRUE );
m_btnStop.EnableWindow( FALSE );
m_staticYield.SetWindowPos( NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
m_staticYield2.SetWindowPos( NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
m_progress.SetWindowPos( NULL, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
}
if( m_bDisableAllControls )
bEnable = FALSE;
m_btnSetPrpt.EnableWindow( bEnable );
m_btnSelectStk.EnableWindow( bEnable );
m_btnSetRate.EnableWindow( bEnable );
m_btnSetRule.EnableWindow( bEnable );
m_btnReport.EnableWindow( bEnable );
m_btnRealOp.EnableWindow( bEnable );
m_comboKType.EnableWindow( bEnable );
m_comboMaindataType.EnableWindow( bEnable );
m_comboBuyLogic.EnableWindow( bEnable );
m_comboBuyLimit.EnableWindow( bEnable );
m_comboSellLogic.EnableWindow( bEnable );
m_comboSellLimit.EnableWindow( bEnable );
m_comboStoreDiv.EnableWindow( bEnable );
m_btnAdvanced.EnableWindow( bEnable );
m_editBuyMulti.EnableWindow( bEnable );
m_editSellMulti.EnableWindow( bEnable );
m_editStartAmount.EnableWindow( bEnable );
m_tmctrlBegin.EnableWindow( bEnable );
m_tmctrlEnd.EnableWindow( bEnable );
if( !m_bDisableAllControls && pStrategy && pStrategy->SimuIsStatusPaused() )
{
m_btnReport.EnableWindow( TRUE );
m_btnRealOp.EnableWindow( TRUE );
}
if( m_bDisableAllControls )
{
m_btnStart.EnableWindow( FALSE );
m_btnStop.EnableWindow( FALSE );
}
return TRUE;
}
/***
重新初始化各个控件的初始选择
*/
BOOL CSimuView::ClearData( )
{
// KType
m_comboKType.InitializeDay( );
// Maindata Type
InitComboMaindataType( );
// BuyLogic
InitComboBuyLogic( );
// Buy Rule
InitComboBuyLimit( );
// SellLogic
InitComboSellLogic( );
// Sell Rule
InitComboSellLimit( );
// StoreDiv
InitComboStoreDiv( );
m_editStockTech.SetWindowText( NULL );
m_progress.SetRange( 0, STRATEGY_MAX_PROGRESS );
m_progress.SetPos( 0 );
return TRUE;
}
/***
通用函数,选择ComboBox的相应项
*/
BOOL CSimuView::SelectComboItem( CComboBox & combo, DWORD dwData )
{
for( int i=0; i<combo.GetCount(); i++ )
{
if( dwData == combo.GetItemData(i) )
{
combo.SetCurSel(i);
return TRUE;
}
}
return FALSE;
}
CStrategy * CSimuView::GetStrategy( )
{
return m_pStrategy;
}
/***
是否能改变当前活动策略
*/
BOOL CSimuView::CanChangeActiveStrategy( )
{
CStrategy * pStrategy = GetStrategy();
if( pStrategy
&& pStrategy->SimuIsStatusRunning()
&& IDNO == AfxMessageBox( IDS_SIMUVIEW_RUNCANNOTCLOSE, MB_YESNO ) )
{
return FALSE;
}
if( pStrategy && pStrategy->SimuIsStatusRunning() )
m_simulation.Pause();
return StoreToStrategy( );
}
/***
当前活动策略换成了其他策略时,调用此函数
*/
void CSimuView::OnActiveStrategyChanged( )
{
if( m_pStrategy )
{
m_pStrategy->ClearCache();
StoreToStrategy( );
m_pStrategy = NULL;
}
m_pStrategy = AfxGetActiveStrategy( );
OnUpdate( NULL, UPDATE_HINT_SIMUVIEW_REREALRUN, NULL );
}
/***
将策略显示到策略视图中
*/
BOOL CSimuView::LoadFromStrategy( )
{
ClearData( );
CStrategy * pStrategy = GetStrategy( );
// Set Title
CString strTitle;
strTitle.LoadString( IDS_SIMUVIEW_SIMU );
if( pStrategy )
strTitle = CString("[") + (LPCTSTR)pStrategy->GetName() + "]" + strTitle;
m_staticTitle.SetWindowText( strTitle );
m_staticWarning.SetWindowText( "" );
if( NULL == pStrategy )
return FALSE;
m_editStockTech.SetWindowText( pStrategy->GetStockTechString( ) );
COpParam & opparam = pStrategy->GetOpParam( );
if( !opparam.IsValid() )
opparam.SetDefaultOfInvalidMember();
// KType
if( !m_comboKType.Select( opparam.m_nKType ) )
m_comboKType.InitializeDay();
// MaindataType
if( !SelectComboItem( m_comboMaindataType, opparam.m_nMaindataType ) )
InitComboMaindataType( );
// BuyLogic
if( !SelectComboItem( m_comboBuyLogic, opparam.m_nBuyLogic ) )
InitComboBuyLogic( );
// BuyLimit
if( !SelectComboItem( m_comboBuyLimit, opparam.m_nBuyLimit ) )
InitComboBuyLimit( );
// SellLogic
if( !SelectComboItem( m_comboSellLogic, opparam.m_nSellLogic ) )
InitComboSellLogic( );
// SellLimit
if( !SelectComboItem( m_comboSellLimit, opparam.m_nSellLimit ) )
InitComboSellLimit( );
// StoreDiv
if( !SelectComboItem( m_comboStoreDiv, opparam.m_nStoreDiv ) )
InitComboStoreDiv( );
// Buy and Sell Multi
m_strBuyMulti.Format( "%.2f", opparam.m_dBuyMulti * 100. );
m_strSellMulti.Format( "%.2f", opparam.m_dSellMulti * 100 );
// Start Amount
m_nStartAmount = opparam.m_nStartAmount/10000;
// Time
CSPTime tmCurrent = CSPTime::GetCurrentTime();
m_tmBegin = CSPTime(tmCurrent.GetYear(),tmCurrent.GetMonth(),tmCurrent.GetDay(),0,0,0,0);
m_tmBegin = m_tmBegin - CSPTimeSpan( 365 * 3, 0, 0, 0 );
m_tmEnd = CSPTime(tmCurrent.GetYear(),tmCurrent.GetMonth(),tmCurrent.GetDay(),23,59,59,0);
m_tmEnd = m_tmEnd - CSPTimeSpan( 1, 0, 0, 0 );
if( opparam.m_atmBegin.GetSize() > 0 )
m_tmBegin = opparam.m_atmBegin.ElementAt(0).GetTime();
if( opparam.m_atmEnd.GetSize() > 0 )
m_tmEnd = opparam.m_atmEnd.ElementAt(0).GetTime();
// TIMEZONES
// Simulation
m_simulation.SetStrategy( pStrategy, GetSafeHwnd() );
SendMessage( WM_USER_SIMULATION_PROGRESS, pStrategy->SimuGetCurrentProgress(STRATEGY_MAX_PROGRESS), NULL );
SendMessage( WM_USER_SIMULATION_YIELD, NULL, (LPARAM)(pStrategy->SimuGetCurrentYield()) );
UpdateData( FALSE );
EnableControls( );
return TRUE;
}
/***
将策略视图中的策略选项保存到策略文件中
*/
BOOL CSimuView::StoreToStrategy( )
{
UpdateData( );
CStrategy * pStrategy = GetStrategy( );
if( NULL == pStrategy )
return TRUE;
COpParam & opparam = pStrategy->GetOpParam( );
if( !opparam.IsValid() )
opparam.SetDefaultOfInvalidMember();
// KType
opparam.m_nKType = m_comboKType.GetSelect();
// MaindataType
opparam.m_nMaindataType = m_comboMaindataType.GetItemData(m_comboMaindataType.GetCurSel());
// BuyLogic
opparam.m_nBuyLogic = m_comboBuyLogic.GetItemData(m_comboBuyLogic.GetCurSel());
// BuyLimit
opparam.m_nBuyLimit = m_comboBuyLimit.GetItemData(m_comboBuyLimit.GetCurSel());
// SellLogic
opparam.m_nSellLogic = m_comboSellLogic.GetItemData(m_comboSellLogic.GetCurSel());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -