BaseView.cpp
上传用户:zhanglf88
上传日期:2013-11-19
资源大小:6036k
文件大小:6k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "../StaticDoc.h"
  3. #include "BaseView.h"
  4. /////////////////////////////////////////////////////////////////////////////
  5. // CBaseView
  6. IMPLEMENT_DYNCREATE(CBaseView, CEditView)
  7. BEGIN_MESSAGE_MAP(CBaseView, CEditView)
  8. //{{AFX_MSG_MAP(CBaseView)
  9. ON_WM_CREATE()
  10. ON_WM_DESTROY()
  11. ON_WM_CTLCOLOR_REFLECT()
  12. ON_CONTROL_REFLECT(EN_CHANGE, OnEditChange)
  13. //}}AFX_MSG_MAP
  14. ON_MESSAGE(WM_USER_GETVIEWTITLE, OnGetViewTitle)
  15. ON_MESSAGE(WM_USER_GETVIEWCMDID, OnGetViewCmdid)
  16. ON_MESSAGE(WM_USER_COLORCHANGE, OnColorChange)
  17. ON_MESSAGE(WM_APP_STKRECEIVER_DATA, OnStkReceiverData)
  18. END_MESSAGE_MAP()
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CBaseView construction/destruction
  21. CBaseView::CBaseView()
  22. {
  23. }
  24. CBaseView::~CBaseView()
  25. {
  26. }
  27. BOOL CBaseView::PreCreateWindow(CREATESTRUCT& cs)
  28. {
  29. BOOL bPreCreated = CEditView::PreCreateWindow(cs);
  30. cs.style &= ~(ES_AUTOHSCROLL | WS_HSCROLL);
  31. return bPreCreated;
  32. }
  33. void CBaseView::SetFont(LPLOGFONT pLogFont)
  34. {
  35. ASSERT(pLogFont);
  36. m_font.DeleteObject();
  37. m_font.CreateFontIndirect(pLogFont);
  38. SendMessage(WM_SETFONT, (WPARAM)m_font.GetSafeHandle(), MAKELPARAM(1,0));
  39. }
  40. void CBaseView::BeginNewLine()
  41. {
  42. GetEditCtrl().SetSel(-1, -1);
  43. int nLineCount = GetEditCtrl().GetLineCount();
  44. if (nLineCount >= 1)
  45. {
  46. //int nLineIndex = GetEditCtrl().LineIndex(nLineCount-1);
  47. //int nLineLen = GetEditCtrl().LineLength(nLineIndex);
  48. CPoint point = GetEditCtrl().PosFromChar(UINT(-1)/*nLineIndex+nLineLen*/);
  49. GetEditCtrl().SetCaretPos(point);
  50. }
  51. CString string = STRING_CRLF;
  52. GetEditCtrl().ReplaceSel(string);
  53. }
  54. void CBaseView::OutputMsgHeader()
  55. {
  56. CString string = "-->";
  57. GetEditCtrl().ReplaceSel(string);
  58. }
  59. void CBaseView::OutputMsgLine(const char * line)
  60. {
  61. BeginNewLine();
  62. OutputMsgHeader();
  63. m_astrMsg.Add(line);
  64. GetEditCtrl().ReplaceSel(line);
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CBaseView diagnostics
  68. #ifdef _DEBUG
  69. void CBaseView::AssertValid() const
  70. {
  71. CEditView::AssertValid();
  72. }
  73. void CBaseView::Dump(CDumpContext& dc) const
  74. {
  75. CEditView::Dump(dc);
  76. }
  77. #endif //_DEBUG
  78. /////////////////////////////////////////////////////////////////////////////
  79. // CBaseView message handlers
  80. int CBaseView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  81. {
  82. if (CEditView::OnCreate(lpCreateStruct) == -1)
  83. return -1;
  84. // TODO: Add your specialized creation code here
  85. GetEditCtrl().SetReadOnly();
  86. GetEditCtrl().SetMargins(20, 20);
  87. LOGFONT lf;
  88. memset(&lf, 0, sizeof(lf));
  89. AfxGetProfile().GetFontBaseView(&lf);
  90. SetFont(&lf);
  91. // 实时行情刷新
  92. AfxGetStkReceiver().AddRcvDataWnd(GetSafeHwnd());
  93. return 0;
  94. }
  95. void CBaseView::OnDestroy() 
  96. {
  97. // 停止行情刷新通知消息
  98. AfxGetStkReceiver().RemoveRcvDataWnd(GetSafeHwnd());
  99. CEditView::OnDestroy();
  100. }
  101. void CBaseView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
  102. {
  103. // TODO: Add your specialized code here and/or call the base class
  104. CEditView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  105. if (bActivate)
  106. {
  107. OnUpdate(NULL, UPDATE_HINT_BASEVIEW, NULL);
  108. CWnd * pParent = GetParent();
  109. if (pParent && ::IsWindow(pParent->GetSafeHwnd()))
  110. pParent->Invalidate();
  111. }
  112. }
  113. void CBaseView::OnEditChange() 
  114. {
  115. }
  116. HBRUSH CBaseView::CtlColor(CDC* pDC, UINT nCtlColor) 
  117. {
  118. if (pDC)
  119. {
  120. pDC->SetBkColor(AfxGetProfile().GetColor(CColorClass::clrBaseBK));
  121. pDC->SetTextColor(AfxGetProfile().GetColor(CColorClass::clrBaseText));
  122. }
  123. static CBrush brushBK;
  124. static COLORREF clrBKLast = RGB(255,255,255);
  125. COLORREF clrBKNow = AfxGetProfile().GetColor(CColorClass::clrBaseBK);
  126. if (NULL == brushBK.GetSafeHandle() || clrBKLast != clrBKNow)
  127. {
  128. brushBK.DeleteObject();
  129. VERIFY(brushBK.CreateSolidBrush(clrBKNow));
  130. }
  131. clrBKLast = clrBKNow;
  132. return (HBRUSH)brushBK.GetSafeHandle();
  133. }
  134. LRESULT CBaseView::OnGetViewTitle(WPARAM wParam, LPARAM lParam)
  135. {
  136. CString strTitle;
  137. strTitle.LoadString(IDS_TITLE_BASEVIEW);
  138. lstrcpyn((LPTSTR)lParam, (LPCTSTR)strTitle, wParam);
  139. if ((int)wParam > strTitle.GetLength())
  140. wParam = strTitle.GetLength();
  141. return wParam;
  142. }
  143. LRESULT CBaseView::OnGetViewCmdid(WPARAM wParam, LPARAM lParam)
  144. {
  145. if (lParam)
  146. *((LPARAM *)lParam) = ID_VIEW_BASE;
  147. return 0L;
  148. }
  149. LRESULT CBaseView::OnColorChange(WPARAM wParam, LPARAM lParam)
  150. {
  151. Invalidate();
  152. return 0L;
  153. }
  154. LRESULT CBaseView::OnStkReceiverData(WPARAM wParam, LPARAM lParam)
  155. {
  156. PCOMMPACKET pCommPacket = (PCOMMPACKET)lParam;
  157. switch(wParam)
  158. {
  159. case CStock::dataBasetext:
  160. if (pCommPacket && CStock::dataCode == pCommPacket->m_dwDataType)
  161. {
  162. for(DWORD i=0; i<pCommPacket->m_dwCount; i++)
  163. {
  164. if (m_stock.GetStockInfo().IsEqualTo(pCommPacket->m_pStockcode[i].m_dwMarket, pCommPacket->m_pStockcode[i].m_szCode))
  165. OnUpdate(NULL, UPDATE_HINT_BASEVIEW, NULL);
  166. }
  167. }
  168. break;
  169. }
  170. return 0L;
  171. }
  172. void CBaseView::OnInitialUpdate() 
  173. {
  174. CEditView::OnInitialUpdate();
  175. OnUpdate(NULL, UPDATE_HINT_BASEVIEW, NULL);
  176. }
  177. void CBaseView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
  178. {
  179. if (UPDATE_HINT_BASEVIEW != lHint)
  180. return;
  181. if (IsWindowVisible())
  182. SetFocus();
  183. CStockInfo info;
  184. if (!AfxGetProfile().GetCurrentStock(&info))
  185. return;
  186. CString strHeader = info.GetStockCode();
  187. strHeader += "  ";
  188. strHeader += info.GetStockName();
  189. strHeader += "rnrn ";
  190. GetEditCtrl().SetWindowText(strHeader);
  191. GetEditCtrl().SetSel(strHeader.GetLength()-1, strHeader.GetLength()-1);
  192. m_stock.Clear();
  193. m_stock.SetStockInfo(&info);
  194. m_stock.SetDatabase(&AfxGetDB());
  195. m_stock.PrepareBaseInfo(TRUE);
  196. char * pText = m_stock.GetBaseTextPtr();
  197. int nLength = m_stock.GetBaseTextLength();
  198. if (pText && nLength > 0)
  199. {
  200. GetEditCtrl().ReplaceSel(pText);
  201. }
  202. else
  203. {
  204. CString strNoBaseData;
  205. strNoBaseData.LoadString(IDS_BASEVIEW_NOBASEDATA);
  206. GetEditCtrl().ReplaceSel(strNoBaseData);
  207. }
  208. GetEditCtrl().SetSel(0, 0);
  209. AfxGetStkReceiver().RequestStockData(CStock::dataBasetext, &info, 1, 0, 0);
  210. }