void CRealTimeView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if( UPDATE_HINT_REALTIMEVIEW != lHint )
		return;
	if( !IsWindowVisible() )
		return;
	SetFocus( );

	ASSERT( RTV_MAX_MULTICOUNT > 0 );

	CStockInfo	info;
	if( AfxGetProfile().GetCurrentStock( &info ) )
	{
		m_realtime[0].SetCurStock( info );
		m_realtime[0].PrepareStockData( );
	}
	else
	{
		m_realtime[0].SetCurStock( STKLIB_CODE_MAIN );
		m_realtime[0].PrepareStockData( );
		AfxGetProfile().SetCurrentStock( STKLIB_CODE_MAIN, FALSE );
	}
	if( CRealTime::modeReportDetail == m_realtime[0].GetDrawMode() )
		AfxGetStkReceiver().RequestStockData( CStock::dataDetail, &info, 1, 0, 0 );
	else
		AfxGetStkReceiver().RequestStockData( CStock::dataMinute, &info, 1, 0, 0 );

	// 多股同列
	int i;
	for( i=1; i<m_nMultiStockCount && i<RTV_MAX_MULTICOUNT; i++ )
	{
		if( AfxGetProfile().GetNextStock( &info ) )
		{
			m_realtime[i].SetCurStock( info );
			m_realtime[i].PrepareStockData( );
			if( CRealTime::modeReportDetail == m_realtime[0].GetDrawMode() )
				AfxGetStkReceiver().RequestStockData( CStock::dataDetail, &info, 1, 0, 0 );
			else
				AfxGetStkReceiver().RequestStockData( CStock::dataMinute, &info, 1, 0, 0 );
		}
	}
	for( i=1; i<m_nMultiStockCount && i<RTV_MAX_MULTICOUNT; i++ )
		AfxGetProfile().GetPrevStock( &info );

	Invalidate( );

	if( 1 == m_nMultiStockCount && CRealTime::modePriceLine == m_realtime[0].GetDrawMode() )
		m_wndReportTab.SetWindowPos( NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW );
	else
		m_wndReportTab.SetWindowPos( NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW );

	CMainFrame	* pFrame = AfxGetMainFrame();
	if( pFrame )
		pFrame->m_SearchBox.SetCurrentWindowText( );

	SendRequestQuote(TRUE);
}
Exemple #2
0
void CBaseView::OnDestroy() 
{
	// 停止行情刷新通知消息
	AfxGetStkReceiver().RemoveRcvDataWnd( GetSafeHwnd() );

	CEditView::OnDestroy();
}
Exemple #3
0
void CGraphView::OnDestroy() 
{
	// 停止行情刷新通知消息
	AfxGetStkReceiver().RemoveRcvDataWnd( GetSafeHwnd() );

	CView::OnDestroy();
}
Exemple #4
0
void CRealTimeView::OnDestroy() 
{
	// 停止行情刷新通知消息
	AfxGetStkReceiver().RemoveRcvDataWnd( GetSafeHwnd() );
	KillTimer( RTV_TIMER_REFRESHBIGTRADE );
	KillTimer( RTV_TIMER_REFRESH );

	CView::OnDestroy();
}
Exemple #5
0
void CMultiSortView::OnDestroy() 
{
	// 停止行情刷新通知消息
	AfxGetStkReceiver().RemoveRcvDataWnd( GetSafeHwnd() );

	KillTimer( MSV_TIMER_REFRESH );

	CView::OnDestroy();
}
void CSListView::OnDestroy() 
{
	// 停止行情刷新通知消息
	AfxGetStkReceiver().RemoveRcvDataWnd( GetSafeHwnd() );
	KillTimer( SLV_TIMER_REFRESH );

	StoreColumnOrderArray( );

	CFormView::OnDestroy();
}
Exemple #7
0
void CMultiSortView::SendRequestQuote( BOOL bForced )
{
	BOOL bInTrade = CSPTime::InTradeTime(CSPTime::GetCurrentTime().GetTime(),900);
	CView * pView = AfxGetStaticDoc()->GetActiveView();
	if( bForced || (bInTrade && pView == this) )
	{
		CStockInfo info;
		info.SetType( m_multisort.GetMultiSortClass( ) );
		AfxGetStkReceiver().RequestStockData( CStock::dataMultisort, &info, 1, 0, 0 );
	}
}
void CStartupDlg::OnOffline() 
{
	m_btnOK.EnableWindow( FALSE );
	m_btnOffline.EnableWindow( FALSE );

	UpdateData( );

	m_ctrlProgress.ShowWindow( SW_SHOW );

	m_staticInfo.SetWindowText( AfxModuleLoadString(IDS_STARTUP_LOADPROGRAM) );
	ASSERT( m_pfnLoadProgram );
	if( AfxGetStkReceiver().m_bFirst && m_pfnLoadProgram &&
		!m_pfnLoadProgram( GetSafeHwnd(), 0, STKLIB_MAX_PROGRESS ) )
	{
		CDialog::OnCancel();
		return;
	}

	AfxGetStkReceiver().m_bFirst = FALSE;

	CDialog::OnOK();
}
Exemple #9
0
int CRealTimeView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	CFont	font;
	if( !font.CreateStockObject( DEFAULT_GUI_FONT ) )
		font.CreateStockObject( ANSI_VAR_FONT );
	SetFont( &font );

	// tab
	if (!m_wndReportTab.Create(WS_VISIBLE|WS_CHILD,CRect(0,0,180,19),this,IDC_REALTIMEVIEW_REPORTTAB))
		return -1;
	
	CString	strName;
	strName.LoadString( IDS_REALTIMETAB_QUOTE );
	m_wndReportTab.Addtab( this, strName, -1);
	strName.LoadString( IDS_REALTIMETAB_PRICE );
	m_wndReportTab.Addtab( this, strName, -1);
	strName.LoadString( IDS_REALTIMETAB_MINUTE );
	m_wndReportTab.Addtab( this, strName, -1);
	strName.LoadString( IDS_REALTIMETAB_BUYSELLEX );
	m_wndReportTab.Addtab( this, strName, -1);
	strName.LoadString( IDS_REALTIMETAB_VALUE );
	m_wndReportTab.Addtab( this, strName, -1);
	strName.LoadString( IDS_REALTIMETAB_DISTRIBUTE );
	m_wndReportTab.Addtab( this, strName, -1);
	strName.LoadString( IDS_REALTIMETAB_BIGTRADE );
	m_wndReportTab.Addtab( this, strName, -1);

	m_wndReportTab.SetColorTabs(AfxGetProfile().GetColor(CColorClass::clrGraphBK));
	m_wndReportTab.SetSelectTabColor( AfxGetProfile().GetColor(CColorClass::clrGraphBK),
									AfxGetProfile().GetColor(CColorClass::clrTitle) );
	m_wndReportTab.SetAutoAjust(FALSE);
	m_wndReportTab.ShowButtonClose(FALSE);
	m_wndReportTab.SetALingTabs( CGuiTabWnd::ALN_BOTTOM );

	// m_realtime
	for( int i=0; i<RTV_MAX_MULTICOUNT; i++ )
		m_realtime[i].SetParent( this );

	// 实时行情刷新
	AfxGetStkReceiver().AddRcvDataWnd( GetSafeHwnd() );

	// 大单成交刷新
	SetTimer( RTV_TIMER_REFRESHBIGTRADE, 30000, NULL );
	SetTimer( RTV_TIMER_REFRESH, 30000, NULL );

	return 0;
}
Exemple #10
0
void CMultiSort::SetMultiSortClass( LONG type )
{
	m_lMultiSortClass	=	type;
	if( modeDirect == m_nRefreshMode )
	{
		CStockInfo info;
		info.SetType( GetMultiSortClass( ) );
		AfxGetStkReceiver().RequestStockData( CStock::dataMultisort, &info, 1, 0, 0 );
	}
	else
	{
		RecalculateSortID( TRUE, TRUE );
	}
}
Exemple #11
0
UINT LoadKDataCacheMain(LPVOID pParam)
{
	AfxGetDB().LoadKDataCache( AfxGetStockContainer(), NULL, NULL, 0, STKLIB_MAX_PROGRESS );
	AfxGetStockContainer().OnDataChanged( );

	AfxGetStkReceiver().RefreshStockContainer( AfxGetStockContainer(), TRUE );

	AfxReloadStockMain( );

	::PostMessage( AfxGetMainWnd()->GetSafeHwnd(), WM_USER_UPDATESLISTVIEW,0, 0 );
	::PostMessage( AfxGetMainWnd()->GetSafeHwnd(), WM_USER_INITDATES, 0, 0 );

	AfxEndThread( 0, TRUE );
	return 0;
}
Exemple #12
0
void CRealTimeView::SendRequestQuote( BOOL bForced )
{
	BOOL bInTrade = CSPTime::InTradeTime(CSPTime::GetCurrentTime().GetTime(),900);
	CView * pView = AfxGetStaticDoc()->GetActiveView();
	if( bForced || (bInTrade && pView == this) )
	{
		for( int i=0; i<m_nMultiStockCount && i<RTV_MAX_MULTICOUNT; i++ )
		{
			CStock & stock = m_realtime[i].GetCurStock( );
			CStockInfo & info = stock.GetStockInfo();
			if( info.IsValidStock() )
				AfxGetStkReceiver().RequestStockData( CStock::dataReport, &info, 1, 0, 0 );
		}
	}
}
LRESULT CDownloadDlg::OnStkReceiverData(WPARAM wParam, LPARAM lParam)
{
	PCOMMPACKET	pCommPacket	=	(PCOMMPACKET)lParam;

	switch( wParam )
	{
	case CStock::dataReport:
		if( pCommPacket && CStock::dataReport == pCommPacket->m_dwDataType 
			&& pCommPacket->m_dwCount > 0 )
		{
			m_nReportCount += pCommPacket->m_dwCount;
			for( DWORD i=0; i<pCommPacket->m_dwCount; i++ )
			{
				CKData kdata;
				kdata.SetKType( CKData::ktypeDay );
				KDATA kd;
				if( UpdateKDATAByREPORT( kd, &(pCommPacket->m_pReport[i]) ) )
				{
					kdata.Add( kd );
					AfxGetDB().InstallKData( kdata, FALSE );
				}
			}

			CStockContainer & container = AfxGetStockContainer();
			if( m_nReportRequestSent - m_nReportCount < 64 && m_nReportRequestSent < (UINT)container.GetSize() )
			{
				container.Lock();
				m_nReportRequestSent += AfxGetStkReceiver().RequestStockData( CStock::dataReport, container.GetData()+m_nReportRequestSent, min(160,container.GetSize()-m_nReportRequestSent), 0, 0 );
				container.UnLock();
			}

			if( !m_bReportFinished && m_nReportCount > 0.95 * m_nReportTotal )
			{
				m_bReportFinished = TRUE;
				::SendMessage( GetSafeHwnd(), WM_USER_DOWNLOAD_PROGRESS, STKLIB_MAX_PROGRESS, NULL );
				AfxBeginThread( DownloadMain, (LPVOID)m_pDownloadInfo,THREAD_PRIORITY_NORMAL);
			}
			else if( !m_bReportFinished && m_nReportTotal > 0 )
			{
				DWORD dwProgress = STKLIB_MAX_PROGRESS * m_nReportCount / m_nReportTotal;
				::SendMessage( GetSafeHwnd(), WM_USER_DOWNLOAD_PROGRESS, dwProgress, NULL );
			}
		}
		break;
	}
	return 0L;
}
Exemple #14
0
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;
}
Exemple #15
0
int CBaseView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CEditView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	GetEditCtrl().SetReadOnly( );
	GetEditCtrl().SetMargins( 20, 20 );

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

	// 实时行情刷新
	AfxGetStkReceiver().AddRcvDataWnd( GetSafeHwnd() );

	return 0;
}
void CDownloadDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	m_btnCancel.EnableWindow( FALSE );
	AfxGetStkReceiver().RemoveRcvDataWnd( GetSafeHwnd() );

	AfxReleaseDB();
	char	szErr[1024];
	if( !AfxInitializeDB( szErr, sizeof(szErr) ) )	AfxMessageBox( szErr, MB_OK|MB_ICONINFORMATION );

	CDialog::OnCancel( );

	if( m_bDBModified )
	{
		BOOL	bRecalculate	=	FALSE;
		CSPTime	tmLatest	=	0;
		if( ( m_netdb.SetRootPath( AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB )
			&& m_netdb.GetTimeLocalRange( &tmLatest, NULL, NULL )
			&& tmLatest.GetTime() > m_tmLatestOld.GetTime() ) )
		{
			bRecalculate	=	TRUE;
		}
		if( m_bAutoRun )
			bRecalculate	=	FALSE;
		AfxGetStkUIApp()->OnDBChanged( FALSE /*bRecalculate*/ );
	}

	if( !m_bAutoRun )
	{
		CNetInfoDlg	dlg;
		dlg.DoModal( );

		if( AfxGetProfile().HasNewVersion()
			&& IDYES == AfxMessageBox( IDS_DOWNLOAD_UPGRADENOW, MB_YESNO ) )
		{
			CUpgradeDlg	dlg;
			dlg.SetAutoRun( TRUE );
			dlg.DoModal();
		}
	}

	CXFDialog::PostNcDestroy();
}
Exemple #17
0
void CBaseView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	// TODO: Add your specialized code here and/or call the base class
	if( UPDATE_HINT_BASEVIEW != lHint )
		return;
	if( IsWindowVisible() )
		SetFocus( );

	CStockInfo	info;
	if( !AfxGetProfile().GetCurrentStock( &info ) )
		return;
	
	CString	strHeader	=	info.GetStockCode();
	strHeader	+=	"  ";
	strHeader	+=	info.GetStockName();
	strHeader	+=	"\r\n\r\n ";
	GetEditCtrl().SetWindowText( strHeader );
	GetEditCtrl().SetSel( strHeader.GetLength()-1, strHeader.GetLength()-1 );

	m_stock.Clear( );
	m_stock.SetStockInfo( &info );
	m_stock.SetDatabase( &AfxGetDB() );

	m_stock.PrepareBaseInfo( TRUE );

	char	* pText	=	m_stock.GetBaseTextPtr();
	int		nLength	=	m_stock.GetBaseTextLength();
	if( pText && nLength > 0 )
	{
		GetEditCtrl().ReplaceSel( pText );
	}
	else
	{
		CString	strNoBaseData;
		strNoBaseData.LoadString( IDS_BASEVIEW_NOBASEDATA );
		GetEditCtrl().ReplaceSel( strNoBaseData );
	}

	GetEditCtrl().SetSel( 0, 0 );

	AfxGetStkReceiver().RequestStockData( CStock::dataBasetext, &info, 1, 0, 0 );
}
Exemple #18
0
int CMultiSortView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	CFont	font;
	if( !font.CreateStockObject( DEFAULT_GUI_FONT ) )
		font.CreateStockObject( ANSI_VAR_FONT );
	SetFont( &font );

	m_multisort.SetParent( this );

	// 实时行情刷新
	AfxGetStkReceiver().AddRcvDataWnd( GetSafeHwnd() );

	SetTimer( MSV_TIMER_REFRESH, 30000, NULL );

	return 0;
}
Exemple #19
0
int CSListView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CFormView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// Create GridCtrl
	CRect rect;
	GetClientRect(rect);
	if( !m_Grid.Create(rect, this, IDC_SLISTVIEW_GRID, WS_CHILD|WS_BORDER|WS_TABSTOP|WS_VISIBLE|WS_VSCROLL|WS_HSCROLL) )
	{
		TRACE( "CSListView::OnCreate(...), Create m_Grid Error.\n" );
		return -1;
	}

	// fill it up with stuff
	m_Grid.SetEditable(FALSE);
	m_Grid.SetListMode(TRUE);
	m_Grid.SetHeaderSort( FALSE ); 
	m_Grid.SetSingleRowSelection(FALSE);
	m_Grid.EnableDragAndDrop(TRUE);
	m_Grid.SetGridLines( GVL_NONE );
	m_Grid.EnableTitleTips( TRUE );
	m_Grid.SetRowResize( TRUE );
	m_Grid.SetColumnResize( TRUE );

	m_Grid.SetBkColor( AfxGetProfile().GetColor(CColorClass::clrSListBK) );
	m_Grid.SetTextBkColor( AfxGetProfile().GetColor(CColorClass::clrSListBK) );
	m_Grid.SetSelectedBkColor(AfxGetProfile().GetColor(CColorClass::clrSListSelected));

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

	// 实时行情刷新
	AfxGetStkReceiver().AddRcvDataWnd( GetSafeHwnd() );

	SetTimer( SLV_TIMER_REFRESH, 3000, NULL );
	
	return 0;
}
Exemple #20
0
int CGraphView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	CFont	font;
	if( !font.CreateStockObject( DEFAULT_GUI_FONT ) )
		font.CreateStockObject( ANSI_VAR_FONT );
	SetFont( &font );

	m_graph.SetParent( this );

	// tab
	if (!m_wndReportTab.Create(WS_VISIBLE|WS_CHILD,CRect(0,0,180,19),this,IDC_GRAPHVIEW_REPORTTAB))
		return -1;
	
	CString	strName;
	strName.LoadString( IDS_GRAPHTAB_PARAM );
	m_wndReportTab.Addtab( this, strName, -1);
	strName.LoadString( IDS_GRAPHTAB_COST );
	m_wndReportTab.Addtab( this, strName, -1);
	strName.LoadString( IDS_GRAPHTAB_FLAME );
	m_wndReportTab.Addtab( this, strName, -1);
	strName.LoadString( IDS_GRAPHTAB_ACTIVITY );
	m_wndReportTab.Addtab( this, strName, -1);

	m_wndReportTab.SetColorTabs(AfxGetProfile().GetColor(CColorClass::clrGraphBK));
	m_wndReportTab.SetSelectTabColor( AfxGetProfile().GetColor(CColorClass::clrGraphBK),
									AfxGetProfile().GetColor(CColorClass::clrTitle) );
	m_wndReportTab.SetAutoAjust(FALSE);
	m_wndReportTab.ShowButtonClose(FALSE);
	m_wndReportTab.SetALingTabs( CGuiTabWnd::ALN_BOTTOM );

	// 实时行情刷新
	AfxGetStkReceiver().AddRcvDataWnd( GetSafeHwnd() );

	return 0;
}
Exemple #21
0
void CSListView::SendRequestQuote( BOOL bForced )
{
	static int nLastStart = -1;
	static int nLastCount = -1;

	BOOL bQuoteTipSended = FALSE;

	BOOL bInTrade = CSPTime::InTradeTime(CSPTime::GetCurrentTime().GetTime(),900);
	CView * pView = AfxGetStaticDoc()->GetActiveView();
	if( bForced )
	{
		CStockContainer stocks;
		CStockInfo	info;
		if( AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAIN, &info ) )
			stocks.Add(info);
		if( AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAINSZN, &info ) )
			stocks.Add(info);
		if( stocks.GetSize() > 0 )
			AfxGetStkReceiver().RequestStockData( CStock::dataReport, stocks.GetData(), stocks.GetSize(), 0, 0 );
	}
	if( bForced || pView == this )
	{
		CCellRange cr = m_Grid.GetVisibleNonFixedCellRange();
		int nStart = cr.GetMinRow() - 1;
		int nCount = cr.GetMaxRow() - cr.GetMinRow() + 1;
		CStockContainer & container = AfxGetSListStockContainer();
		container.Lock();
		if( nStart >= 0 && nCount > 0 && container.GetSize() > 0 && (bInTrade || bForced || nLastStart != nStart || nLastCount != nCount) )
		{
			nLastStart = nStart;
			nLastCount = nCount;
			AfxGetStkReceiver().RequestStockData( CStock::dataReport, container.GetData()+nStart, min(nCount,container.GetSize()-nStart), 0, 0 );
			bQuoteTipSended = (0 == nStart && nCount >= 9);
		}
		container.UnLock();
	}

	if( bInTrade )
	{
		// 预警系统所需股票行情刷新
		CAlarmCondContainer & conds = AfxGetProfile().GetAlarmCondContainer();
		CStockContainer stocks;
		stocks.SetSize( 0, conds.GetSize() + 5 );
		for( int i=0; i<conds.GetSize(); i++ )
		{
			ALARMCOND cond = conds.GetAt(i);
			CStockInfo info;
			if( AfxGetStockContainer().GetStockInfo( cond.m_szCode, &info ) )
				stocks.Add( info );
		}
		CStockInfo infoMain, infoMainSzn;
		if( AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAIN, &infoMain )
			&& AfxGetStockContainer().GetStockInfo( STKLIB_CODE_MAINSZN, &infoMainSzn ) )
		{
			stocks.Add( infoMain );
			stocks.Add( infoMainSzn );
		}

		//  行情QuoteTip 需要行情数据
		if( !bQuoteTipSended )
		{
			CStockContainer & container = AfxGetSListStockContainer();
			container.Lock();
			for( int i=0; i<9 && i<container.GetSize(); i++ )
				stocks.Add( container.ElementAt(i) );
			container.UnLock();
		}

		if( stocks.GetSize() > 0 )
			AfxGetStkReceiver().RequestStockData( CStock::dataReport, stocks.GetData(), stocks.GetSize(), 0, 0 );
	}
}
Exemple #22
0
BOOL CStkUIApp::InitInstance()
{
	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.
	AfxSocketInit( );

	AfxOleInit();

	// 程序只能启动一个实例
	m_pMutex = CreateMutex(NULL, FALSE, _T("TsKing"));
	if (m_pMutex != NULL)
	{
		if (GetLastError() == ERROR_ALREADY_EXISTS)
		{
			CloseHandle(m_pMutex);
			m_pMutex = NULL;

			return FALSE;
		}
	}

	GetVersionNumber();

	AfxGetProfile().LoadProfile( );
	::SetCurrentDirectory( AfxGetProfile().GetWorkDirectory() );
	AfxGetSView().Load( AfxGetProfile().GetSViewFile() );

	// Change the registry key under which our settings are stored.
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization.
	// SetRegistryKey( szRegKeyCompany );
	AfxRegSetValue( szRegKeyCompany, szRegKeyApp, "Install", "Path", AfxGetProfile().GetWorkDirectory() );
	AfxRegSetValue( szRegKeyCompany, szRegKeyApp, "Install", "Version", AfxGetProfile().GetVersion() );

	// change profile ( INI file )
	BOOL bEnable = AfxEnableMemoryTracking(FALSE);
	if( m_pszProfileName )	free((void*)m_pszProfileName);
	m_pszProfileName = _tcsdup(AfxGetProfile().GetWorkDirectory()+m_pszExeName+".ini");
	AfxEnableMemoryTracking(bEnable);

	LoadStdProfileSettings(64);  // Load standard INI file options (including MRU)

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	// Enable DDE Execute open
	EnableShellOpen();
	AfxUnregisterShellFileTypes();
	// AfxRegisterShellFileTypes(FALSE);

	// Empty Temp Directory
	{
		CNetDatabase netdb;
		if (netdb.SetRootPath(AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB))
			netdb.EmptyTempDirectory();
	}
	AfxSetDB(&AfxGetNetDB());
	//*/

	// Load Data
	char szErr[1024];
	if (!AfxInitializeDB(szErr, sizeof(szErr)))
	{
		AfxMessageBox(szErr, MB_OK | MB_ICONINFORMATION);
		return FALSE;
	}

	// 初始化
	AfxGetStockContainer().Load(&AfxGetDB(), NULL, NULL);				// 读取证券信息,代码表、财务、除权等
	AfxGetDomainContainer().Load(AfxGetProfile().GetDomainFile());		// 读取板块
	AfxGetGroupContainer().Load(AfxGetProfile().GetGroupFile());		// 读取自选板块

	// 分析标准外壳命令、DDE、打开文件操作的命令行
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

#ifdef _TSK_MAINFRAME
	// 注册应用程序的文档模板。文档模板
	// 将用作文档、框架窗口和视图之间的连接
	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CStaticDoc),
		RUNTIME_CLASS(CMainFrame),       // 主 SDI 框架窗口
		RUNTIME_CLASS(CSListView));
	if (!pDocTemplate)
		return FALSE;
	AddDocTemplate(pDocTemplate);

	// 调度在命令行中指定的命令。如果
	// 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
#else
	// Create MainFrame and Static Doc and child frames and static views
	CStaticDoc* pStaticDoc = CStaticDoc::OpenDocumentFile(NULL);
	if (pStaticDoc == NULL)
	{
		AfxMessageBox(IDS_STATICDOC_FAILED, MB_OK | MB_ICONINFORMATION);
		return FALSE;
	}
	pStaticDoc->m_bAutoDelete = FALSE;
	CString	strAppTitle;
	strAppTitle.LoadString(AFX_IDS_APP_TITLE);
	pStaticDoc->SetTitle(strAppTitle);
	SetStaticDoc(pStaticDoc);

	// Create MainFrame
	CMainFrame* pMainFrame = CMainFrame::CreateNewFrame();
	if (pMainFrame == NULL)
	{
		AfxMessageBox(IDS_STATICDOC_FAILED, MB_OK | MB_ICONINFORMATION);
		delete pStaticDoc;
		SetStaticDoc(NULL);
		return FALSE;
	}
	SetMainWnd(pMainFrame);
#endif

	// 股票行情接收
	AfxGetStkReceiver().CreateReceiver(m_pMainWnd);
	AfxGetStkReceiver().NetEngineSetAutoReport(FALSE);

	/* Show Startup Window
	CStartupDlg startup;
	CBitmap	bmp;
	bmp.LoadBitmap(IDB_DLGLEFTLOGO);
	startup.SetBitmap((HBITMAP)bmp.GetSafeHandle());
	startup.SetLoadProgramFunc(LoadProgram);
	if (IDOK != startup.DoModal())
	{
		pMainFrame->SendMessage(WM_CLOSE);
		return FALSE;
	}
	//*/

	/* Show Splash Window
	CSplashDlg splash;
	CBitmap bmp;
	bmp.LoadBitmap(IDB_SPLASH);
	splash.SetBitmap(HBITMAP(bmp.GetSafeHandle()));
	splash.Create(NULL, 0, AfxGetSView().GetU(), AfxGetSView().GetS(), AfxGetVersionString(), FALSE, 0, STKLIB_MAX_PROGRESS);
	splash.ShowWindow(SW_SHOW);
	splash.UpdateWindow();
	LoadProgram(splash.GetSafeHwnd(), 0, STKLIB_MAX_PROGRESS);
	splash.DestroyWindow();
	//*/

	// //////////////////////////////////////////////////////////////

	// Open Simulation Strategy
	if (GetFirstStrategyPosition() == NULL)
	{
		if (OpenLastOpenedStrategy() == 0)
			OpenDefaultStrategy();
	}

	//if (!AfxGetStaticDoc()->GetViewIfExist(RUNTIME_CLASS(CSListView)))
	//	AfxGetStaticDoc()->ShowStaticView(RUNTIME_CLASS(CSListView), TRUE);

	//AfxSwitchToStaticView(RUNTIME_CLASS(CSListView));

	AfxGetProfile().SetCurrentStock(STKLIB_CODE_SZZS, FALSE);
	((CMainFrame*)m_pMainWnd)->m_SearchBox.InitStocks( TRUE, TRUE, TRUE );
	((CMainFrame*)m_pMainWnd)->m_SearchBox.SetCurrentWindowText();

	//*//////////////////////////////////////////////////////////////

	// Dispatch commands specified on the command line
	if( CCommandLineInfo::AppUnregister == cmdInfo.m_nShellCommand )
	{
		AfxUnregisterShellFileTypes();
		if (!cmdInfo.m_bRunEmbedded)
			AfxMessageBox(AFX_IDP_UNREG_DONE, MB_OK | MB_ICONINFORMATION);
		if (m_pCmdInfo == NULL)
		{
			m_pCmdInfo = new CCommandLineInfo;
			m_pCmdInfo->m_nShellCommand = CCommandLineInfo::AppUnregister;
		}
		return FALSE;
	}

	// Dispatch commands specified on the command line
	if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileOpen)
	{
		OpenStrategyFile(cmdInfo.m_strFileName);
		AfxSwitchToStaticView(RUNTIME_CLASS(CSimuView));
	}

	// 启动通视接收系统,不显示选择接收系统对话框
	//AfxGetStkReceiver().EngineBeginWorking(FALSE);

	// The one and only window has been initialized, so show and update it.
	// Load Last WindowPlacement
	WINDOWPLACEMENT wp;
	if (AfxGetProfile().GetWindowPlacement(&wp))
		m_pMainWnd->SetWindowPlacement(&wp);
	else
		m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);

	// Enable drag/drop open
	//m_pMainWnd->DragAcceptFiles();

	// Check New Version
	m_pMainWnd->SetTimer(TIMER_AUTOUPDATE, 5000, NULL);

	return TRUE;
}
void CDownloadDlg::OnOK() 
{
	UpdateData( );

	// clear error pac msg
	m_astrErrorPac.RemoveAll();

	// disable and enble buttons
	m_btnOK.EnableWindow( FALSE );
	m_btnCancel.EnableWindow( FALSE );
	m_btnProxySet.EnableWindow( FALSE );
	m_btnRefreshServers.EnableWindow( FALSE );
	m_btnStop.EnableWindow( TRUE );

	BOOL	bOK	=	TRUE;

	// Set Message
	SendMessage( WM_USER_DOWNLOAD_MESSAGE, PROG_NEWGROUP, IDS_DLMSG_CONNECTING );
	m_staticStatus.SetWindowPos( NULL, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_SHOWWINDOW);
	MSG		msg;
	while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) )
		AfxGetApp()->PumpMessage();
	
	// set server info
	if( bOK && !m_netdb.SetRootPath( AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB ) )
	{
		AfxMessageBox( IDS_ROOTPATH_ERROR, MB_OK | MB_ICONINFORMATION );
		bOK	=	FALSE;
	}
	CString	strServer;
	m_comboServers.GetWindowText( strServer );
	CDownloadServer	server;
	if( !server.FromString( strServer ) )
	{
		AfxMessageBox( IDS_NOSERVER_DEFINED, MB_OK | MB_ICONINFORMATION );
		bOK	=	FALSE;
	}
	AfxGetProfile().SetDefaultServer( strServer );
	
	if( bOK && !m_netdb.SetServer( server.m_strAddress, server.m_nPort ) )
	{
		AfxMessageBox( IDS_NOSERVER_DEFINED, MB_OK | MB_ICONINFORMATION );
		bOK	=	FALSE;
	}
	// set access type
	if( bOK && !m_netdb.SetAccessType( AfxGetQSProfile().GetAccessType(), AfxGetQSProfile().GetProxyType(),
			AfxGetQSProfile().GetProxyAddress(), AfxGetQSProfile().GetProxyPort(),
			AfxGetQSProfile().GetProxyUser(), AfxGetQSProfile().GetProxyPasswd() ) )
	{
		AfxMessageBox( IDS_NOSERVER_DEFINED, MB_OK | MB_ICONINFORMATION );
		bOK	=	FALSE;
	}

	// login
	if( bOK && !m_netdb.Login( AfxGetSView().GetS(), AfxGetSView().GetU(),
							   NULL, AfxGetProfile().GetVersion() ) )
	{
		char	szErr[1024];
		if( m_netdb.GetLastErrorMessage(szErr,1023) )
			AfxMessageBox( szErr, MB_OK | MB_ICONINFORMATION );
		else
			AfxMessageBox( IDS_LOGIN_FAILED, MB_OK | MB_ICONINFORMATION );
		bOK	=	FALSE;
	}
	// load package info
	if( bOK && ! m_netdb.NetloadPackageInfo( NULL, NULL ) )
	{
		char	szErr[1024];
		if( m_netdb.GetLastErrorMessage(szErr,1023) )
			AfxMessageBox( szErr, MB_OK | MB_ICONINFORMATION );
		else
			AfxMessageBox( IDS_DOWNLOAD_FAILED, MB_OK | MB_ICONINFORMATION );
		bOK	=	FALSE;
	}

	if( bOK )
	{
		// show message
		m_staticStatus.SetWindowPos( NULL, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_SHOWWINDOW);
		m_ctrlProgress.SetWindowPos( NULL, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_SHOWWINDOW);
		CString	strMsg;
		strMsg.LoadString( IDS_DATA_DOWNLOADING );
		m_staticStatus.SetWindowText( strMsg );

		CDownloadDlg::m_hEventKillDownloadThread = CreateEvent(NULL,FALSE,FALSE,NULL);
		CDownloadDlg::m_hEventDownloadThreadKilled = CreateEvent(NULL,FALSE,FALSE,NULL);

		if( NULL == m_pDownloadInfo )
			m_pDownloadInfo	=	new DOWNLOAD_INFO;
		memset( m_pDownloadInfo, 0, sizeof(DOWNLOAD_INFO) );
		m_pDownloadInfo->hMainWnd	=	GetSafeHwnd();
		m_pDownloadInfo->pNetDB		=	&m_netdb;
		m_pDownloadInfo->bReport	=	m_btnCheckReport.GetCheck();
		m_pDownloadInfo->bDay		=	m_btnCheckDay.GetCheck();
		m_pDownloadInfo->tmDayFrom	=	m_tmDayFrom.GetTime();
		m_pDownloadInfo->tmDayTo	=	m_tmDayTo.GetTime();
		m_pDownloadInfo->bMin5		=	m_btnCheckMin5.GetCheck();
		m_pDownloadInfo->tmMin5From	=	m_tmMin5From.GetTime();
		m_pDownloadInfo->tmMin5To	=	m_tmMin5To.GetTime();
		m_pDownloadInfo->bBase		=	m_btnCheckBase.GetCheck();
		m_pDownloadInfo->bXDR		=	m_btnCheckXDR.GetCheck();

		if( m_pDownloadInfo->bReport )
		{
			::SendMessage( GetSafeHwnd(), WM_USER_DOWNLOAD_MESSAGE, PROG_NEWGROUP, IDS_DLMSG_REPORT );
			::SendMessage( GetSafeHwnd(), WM_USER_DOWNLOAD_PROGRESS, 0, NULL );
			m_nReportCount = 0;
			m_bReportFinished = FALSE;
			AfxGetStkReceiver().AddRcvDataWnd( GetSafeHwnd() );
			CStockContainer & container = AfxGetStockContainer();
			container.Lock();
			m_nReportTotal = container.GetSize();
			m_nReportRequestSent = AfxGetStkReceiver().RequestStockData( CStock::dataReport, container.GetData(), min(160,container.GetSize()), 0, 0 );
			container.UnLock();
		}
		else
		{
			AfxBeginThread( DownloadMain, (LPVOID)m_pDownloadInfo,THREAD_PRIORITY_NORMAL);
		}
	}
	else
	{
		// disable and enble buttons
		m_btnOK.EnableWindow( TRUE );
		m_btnCancel.EnableWindow( TRUE );
		m_btnProxySet.EnableWindow( TRUE );
		m_btnRefreshServers.EnableWindow( TRUE );
		m_btnStop.EnableWindow( FALSE );
	}
}
void CStartupDlg::OnOK() 
{
	m_btnOK.EnableWindow( FALSE );
	m_btnOffline.EnableWindow( FALSE );

	UpdateData( );

	m_ctrlProgress.ShowWindow( SW_SHOW );

	int nSel = m_comboServer.GetCurSel();
	if( CB_ERR == nSel )
	{
		AfxMessageBox( AfxModuleLoadString(IDS_SELECTSRV_NOSELECTED) );
		m_btnOK.EnableWindow( TRUE );
		if( !m_bDisableOffline )
			m_btnOffline.EnableWindow( TRUE );
		m_ctrlProgress.ShowWindow( SW_HIDE );
		return;
	}

	int i = m_comboServer.GetItemData(nSel);
	CQuoteServerArray & aServers = AfxGetQSProfile().GetQuoteServers();
	if( i >= 0 && i < aServers.GetSize() )
	{
		AfxGetQSProfile().SetCurrentServer(i);
		CQuoteServer & qs = aServers.ElementAt(i);

		// Save
		qs.m_strUser = m_strUser;
		qs.m_strPasswd = m_strPasswd;
		qs.m_bSavePasswd = m_bSavePasswd;
		if( !qs.m_bSavePasswd )
			qs.m_strPasswd.Empty();

		// Load
		m_strAddress = qs.m_strAddress;
		m_nPort = qs.m_nPort;
	}
	AfxGetQSProfile().StoreProfile();

	m_staticInfo.SetWindowText( AfxModuleLoadString(IDS_STARTUP_CONNECTSERVER) );

	AfxBeginThread( RefreshServers, NULL, THREAD_PRIORITY_NORMAL);

	if( !AfxGetStkReceiver().NetEngineBeginWorking( m_strAddress, m_nPort, m_strUser, m_strPasswd ) )
	{
		m_staticInfo.SetWindowText( AfxModuleLoadString(IDS_STARTUP_CONNECTFAILED) );
		m_btnOK.EnableWindow( TRUE );
		if( !m_bDisableOffline )
			m_btnOffline.EnableWindow( TRUE );
		m_ctrlProgress.ShowWindow( SW_HIDE );
		return;
	}

	m_staticInfo.SetWindowText( AfxModuleLoadString(IDS_STARTUP_LOADPROGRAM) );
	ASSERT( m_pfnLoadProgram );
	if( AfxGetStkReceiver().m_bFirst && m_pfnLoadProgram &&
		!m_pfnLoadProgram( GetSafeHwnd(), 0, STKLIB_MAX_PROGRESS ) )
	{
		CDialog::OnCancel();
		return;
	}

	AfxGetStkReceiver().m_bFirst = FALSE;

	CDialog::OnOK();
}
BOOL CDownloadDlg::OnInitDialog() 
{
	CXFDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_staticRefreshServer.SetWindowPos( NULL, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_HIDEWINDOW);
	m_staticStatus.SetWindowPos( NULL, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_HIDEWINDOW);
	m_ctrlProgress.SetWindowPos( NULL, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_HIDEWINDOW);

	m_btnStopRefresh.EnableWindow( FALSE );
	m_btnStop.EnableWindow( FALSE );

	InitComboServers();

	m_ctrlProgress.SetRange( 0, STKLIB_MAX_PROGRESS );
	m_ctrlProgress.SetPos( 0 );
	m_btnCheckReport.SetCheck( AfxGetStkReceiver().NetEngineIsWorking() );
	m_btnCheckReport.EnableWindow( AfxGetStkReceiver().NetEngineIsWorking() );
	m_btnCheckDay.SetCheck( TRUE );

	// Set Time
	CSPTime	tmCurrent	=	CSPTime::GetCurrentTime();
	if( tmCurrent.GetHour() < 15 )
		tmCurrent	-=	CSPTimeSpan(1,0,0,0);

	if( tmCurrent.GetMonth() == 1 && tmCurrent.GetDay() == 1 )
		tmCurrent	-=	CSPTimeSpan(1,0,0,0);
	if( tmCurrent.GetMonth() == 5 && tmCurrent.GetDay() == 1 )
		tmCurrent	-=	CSPTimeSpan(1,0,0,0);
	if( tmCurrent.GetMonth() == 10 && tmCurrent.GetDay() == 1 )
		tmCurrent	-=	CSPTimeSpan(1,0,0,0);
	if( tmCurrent.GetDayOfWeek() == 1 )
		tmCurrent	-=	CSPTimeSpan(2,0,0,0);
	if( tmCurrent.GetDayOfWeek() == 7 )
		tmCurrent	-=	CSPTimeSpan(1,0,0,0);
	
	m_tmDayFrom		=	m_netdb.GetTimeInitial().GetTime();
	m_tmDayTo		=	tmCurrent;
	m_tmMin5From	=	m_tmMin5To	=	tmCurrent;

	CSPTime	tmLatest;
	if( m_netdb.SetRootPath( AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB )
		&& m_netdb.GetTimeLocalRange( &tmLatest, NULL, NULL ) )
	{
		CString	strTimeLatest	=	(LPCTSTR)AfxGetTimeString( tmLatest.GetTime(), "%Y-%m-%d", TRUE ); //tmLatest.Format( "%Y-%m-%d,%A" );
		m_staticLatest.SetWindowText( strTimeLatest );

		m_tmDayFrom	=	CSPTime(tmLatest.GetTime()) + CSPTimeSpan(1,0,0,0 );

		if( m_tmDayFrom.GetMonth() == 1 && m_tmDayFrom.GetDay() == 1 )
			m_tmDayFrom	+=	CSPTimeSpan(1,0,0,0);
		if( m_tmDayFrom.GetMonth() == 5 && m_tmDayFrom.GetDay() == 1 )
			m_tmDayFrom	+=	CSPTimeSpan(1,0,0,0);
		if( m_tmDayFrom.GetMonth() == 10 && m_tmDayFrom.GetDay() == 1 )
			m_tmDayFrom	+=	CSPTimeSpan(1,0,0,0);
		if( m_tmDayFrom.GetDayOfWeek() == 1 )
			m_tmDayFrom	+=	CSPTimeSpan(1,0,0,0);
		if( m_tmDayFrom.GetDayOfWeek() == 7 )
			m_tmDayFrom	+=	CSPTimeSpan(2,0,0,0);
		
		if( m_tmDayFrom > m_tmDayTo )
			m_tmDayTo	=	m_tmDayFrom;
	}

	// Initial Download
	if( m_bInitDownloadTime )
	{
		m_tmDayFrom	=	m_tmDLBegin;
		m_tmDayTo	=	m_tmDLEnd;
	}

	UpdateData( FALSE );

	if( m_bAutoRun )
	{
		UpdateWindow( );
		ShowWindow( SW_SHOW );
		OnOK( );
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}