📄 stkui.cpp.svn-base
字号:
if (AfxGetProfile().GetWindowPlacement(&wp))
m_pMainWnd->SetWindowPlacement(&wp);
else
m_pMainWnd->ShowWindow( SW_SHOWMAXIMIZED );
// Dispatch commands specified on the command line
if (CCommandLineInfo::FileOpen == cmdInfo.m_nShellCommand)
{
OpenStrategyFile(cmdInfo.m_strFileName);
AfxSwitchToStaticView(RUNTIME_CLASS(CSimuView));
}
// Enable drag/drop open
m_pMainWnd->DragAcceptFiles();
// Check Evalation
m_pMainWnd->SetTimer(TIMER_AUTOUPDATE, 5000, NULL);
return TRUE;
}
BOOL CStkUIApp::OnDBChanged( BOOL bRecalculate )
{
CWaitCursor waitcursor;
// Reload DB
AfxGetStockContainer().Load( &AfxGetDB(), NULL, NULL );
AfxGetDomainContainer().Load( AfxGetProfile().GetDomainFile() );
AfxGetGroupContainer().Load( AfxGetProfile().GetGroupFile() );
AfxGetDB().LoadKDataCache( AfxGetStockContainer(), NULL, NULL, 0, STKLIB_MAX_PROGRESS );
AfxGetStockContainer().OnDataChanged( );
AfxGetStkReceiver().RefreshStockContainer( AfxGetStockContainer(), TRUE );
// Reload AfxGetStockMain()
AfxReloadStockMain( );
// Recalcuate Yield
if( bRecalculate && IDYES == AfxMessageBox( IDS_INSTALLPAC_IFRECALCULATE, MB_YESNO|MB_ICONINFORMATION ) )
{
AfxRecalculateYield( AfxGetProfile().GetYieldAverageDays(), TRUE );
AfxGetStockContainer().ReloadBase( &AfxGetDB() );
}
// Update SListBar
CMainFrame * pMainFrame = AfxGetMainFrame();
if( pMainFrame )
{
pMainFrame->m_SearchBox.InitStocks( TRUE, TRUE, TRUE );
pMainFrame->m_SearchBox.SetCurrentWindowText( );
//pMainFrame->m_DateBox.InitDates( );
//pMainFrame->m_DateBox.SetCurrentWindowText( );
}
// Update Views
AfxGetSListStockContainer().ReRetrieveFromStatic( AfxGetActiveStrategy(), TRUE );
AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_SLISTVIEW, NULL );
AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_GRAPHVIEW, NULL );
AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_BASEVIEW, NULL );
AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_SIMUVIEW_REREALRUN, NULL );
AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_SELECTORVIEW, NULL );
::PostMessage( AfxGetGroupView()->GetSafeHwnd(), WM_USER_UPDATEGROUPS, 0, 0 );
return TRUE;
}
void CStkUIApp::SaveLastOpenedStrategy( )
{
CSPStringArray astr;
POSITION pos = GetFirstStrategyPosition();
while(pos != NULL)
{
CStrategy* pStrategy = GetNextStrategy(pos);
if( pStrategy )
astr.Add( pStrategy->GetPathName() );
}
AfxGetProfile().SetLastOpenedStrategy( astr );
}
int CStkUIApp::OpenLastOpenedStrategy( )
{
CSPStringArray & astrStrategyToOpen = AfxGetProfile().GetLastOpenedStrategy( );
CSPString strLastActive = AfxGetProfile().GetLastActiveStrategy( );
if( 0 != access(strLastActive,0) )
strLastActive.Empty();
int nCount = 0;
for( int i=0; i<astrStrategyToOpen.GetSize(); i++ )
{
if( 0 != access(astrStrategyToOpen.ElementAt(i),0) )
continue;
if( NULL != OpenStrategyFile(astrStrategyToOpen.ElementAt(i)) )
{
nCount ++;
if( strLastActive.IsEmpty() )
strLastActive = astrStrategyToOpen.ElementAt(i);
}
}
if( !strLastActive.IsEmpty() )
OpenStrategyFile(strLastActive);
return nCount;
}
int CStkUIApp::OpenDefaultStrategy( )
{
CSPStringArray astrStrategyToOpen;
// Recent
if( m_pRecentFileList )
{
for( int i=m_pRecentFileList->GetSize()-1; i>=0; i-- )
{
CString strPath = (*m_pRecentFileList)[i];
if( !strPath.IsEmpty() )
astrStrategyToOpen.Add( strPath );
}
}
// projects
CString strExt = AfxGetStrategyFileExt( );
if( !strExt.IsEmpty())
{
CFileFind finder;
BOOL bWorking = finder.FindFile( AfxGetFilePath( (LPCTSTR)AfxGetProfile().GetProjectPath(), LPCTSTR("*" + strExt) ) );
while( bWorking )
{
bWorking = finder.FindNextFile();
CString strPath = finder.GetFilePath();
int i;
for( i=0; i<astrStrategyToOpen.GetSize(); i++ )
{
if( 0 == strPath.Compare( astrStrategyToOpen.ElementAt(i) ) )
break;
}
if( i == astrStrategyToOpen.GetSize() )
astrStrategyToOpen.Add( strPath );
}
finder.Close();
}
AfxGetProfile().SetLastOpenedStrategy( astrStrategyToOpen );
return OpenLastOpenedStrategy( );
}
CStrategy * CStkUIApp::GetActiveStrategy( )
{
CStrategy * pStrategy = NULL;
CStrategyView * pStrategyView = AfxGetStrategyView();
if( pStrategyView )
pStrategy = pStrategyView->GetActiveStrategy();
return pStrategy;
}
void CStkUIApp::AddStrategy(CStrategy* pStrategy)
{
if( NULL == pStrategy )
return;
ASSERT(m_strategyList.Find(pStrategy, NULL) == NULL); // must not be in list
m_strategyList.AddTail(pStrategy);
if( m_bAutoUpdateViews )
{
::SendMessage( AfxGetStrategyView()->GetSafeHwnd(), WM_USER_ADDSTRATEGY, 0, 0 );
AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_WIZARDVIEW, NULL );
// AfxGetMainFrame()->ShowWorkspBar( );
}
}
void CStkUIApp::RemoveStrategy(CStrategy* pStrategy)
{
POSITION pos = m_strategyList.Find(pStrategy);
ASSERT( NULL != pos );
if( pos )
m_strategyList.RemoveAt( pos );
if( m_bAutoUpdateViews )
{
::SendMessage( AfxGetStrategyView()->GetSafeHwnd(), WM_USER_REMOVESTRATEGY, 0, 0 );
AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_WIZARDVIEW, NULL );
}
}
POSITION CStkUIApp::GetFirstStrategyPosition() const
{
return m_strategyList.GetHeadPosition();
}
CStrategy* CStkUIApp::GetNextStrategy(POSITION& rPos) const
{
return (CStrategy*)m_strategyList.GetNext(rPos);
}
BOOL CStkUIApp::ExistStrategy( CStrategy * pStrategy )
{
POSITION pos = GetFirstStrategyPosition( );
while( NULL != pos )
{
CStrategy * p = GetNextStrategy( pos );
if( p == pStrategy )
return TRUE;
}
return FALSE;
}
BOOL CStkUIApp::IsFileOpened( LPCTSTR lpszFileName )
{
POSITION pos = GetFirstStrategyPosition();
while (pos != NULL)
{
CStrategy* pStrategy = GetNextStrategy(pos);
if( 0 == pStrategy->GetPathName().CompareNoCase( lpszFileName ) )
{
return TRUE;
}
}
return FALSE;
}
CString CStkUIApp::GetLastStrategyDirectory( )
{
CString strLastStrategyDirectory;
if( m_pRecentFileList && m_pRecentFileList->GetSize() > 0 )
{
strLastStrategyDirectory = (*m_pRecentFileList)[0];
strLastStrategyDirectory = AfxGetFileDirectoryExist( strLastStrategyDirectory, "" );
}
if( strLastStrategyDirectory.IsEmpty() || 0 != access( strLastStrategyDirectory,0) )
{
strLastStrategyDirectory = AfxGetProfile().GetProjectPath();
}
return strLastStrategyDirectory;
}
CString CStkUIApp::GetNextNewStrategyTitle( CString & strExtBuffer, CString strPath )
{
CString string;
VERIFY( string.LoadString( IDS_STRATEGY_NONAME ) );
CString strExt = AfxGetStrategyFileExt( );
if( !strExt.IsEmpty())
strExtBuffer = strExt;
CStringArray astrExistTitle;
POSITION pos = GetFirstStrategyPosition();
while( NULL != pos )
{
CStrategy * pStrategy = GetNextStrategy( pos );
astrExistTitle.Add( AfxGetFileTitleNoExt(pStrategy->GetPathName()) );
}
CFileFind finder;
BOOL bWorking = finder.FindFile( AfxGetFilePath( (LPCTSTR)strPath, LPCTSTR("*" + strExt) ) );
while( bWorking )
{
bWorking = finder.FindNextFile();
astrExistTitle.Add( finder.GetFileTitle( ) );
}
finder.Close();
for( int i=1; ; i++ )
{
CString strTemp;
strTemp.Format( "%s(%d)", string, i );
BOOL bHas = FALSE;
for( int k=0; k<astrExistTitle.GetSize(); k++ )
{
if( 0 == strTemp.CompareNoCase( astrExistTitle.ElementAt(k) ) )
{
bHas = TRUE;
break;
}
}
if( !bHas )
{
string = strTemp;
break;
}
}
return string;
}
CStrategy* CStkUIApp::OpenStrategyFile( LPCTSTR lpszPathName )
{
// Resolve File Name
TCHAR szPath[_MAX_PATH];
ASSERT(lstrlen(lpszPathName) < sizeof(szPath));
if( NULL != lpszPathName )
{
TCHAR szTemp[_MAX_PATH];
if (lpszPathName[0] == '\"')
++lpszPathName;
lstrcpyn(szTemp, lpszPathName, _MAX_PATH);
LPTSTR lpszLast = _tcsrchr(szTemp, '\"');
if (lpszLast != NULL)
*lpszLast = 0;
AfxFullPath(szPath, szTemp);
TCHAR szLinkName[_MAX_PATH];
if (AfxResolveShortcut(AfxGetMainWnd(), szPath, szLinkName, _MAX_PATH))
lstrcpy(szPath, szLinkName);
}
if( NULL != lpszPathName )
{
POSITION pos = GetFirstStrategyPosition();
while (pos != NULL)
{
CStrategy* pStrategy = GetNextStrategy(pos);
if( 0 == pStrategy->GetPathName().CompareNoCase( szPath ) )
{
if( m_bAutoUpdateViews )
{
::SendMessage( AfxGetStrategyView()->GetSafeHwnd(), WM_USER_ACTIVATESTRATEGY, DWORD(pStrategy), 0 );
AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_WIZARDVIEW, NULL );
// AfxGetMainFrame()->ShowWorkspBar( );
}
return pStrategy;
}
}
}
CStrategy * pStrategy = new CStrategy();
if( NULL == pStrategy )
return NULL;
char szErr[256];
if( !pStrategy->OpenStrategyFile( szPath, szErr, sizeof(szErr)-1 ) )
{
AfxMessageBox( szErr, MB_OK|MB_ICONINFORMATION );
delete pStrategy;
return NULL;
}
AddStrategy( pStrategy );
return pStrategy;
}
void CStkUIApp::CloseAllStrategy( BOOL bEndSession )
{
POSITION pos = GetFirstStrategyPosition();
while (pos != NULL)
{
CStrategy* pStrategy = GetNextStrategy(pos);
pStrategy->OnClose();
delete pStrategy;
}
m_strategyList.RemoveAll();
if( ! bEndSession && m_bAutoUpdateViews )
{
::SendMessage( AfxGetStrategyView()->GetSafeHwnd(), WM_USER_REMOVESTRATEGY, 0, 0 );
AfxGetStaticDoc()->UpdateAllViews( NULL, UPDATE_HINT_WIZARDVIEW, NULL );
}
}
CRecentFileList * CStkUIApp::GetRecentFileList( )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -