⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stkui.cpp.svn-base

📁 股票软件源码
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
// StkUI.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "StkUI.h"
#include <io.h>
#include <afxsock.h>

#include "MainFrm.h"
#include "ChildFrm.h"
#include "StaticDoc.h"
#include "View/WizardView.h"
#include "View/SimuView.h"
#include "View/InfoView.h"
#include "Dialog/SetPrpt.h"
#include "Dialog/SelectStk.h"
#include "Dialog/SetRate.h"
#include "Dialog/SetRule.h"
#include "Dialog/SimuReport.h"
#include "Dialog/SimuRealOp.h"
#include "Dialog/CloseStrategyDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CStkUIApp theApp;

/////////////////////////////////////////////////////////////////////////////
// CStkUIApp

BEGIN_MESSAGE_MAP(CStkUIApp, CWinApp)
	//{{AFX_MSG_MAP(CStkUIApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_FILE_NEW, OnFileNew)
	ON_COMMAND(ID_STRATEGY_NEW, OnStrategyNew)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND(ID_STRATEGY_SAVE, OnStrategySave)
	ON_UPDATE_COMMAND_UI(ID_STRATEGY_SAVE, OnUpdateStrategySave)
	ON_COMMAND(ID_STRATEGY_SAVE_AS, OnStrategySaveAs)
	ON_UPDATE_COMMAND_UI(ID_STRATEGY_SAVE_AS, OnUpdateStrategySaveAs)
	ON_COMMAND(ID_STRATEGY_CLOSE, OnStrategyClose)
	ON_UPDATE_COMMAND_UI(ID_STRATEGY_CLOSE, OnUpdateStrategyClose)
	ON_COMMAND(ID_STRATEGY_SAVEALL, OnStrategySaveall)
	ON_UPDATE_COMMAND_UI(ID_STRATEGY_SAVEALL, OnUpdateStrategySaveall)
	//}}AFX_MSG_MAP
	// Standard print setup command
	ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStkUIApp construction

CStkUIApp::CStkUIApp()
{
	m_pMutex = NULL;
	m_pStaticDoc = NULL;
	m_bAutoUpdateViews = TRUE;
}

BOOL CALLBACK SplashProgressCallback(DWORD dwCode, DWORD dwProgress,
							LPCTSTR lpszMsg, void *cookie)
{
	HWND	hMainWnd	=	(HWND)cookie;

	if( PROG_PROGRESS == dwCode && ::IsWindow(hMainWnd) )
	{
		::SendMessage( hMainWnd, WM_USER_SPLASH_PROGRESS, dwProgress, (LPARAM)lpszMsg );
	}

	MSG		msg;
	while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) )
		AfxGetApp()->PumpMessage();
	return TRUE;
}

BOOL CALLBACK StartupProgressCallback(DWORD dwCode, DWORD dwProgress,
							LPCTSTR lpszMsg, void *cookie)
{
	HWND	hMainWnd	=	(HWND)cookie;

	if( PROG_PROGRESS == dwCode && ::IsWindow(hMainWnd) )
	{
		::SendMessage( hMainWnd, WM_USER_STARTUP_PROGRESS, dwProgress, (LPARAM)lpszMsg );
	}

	MSG		msg;
	while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) )
		AfxGetApp()->PumpMessage();
	return TRUE;
}

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;
}

BOOL CALLBACK LoadProgram( HWND hWnd, int nMinProgress, int nMaxProgress )
{
	int nMin = nMinProgress;
	int nMax = nMaxProgress;
	int nRange = nMaxProgress-nMinProgress;
	CStkUIApp * pApp = AfxGetStkUIApp();
	if( NULL == pApp )
		return FALSE;

	CStaticDoc * pStaticDoc = pApp->GetStaticDoc();
	CMainFrame * pMainFrame = AfxGetMainFrame();

	HINSTANCE hInstanceOld = AfxGetResourceHandle();
	AfxSetResourceHandle( AfxGetInstanceHandle() );

	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin, 0 );

	AfxGetStockContainer().Load( &AfxGetDB(), NULL, NULL );
	AfxGetDomainContainer().Load( AfxGetProfile().GetDomainFile() );
	AfxGetGroupContainer().Load( AfxGetProfile().GetGroupFile() );
	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*4/30, 0 );

	pMainFrame->m_SearchBox.InitStocks( TRUE, TRUE, TRUE );
	//pMainFrame->m_DateBox.InitDates( );
	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*8/30, 0 );

	// Open Simulation Strategy
	if( NULL == pApp->GetFirstStrategyPosition() )
	{
		if( 0 == pApp->OpenLastOpenedStrategy( ) )
			pApp->OpenDefaultStrategy( );
	}
	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*12/30, 0 );

	// Show Views
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CWizardView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CWizardView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*14/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CSimuView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CSimuView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*16/30, 0 );
	if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CSListView) ) )
		pStaticDoc->ShowStaticView( RUNTIME_CLASS(CSListView), TRUE );
	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*18/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CRealTimeView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CRealTimeView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*20/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CMultiSortView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CMultiSortView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*22/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CGraphView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CGraphView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*24/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CBaseView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CBaseView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*26/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CInfoView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CInfoView), TRUE );
	//SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMin+nRange*28/30, 0 );
	//if( !pStaticDoc->GetViewIfExist( RUNTIME_CLASS(CSelectorView) ) )
	//	pStaticDoc->ShowStaticView( RUNTIME_CLASS(CSelectorView), TRUE );

	AfxSwitchToStaticView( RUNTIME_CLASS(CSListView) );

	AfxGetProfile().SetCurrentStock( STKLIB_CODE_SZZS, FALSE );
	pMainFrame->m_SearchBox.SetCurrentWindowText( );
	//pMainFrame->m_DateBox.SetWindowPos(NULL,0,0,135,200,SWP_NOMOVE|SWP_SHOWWINDOW|SWP_NOZORDER|SWP_NOREDRAW);

	AfxBeginThread( LoadKDataCacheMain, NULL, THREAD_PRIORITY_NORMAL);

	SendMessage( hWnd, WM_USER_STARTUP_PROGRESS, nMax, 0 );

	AfxSetResourceHandle( hInstanceOld );

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CStkUIApp initialization

TCHAR szRegKeyCompany[] = _T("Tsking Stock Software");
TCHAR szRegKeyApp[] = _T("Tsking");

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);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// 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;
	}

	// 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;
	}

	// Create MainFrame and Static Doc and child frames and static views
	CStaticDoc * pStaticDoc = CStaticDoc::OpenDocumentFile( NULL );
	if( NULL == pStaticDoc )
	{
		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( NULL == pMainFrame )
	{
		AfxMessageBox( IDS_STATICDOC_FAILED, MB_OK | MB_ICONINFORMATION );
		delete pStaticDoc;
		SetStaticDoc( NULL );
		return FALSE;
	}
	SetMainWnd( pMainFrame );

	// 股票行情接收
	AfxGetStkReceiver().CreateReceiver(pMainFrame);
	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();
	//*/

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

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

	// 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);
	pMainFrame->m_SearchBox.SetCurrentWindowText();

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

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

	// The one and only window has been initialized, so show and update it.
	// Load Last WindowPlacement
	WINDOWPLACEMENT wp;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -