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

📄 mystockview.cpp

📁 一种简单的股票软件源代码,编译后可以实时显示证券行情
💻 CPP
📖 第 1 页 / 共 2 页
字号:
										    pGridFrame->m_grid.SetItemText(p,1,string);
											string.Format("%8s",Buf.m_szName);//名称
											pGridFrame->m_grid.SetItemText(p,2,string);
										
											string.Format("%8.2f",Buf.m_fNewPrice);//最新
											pGridFrame->m_grid.SetItemText(p,3,string);
											string.Format("%8.2f",Buf.m_fNewPrice-Buf.m_fLastClose);//涨跌
											pGridFrame->m_grid.SetItemText(p,4,string);
											if(Buf.m_fNewPrice-Buf.m_fLastClose>0)
											{
												   pGridFrame->m_grid.SetItemFgColor(p,4,RGB(255,0,0));
												   pGridFrame->m_grid.SetItemFgColor(p,3,RGB(255,0,0));
												   pGridFrame->m_grid.SetItemFgColor(p,5,RGB(255,0,0));
												   pGridFrame->m_grid.SetItemFgColor(p,7,RGB(255,0,0));
											}
											if(Buf.m_fNewPrice-Buf.m_fLastClose<0)
											{
												pGridFrame->m_grid.SetItemFgColor(p,4,RGB(10,160,36));
												pGridFrame->m_grid.SetItemFgColor(p,3,RGB(10,160,36));
												pGridFrame->m_grid.SetItemFgColor(p,5,RGB(10,160,36));
												pGridFrame->m_grid.SetItemFgColor(p,7,RGB(10,160,36));
											}
											if(Buf.m_fNewPrice-Buf.m_fLastClose==0.00)
											{
												string.Format("%8.2f",0.00);
											}
											else
											{
												string.Format("%8.2f",(Buf.m_fNewPrice-Buf.m_fLastClose)/Buf.m_fLastClose*100);
											}
											string+="%";
											pGridFrame->m_grid.SetItemText(p,5,string);//涨跌幅
											string.Format("%10.0f",Buf.m_fVolume);//总手
											pGridFrame->m_grid.SetItemText(p,6,string);
											string.Format("%8.2f",Buf.m_fHigh);//最高
											if(Buf.m_fHigh>Buf.m_fLastClose)
												pGridFrame->m_grid.SetItemFgColor(p,7,RGB(255,0,0));
											if(Buf.m_fHigh<Buf.m_fLastClose)
												pGridFrame->m_grid.SetItemFgColor(p,7,RGB(10,160,36));
											pGridFrame->m_grid.SetItemText(p,7,string);
											string.Format("%8.2f",Buf.m_fLow);//最低
											if(Buf.m_fLow>Buf.m_fLastClose)
												pGridFrame->m_grid.SetItemFgColor(p,8,RGB(255,0,0));
											if(Buf.m_fLow<Buf.m_fLastClose)
												pGridFrame->m_grid.SetItemFgColor(p,8,RGB(10,160,36));
											pGridFrame->m_grid.SetItemText(p,8,string);

											string.Format("%8.2f",Buf.m_fOpen);//今开
											if(Buf.m_fOpen>Buf.m_fLastClose)
												pGridFrame->m_grid.SetItemFgColor(p,9,RGB(255,0,0));
											if(Buf.m_fOpen<Buf.m_fLastClose)
												pGridFrame->m_grid.SetItemFgColor(p,9,RGB(10,160,36));
											pGridFrame->m_grid.SetItemText(p,9,string);
											string.Format("%8.2f",Buf.m_fLastClose);//昨收
											pGridFrame->m_grid.SetItemText(p,10,string);
											string.Format("%10.0f",Buf.m_fAmount);//总额
											pGridFrame->m_grid.SetItemText(p,11,string);
											pGridFrame->m_grid.RedrawRow(p);
											//pDoc->m_FileName="600839";//测试用
											if(!(strcmp(string,pDoc->m_FileName)))
												m_bUpdataAllView=true;

											
									
											break;
											
									  }
								}
							}
					}
				}
				if(m_bUpdataAllView)
				{
					pDoc->UpdateAllViews(this);
					m_bUpdataAllView=FALSE;
				}


			}
			

		}
		}
				
		break;
	
	case RCV_FILEDATA:
	    if( !pHeader->m_pData || pHeader->m_wDataType == FILE_TYPE_RES)
		{
			TRACE("MSG: CStkDemo::OnStkDataOK, Replaced data \n");
			break;
		}
		switch(pHeader->m_wDataType)
		{
		case FILE_HISTORY_EX:						// 补日线数据
			
			break;

		case FILE_MINUTE_EX:						// 补分钟线数据
			
			break;

		case FILE_BASE_EX:						// 钱龙兼容基本资料文件,m_szFileName仅包含文件名
		
			break;

		case FILE_NEWS_EX:						// 新闻类,其类型由m_szFileName中子目录名来定
			
			break;

		case FILE_SOFTWARE_EX:
			
			break;

		case FILE_SHAZQDATA_EX:		//h上海国债净价交易
			
			break;
		default:
			TRACE("Msg: CStkDemo::OnStkDataOK,Unkonw data type\n");
		}
		break;
	}
	//RedrawWindow();
	return 0L;
}


void CMyStockView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);

	pGridFrame->SetWindowPos(NULL,0,0,cx,cy,SWP_SHOWWINDOW);//调整表格
	
	//失能窗口的关闭按钮:
	CWnd* pParen=this->GetParent();	
	CMenu* pmenu=pParen->GetSystemMenu(FALSE);
	if(! m_bFirstWindow)
	{
		if(pmenu)
		{
			pmenu->DeleteMenu(SC_CLOSE,MF_BYCOMMAND);
		}
		m_bFirstWindow=true;
	}
}

void CMyStockView::OnStock() 
{

 if(!m_bStocker)
   {
	   gSTOCKDLL.GetStockDrvInfo(RI_SUPPORTEXTHQ,NULL);	//设置 Szn Label6 Receive

	   int ok = gSTOCKDLL.Stock_Init(m_hWnd,My_Msg_StkData,RCV_WORK_SENDMSG);	// 数据共享引用

	   if( ok > 0 )
	   {
	   //
	    	DWORD m_TV_Code = 201;
	    	gSTOCKDLL.GetStockDrvInfo(RI_ENABLETS3FILE,&m_TV_Code);

		    m_bStocker=true;
	
	   }	
   }

	
}

void CMyStockView::OnUpdateStock(CCmdUI* pCmdUI) 
{
	if(m_bStocker)
	{
		pCmdUI->Enable(FALSE);
	}
	else
	{
		pCmdUI->Enable(true);
	}

	
}
int CMyStockView::SetGridData()
{
	CMyStockDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	

	POSITION pos=pDoc->m_DataMap.GetStartPosition();
	int lines=pDoc->m_DataMap.GetCount();
	if(lines>100)
	pGridFrame->m_grid.SetRowCount(lines+1);


	CString string,string1;
	pMapData m_pMapdata=new MapData;
	int row=1;

	while(pos !=NULL)
	{
		pDoc->m_DataMap.GetNextAssoc(pos,string1,(CObject *&)m_pMapdata);
		
				string.Format("%6s",m_pMapdata->m_Report.m_szLabel);//代码
				 pGridFrame->m_grid.SetItemText(row,1,string);
		         string.Format("%8s",m_pMapdata->m_Report.m_szName);//名称
		         string1=string;
		         pGridFrame->m_grid.SetItemText(row,2,string);
				 					
		         string.Format("%8.2f",m_pMapdata->m_Report.m_fNewPrice);//最新
		         pGridFrame->m_grid.SetItemText(row,3,string);
		         string.Format("%8.2f",m_pMapdata->m_Report.m_fNewPrice-m_pMapdata->m_Report.m_fLastClose);//涨跌
		         pGridFrame->m_grid.SetItemText(row,4,string);
		         if(m_pMapdata->m_Report.m_fNewPrice-m_pMapdata->m_Report.m_fLastClose>0)
				 {

			       pGridFrame->m_grid.SetItemFgColor(row,4,RGB(255,0,0));
			       pGridFrame->m_grid.SetItemFgColor(row,3,RGB(255,0,0));
			       pGridFrame->m_grid.SetItemFgColor(row,5,RGB(255,0,0));
			       pGridFrame->m_grid.SetItemFgColor(row,7,RGB(255,0,0));
				 }
		         if(m_pMapdata->m_Report.m_fNewPrice-m_pMapdata->m_Report.m_fLastClose<0)
				 {

			     pGridFrame->m_grid.SetItemFgColor(row,4,RGB(10,160,36));
			     pGridFrame->m_grid.SetItemFgColor(row,3,RGB(10,160,36));
			     pGridFrame->m_grid.SetItemFgColor(row,5,RGB(10,160,36));
				 pGridFrame->m_grid.SetItemFgColor(row,7,RGB(10,160,36));
		
				 }


                if(m_pMapdata->m_Report.m_fNewPrice-m_pMapdata->m_Report.m_fLastClose==0.00)
				{
			       string.Format("%8.2f",0.00);
				}
		       else
			   {
			       string.Format("%8.2f",(m_pMapdata->m_Report.m_fNewPrice-m_pMapdata->m_Report.m_fLastClose)/m_pMapdata->m_Report.m_fLastClose*100);
			   }
		       string+="%";
		       pGridFrame->m_grid.SetItemText(row,5,string);//涨跌幅
		       string.Format("%10.0f",m_pMapdata->m_Report.m_fVolume);//总手
		       pGridFrame->m_grid.SetItemText(row,6,string);
		       string.Format("%8.2f",m_pMapdata->m_Report.m_fHigh);//最高
		       if(m_pMapdata->m_Report.m_fHigh>m_pMapdata->m_Report.m_fLastClose)
			     pGridFrame->m_grid.SetItemFgColor(row,7,RGB(255,0,0));
		       if(m_pMapdata->m_Report.m_fHigh<m_pMapdata->m_Report.m_fLastClose)
			     pGridFrame->m_grid.SetItemFgColor(row,7,RGB(10,160,36));
	           pGridFrame->m_grid.SetItemText(row,7,string);

		      string.Format("%8.2f",m_pMapdata->m_Report.m_fLow);//最低
	          if(m_pMapdata->m_Report.m_fLow>m_pMapdata->m_Report.m_fLastClose)
			     pGridFrame->m_grid.SetItemFgColor(row,8,RGB(255,0,0));
		      if(m_pMapdata->m_Report.m_fLow<m_pMapdata->m_Report.m_fLastClose)
			     pGridFrame->m_grid.SetItemFgColor(row,8,RGB(10,160,36));
		         pGridFrame->m_grid.SetItemText(row,8,string);

		     string.Format("%8.2f",m_pMapdata->m_Report.m_fOpen);//今开
		     if(m_pMapdata->m_Report.m_fOpen>m_pMapdata->m_Report.m_fLastClose)
			   pGridFrame->m_grid.SetItemFgColor(row,9,RGB(255,0,0));
		     if(m_pMapdata->m_Report.m_fOpen<m_pMapdata->m_Report.m_fLastClose)
			   pGridFrame->m_grid.SetItemFgColor(row,9,RGB(10,160,36));
		     pGridFrame->m_grid.SetItemText(row,9,string);
		     string.Format("%8.2f",m_pMapdata->m_Report.m_fLastClose);//昨收
             pGridFrame->m_grid.SetItemText(row,10,string);
		     string.Format("%10.0f",m_pMapdata->m_Report.m_fAmount);//总额
		     pGridFrame->m_grid.SetItemText(row,11,string);
			 
			 row++;
		
	}

		pGridFrame->m_grid.Refresh();


	return 0;

}

void CMyStockView::OnUnstock() 
{
	gSTOCKDLL.Stock_Quit(m_hWnd);
	m_bStocker=FALSE;    
	
}

void CMyStockView::OnUpdateUnstock(CCmdUI* pCmdUI) 
{

	if(!m_bStocker)
	{
		pCmdUI->Enable(FALSE);
	}
	else
	{
		pCmdUI->Enable(true);
	}
}

int CMyStockView::ONNewFile(CString string)
{
	CMyStockDoc* pDoc=GetDocument();
	pDoc->m_FileName=string;
	CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd();

	pFrame->OnNewview();

	return 0;


}

⌨️ 快捷键说明

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