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

📄 mainfrm.cpp

📁 程序经过了调试,直接运行就可以显示结果,为股市应用程序,VC++的
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "stock.h"
#include "Realtime.h"
#include "StockView.h"
#include "MainFrm.h"
//#include "gushi.h""
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define WM_Respose		(WM_USER+120)
#define WM_Refresh      (WM_USER+140)
#define ID_VIEW1    1
#define ID_VIEW2    2
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
CWinThread* CMainFrame::m_pReadThread = NULL;
CString CMainFrame::pCode=_T("");
CString CMainFrame::pName=_T("");
CData   CMainFrame::data;
BOOL    CMainFrame::bTime=false;
BOOL    CMainFrame::bControl=true;
char Code[50],Name[50];
int iContinue = 1;
LPCTSTR		mStock=TEXT("Software\\Microsoft\\Stock\\");
HKEY        hkey;
DWORD       dType1=REG_SZ,dSize1=sizeof(REG_SZ);
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_CLOSE()
	ON_COMMAND(IDM_KLine, OnKLine)
	ON_COMMAND(IDM_RealTime, OnRealTime)
    ON_MESSAGE(WM_Respose,OnRespose)
	ON_MESSAGE(WM_Refresh,OnRefresh)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	m_pUIFrameWnd = NULL;
	m_pUIThread = NULL;
}
CMainFrame::~CMainFrame()
{
    m_pUIFrameWnd->FreeLibrary();
	if( m_KeyCodeTable.MemCount!=0)
	{
		m_pKeyWizzard->DelKeyTableReg(&m_KeyCodeTable);
		delete[] m_KeyCodeTable.pDate;
		m_KeyCodeTable.pDate = NULL;
	}
	if(m_pKeyWizzard != NULL)
	{
		delete m_pKeyWizzard;
		m_pKeyWizzard = NULL;
	}
	KillTimer(1);
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);
    //Read regedit
/*	if(RegOpenKeyEx(HKEY_CURRENT_USER,mStock,0,KEY_ALL_ACCESS,&hkey)!=ERROR_SUCCESS)
			RegCreateKey(HKEY_CURRENT_USER,mStock,&hkey);
	if(RegQueryValueEx(hkey,TEXT("Name"),NULL,&dType1,(LPBYTE)&pName,&dSize1)!=ERROR_SUCCESS)
	{
			RegSetValueEx(hkey,"Name",0,REG_SZ,(LPBYTE)&pName,dSize1);
	}
    if(RegQueryValueEx(hkey,TEXT("Code"),NULL,&dType1,(LPBYTE)&pCode,&dSize1)!=ERROR_SUCCESS)
	{
			RegSetValueEx(hkey,"Code",0,REG_SZ,(LPBYTE)&pCode,dSize1);
	}*/
//reading information
	TCHAR szPath[] = TEXT("C:\\config.ini");
    GetPrivateProfileString("Information","Code","600000",Code,50,szPath);
	GetPrivateProfileString("Information","Name","浦发银行",Name,50,szPath);
	pCode.Format("%s",Code);
	pName.Format("%s",Name);
	data.m_strCode=pCode;
	data.m_strName=pName;
    m_pUIThread = (CUIThread*)AfxBeginThread(RUNTIME_CLASS(CUIThread), 2);	
	m_pReadThread = AfxBeginThread(CUIFrameWnd::ReadRingThread, &iContinue, 0, 0, CREATE_SUSPENDED, NULL);
	m_pUIThread ->ResumeThread();
	if(m_pUIThread != NULL)
	{
		m_pUIFrameWnd = m_pUIThread->GetUIFrameWndPtr();
		if(m_pUIFrameWnd != NULL)
		{
			m_pUIFrameWnd->TransportStock(m_csKeyTableCode, m_csKeyTableName);
			InitKeyTable();
		}
	}
	SwitchView(data,1);
	Change(pCode);
	SetTimer(1,10000,NULL);
    Initext();
    InitKeyTable();
	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers


BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
		if(pMsg->message == WM_KEYUP)
	{
		if( !HIBYTE(::GetKeyState(VK_CONTROL)) )
		{
			char nChar = 0;
			if( pMsg->wParam==VK_MULTIPLY )
				nChar = '*';
			else if( pMsg->wParam>=0x30 && pMsg->wParam<=0x39 )
				nChar = pMsg->wParam;
			else if( pMsg->wParam>=0x41 && pMsg->wParam<=0x5A )
				nChar = pMsg->wParam;
			else if( pMsg->wParam==191 )
				nChar = '?';
			else if( pMsg->wParam>=VK_NUMPAD0 && pMsg->wParam<=VK_NUMPAD9 )
				nChar = pMsg->wParam-VK_NUMPAD0+0x30;
			if( nChar != 0 )
			{
				CRect rect;
				GetWindowRect(&rect);
				m_pKeyWizzard->InputFirstChar(nChar);
				m_pKeyWizzard->SetPosLT(rect.right-200, rect.bottom-200);
				m_pKeyWizzard->DoModal();
				return TRUE;
			}
		}
	}
	return CFrameWnd::PreTranslateMessage(pMsg);
}
void CMainFrame::Initext()
{
	CString strCode, strName;	
	CStdioFile finSHIdx;
	finSHIdx.Open("SHIndex.txt",  CFile::modeRead);
	while(1)
	{
		CString str,strCode, strName;
		finSHIdx.ReadString(str);
		if(str == "")
			break;
		strCode = str.Left(str.Find(" ",0));
		strName = str.Right(str.GetLength() - str.Find(" ",0)-1);
		m_csKeyTableCode.push_back(strCode);
		m_csKeyTableName.push_back(strName);
	}
	finSHIdx.Close();
}
void CMainFrame::InitKeyTable()
{
	int nSize = m_csKeyTableCode.size();
	m_pKeyWizzard = new CKeyWizzard;//键盘精灵
	m_KeyCodeTable.Status = 1;
	m_KeyCodeTable.hWnd = GetSafeHwnd();
	m_KeyCodeTable.MsgId = WM_Respose;
	m_KeyCodeTable.Count = nSize;
	m_KeyCodeTable.pDate = new TaKeyTable[nSize];
	ASSERT(m_csKeyTableCode.size() == m_csKeyTableName.size());
	for(int i = 0;i < nSize; i++)
	{
		strcpy(m_KeyCodeTable.pDate[i].Code, m_csKeyTableCode[i]);
		strcpy(m_KeyCodeTable.pDate[i].Name, m_csKeyTableName[i]);
		m_KeyCodeTable.pDate[i].wParam = i;
		m_KeyCodeTable.pDate[i].lParam = 1;
	}
	m_pKeyWizzard->AddKeyTableReg(&m_KeyCodeTable);
}
int CMainFrame::OnRespose(DWORD wParam,DWORD lParam)
{
	pCode = m_KeyCodeTable.pDate[(int)wParam].Code;
	pName = m_KeyCodeTable.pDate[(int)wParam].Name;
	data.m_strCode=pCode;
	data.m_strName=pName;
	Change(pCode);
	return 1;
}
void CMainFrame::OnRefresh(DWORD wParam,DWORD lParam)
{
	if(!bControl)
	SwitchView(data,1); 
	else
	SwitchView(data,2);
}
void CMainFrame::Refresh(CData& indata)
{
	data=indata;
	CMainFrame *pMain = (CMainFrame *)AfxGetApp()->m_pMainWnd;
	pMain->SendMessage(WM_Refresh,0,0);
}

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
/*	if(RegOpenKeyEx(HKEY_CURRENT_USER,mStock,0,KEY_ALL_ACCESS,&hkey)!=ERROR_SUCCESS)
		RegCreateKey(HKEY_CURRENT_USER,mStock,&hkey);
	if(RegQueryValueEx(hkey,TEXT("Name"),NULL,&dType1,(LPBYTE)&pName,&dSize1)!=ERROR_SUCCESS)
	{
		RegSetValueEx(hkey,"Name",0,REG_SZ,(LPBYTE)&pName,dSize1);
	}
    if(RegQueryValueEx(hkey,TEXT("Code"),NULL,&dType1,(LPBYTE)&pCode,&dSize1)!=ERROR_SUCCESS)
	{
		RegSetValueEx(hkey,"Code",0,REG_SZ,(LPBYTE)&pCode,dSize1);
	}*/
	TCHAR szPath[] = TEXT("C:\\config.ini");
	WritePrivateProfileString("Information","Code", pCode,szPath);
    WritePrivateProfileString("Information","Name", pName,szPath);
	DWORD dwExitCode;
	if(m_pUIThread != NULL)		
	{
		BOOL bGetExitCode = GetExitCodeThread(m_pUIThread->m_hThread, &dwExitCode);	
		if(bGetExitCode)
			TerminateThread(m_pUIThread->m_hThread, dwExitCode);
		else
			DWORD dwError = GetLastError();
	}
	CFrameWnd::OnClose();
}

void CMainFrame::OnKLine() 
{
	// TODO: Add your command handler code here	
	bControl=true;
    Change(pCode);

}

void CMainFrame::OnRealTime() 
{
	// TODO: Add your command handler code here	
	bControl=false;
	Change(pCode);

}

void CMainFrame::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	m_pUIFrameWnd->TransportStock(m_csKeyTableCode, m_csKeyTableName);
	InitKeyTable();
//	if(bControl)
 //   SwitchView(data,2);
    bTime=true;

	CFrameWnd::OnTimer(nIDEvent);
}
void CMainFrame::Change(CString strCode)
{
	CData data1;
    m_pUIFrameWnd->SearchData(strCode,data1);
	if(!bControl)
	{
	SwitchView(data1,1);
	}
	else
    if(bControl)
	{
	SwitchView(data1,2);

	}
}
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	  CCreateContext   cc;   
      cc.m_pCurrentDoc   =   pContext->m_pCurrentDoc;   
      cc.m_pNewViewClass=RUNTIME_CLASS(CRealtime);   
      m_pRealtime=(CRealtime*)CreateView(&cc,ID_VIEW1);   
      cc.m_pNewViewClass=RUNTIME_CLASS(CStockView);   
      m_pStockView=(CStockView*)CreateView(&cc,ID_VIEW2);    
      return   TRUE;   
}
void CMainFrame::SwitchView(CData& data,int nID)
{         
          m_pRealtime->SetDlgCtrlID(ID_VIEW1); 
          m_pRealtime->ShowWindow(SW_HIDE);   
          m_pStockView->SetDlgCtrlID(ID_VIEW2);   
          m_pStockView->ShowWindow(SW_HIDE);   
          if   (nID==ID_VIEW1)   
          {   
              m_pRealtime->SetDlgCtrlID(AFX_IDW_PANE_FIRST);   
              m_pRealtime->ShowWindow(SW_SHOWMAXIMIZED); 
			  m_pRealtime->GetData(data);
			  m_pRealtime->Invalidate();
          } 
		  else
        {   
			  m_pRealtime->GetData(data);
              m_pStockView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);   
              m_pStockView->ShowWindow(SW_SHOWMAXIMIZED);
			  m_pStockView->GetData(data);
			  m_pStockView->Invalidate();
        }   
        RecalcLayout();  
}

//未用
void CMainFrame::SwitchViewNo(CData& data,int nID)
{         
          m_pRealtime->SetDlgCtrlID(ID_VIEW1); 
          m_pRealtime->ShowWindow(SW_HIDE);   
          m_pStockView->SetDlgCtrlID(ID_VIEW2);   
          m_pStockView->ShowWindow(SW_HIDE);   
          if   (nID!=ID_VIEW1)   
          {   
               m_pRealtime->SetDlgCtrlID(AFX_IDW_PANE_FIRST);   
              m_pRealtime->ShowWindow(SW_SHOWMAXIMIZED); 
			  m_pRealtime->GetData(data);
          } 
		  else
        {   
              
			  m_pStockView->GetData(data);
        }   
        RecalcLayout();  
}

⌨️ 快捷键说明

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