Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

253 lines
7.4 KiB

  1. // LCDManView.cpp : implementation of the CLCDManView class
  2. //
  3. #include "stdafx.h"
  4. #include "LCDMan.h"
  5. #include "LCDManDoc.h"
  6. #include "LCDManView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CLCDManView
  14. IMPLEMENT_DYNCREATE(CLCDManView, CView)
  15. BEGIN_MESSAGE_MAP(CLCDManView, CView)
  16. //{{AFX_MSG_MAP(CLCDManView)
  17. ON_COMMAND(ID_VIEW_NEXT, OnViewNext)
  18. ON_COMMAND(ID_VIEW_PREVIOUS, OnViewPrevious)
  19. ON_WM_TIMER()
  20. //}}AFX_MSG_MAP
  21. // Standard printing commands
  22. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CLCDManView construction/destruction
  28. CLCDManView::CLCDManView() : /*m_Rect(0, 0, 700, 70),*/ m_RectImg(100, 50, 100 + LCD_X_DIMENSION, 50 + LCD_Y_DIMENSION),
  29. m_iTimerInterval (0), m_iTextPos(0), m_pos(NULL)
  30. {
  31. m_bmText.bmBits = m_bmVal;
  32. }
  33. CLCDManView::~CLCDManView()
  34. {
  35. }
  36. BOOL CLCDManView::PreCreateWindow(CREATESTRUCT& cs)
  37. {
  38. // TODO: Modify the Window class or styles here by modifying
  39. // the CREATESTRUCT cs
  40. return CView::PreCreateWindow(cs);
  41. }
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CLCDManView drawing
  44. void CLCDManView::OnDraw(CDC* pDC)
  45. {
  46. CLCDManDoc* pDoc = GetDocument();
  47. ASSERT_VALID(pDoc);
  48. if (!pDoc->GetLIst()->IsEmpty())
  49. {
  50. // Convert the text into bitmap
  51. // HDC hDCMem = ::CreateCompatibleDC(pDC->m_hDC);
  52. CDC dcMem;
  53. if (!dcMem.CreateCompatibleDC(pDC))
  54. return;
  55. CFont cfFit;
  56. LOGFONT logfnt;
  57. // determine default font for document
  58. memset(&logfnt, 0, sizeof logfnt);
  59. lstrcpy(logfnt.lfFaceName, _T("Arial"));
  60. logfnt.lfOutPrecision = OUT_TT_PRECIS;
  61. logfnt.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  62. logfnt.lfQuality = PROOF_QUALITY;
  63. logfnt.lfPitchAndFamily = FF_SWISS | VARIABLE_PITCH;
  64. logfnt.lfHeight = (LCD_Y_DIMENSION);
  65. cfFit.CreateFontIndirect(&logfnt);
  66. CFont *pcfDefault = dcMem.SelectObject( &cfFit );
  67. SIZE size;
  68. size.cx = LCD_X_DIMENSION;
  69. size.cy = LCD_Y_DIMENSION;
  70. CBitmap CBitMapText;
  71. // HBITMAP hBitMap = ::CreateCompatibleBitmap(hDCMem, size.cx, size.cy);
  72. if (!CBitMapText.CreateCompatibleBitmap(pDC, size.cx, size.cy))
  73. return;
  74. dcMem.SelectObject(&CBitMapText);
  75. SIZE szState = dcMem.GetTextExtent(pDoc->GetState());
  76. CRect crectState(0, 0, szState.cx, size.cy);
  77. CRect crectMsg(szState.cx, 0, size.cx, size.cy);
  78. // Build the full message string from m_List
  79. CStringList *pList = pDoc->GetLIst();
  80. CString CStrFull = (TEXT(""));
  81. CString cstr(TEXT(""));
  82. POSITION pos ;
  83. if (pList->IsEmpty())
  84. return;
  85. SIZE szMsg;
  86. LONG lFullLength = 0;
  87. for ( pos = pList->GetHeadPosition(); ; )
  88. {
  89. cstr = pList->GetNext(pos);
  90. szMsg = dcMem.GetTextExtent(cstr);
  91. CStrFull += cstr;
  92. lFullLength += szMsg.cx;
  93. if (lFullLength > size.cx + 10 && m_iTimerInterval == 0)
  94. {
  95. // Start rolling
  96. m_iTimerInterval = 200;
  97. KillTimer(1);
  98. SetTimer(1, m_iTimerInterval, NULL);
  99. m_iTextPos = 0;
  100. }
  101. if (lFullLength - m_iTextPos > size.cx + 10)
  102. break;
  103. else if (pos == NULL && lFullLength > size.cx + 10)
  104. pos = pList->GetHeadPosition();
  105. else if (pos == NULL)
  106. break;
  107. }
  108. if (lFullLength <= size.cx + 10 && m_iTimerInterval != 0)
  109. {
  110. // Stop rolling
  111. m_iTimerInterval = 0;
  112. KillTimer(1);
  113. m_iTextPos = 0;
  114. }
  115. dcMem.ExtTextOut(0, 0, ETO_CLIPPED | ETO_OPAQUE, &crectState, pDoc->GetState(), NULL);
  116. dcMem.ExtTextOut(crectState.right - m_iTextPos,0, ETO_CLIPPED | ETO_OPAQUE, &crectMsg, CStrFull, NULL);
  117. // Recreate the bitmap from BITMAP srtuct
  118. CBitMapText.GetBitmap(&m_bmText);
  119. m_bmText.bmBits = m_bmVal;
  120. CBitMapText.GetBitmapBits(sizeof(m_bmVal), m_bmText.bmBits);
  121. dcMem.SelectObject(pcfDefault );
  122. dcMem.DeleteDC();
  123. CBitMapText.DeleteObject();
  124. CBitmap CBOut;
  125. if (!CBOut.CreateBitmapIndirect(&m_bmText))
  126. return;
  127. // Display new bitmap
  128. CDC dcMem1;
  129. if (!dcMem1.CreateCompatibleDC(pDC))
  130. return;
  131. dcMem1.SelectObject(&CBOut);
  132. // Display the bitmap
  133. GetClientRect(m_RectImg);
  134. m_RectImg.top = (m_RectImg.bottom - LCD_Y_DIMENSION) / 2;
  135. m_RectImg.bottom = (m_RectImg.bottom + LCD_Y_DIMENSION) / 2;
  136. m_RectImg.left = (m_RectImg.right - LCD_X_DIMENSION) / 2;
  137. m_RectImg.right = (m_RectImg.right + LCD_X_DIMENSION) / 2;
  138. CRect crFrame(m_RectImg);
  139. crFrame.InflateRect(1,1,1,1);
  140. pDC->Rectangle(&crFrame);
  141. pDC->BitBlt(m_RectImg.left, m_RectImg.top, size.cx, size.cy, &dcMem1, 0, 0, SRCCOPY );
  142. // Clean up
  143. CBOut.DeleteObject();
  144. }
  145. }
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CLCDManView printing
  148. BOOL CLCDManView::OnPreparePrinting(CPrintInfo* pInfo)
  149. {
  150. // default preparation
  151. return DoPreparePrinting(pInfo);
  152. }
  153. void CLCDManView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  154. {
  155. // TODO: add extra initialization before printing
  156. }
  157. void CLCDManView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  158. {
  159. // TODO: add cleanup after printing
  160. }
  161. /////////////////////////////////////////////////////////////////////////////
  162. // CLCDManView diagnostics
  163. #ifdef _DEBUG
  164. void CLCDManView::AssertValid() const
  165. {
  166. CView::AssertValid();
  167. }
  168. void CLCDManView::Dump(CDumpContext& dc) const
  169. {
  170. CView::Dump(dc);
  171. }
  172. CLCDManDoc* CLCDManView::GetDocument() // non-debug version is inline
  173. {
  174. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLCDManDoc)));
  175. return (CLCDManDoc*)m_pDocument;
  176. }
  177. #endif //_DEBUG
  178. /////////////////////////////////////////////////////////////////////////////
  179. // CLCDManView message handlers
  180. void CLCDManView::OnViewNext()
  181. {
  182. CLCDManDoc* pDoc = GetDocument();
  183. ASSERT_VALID(pDoc);
  184. CStringList *pList = pDoc->GetLIst();
  185. if (m_pos)
  186. {
  187. pList->GetNext(m_pos);
  188. }
  189. InvalidateRect(NULL, TRUE);
  190. }
  191. void CLCDManView::OnViewPrevious()
  192. {
  193. CLCDManDoc* pDoc = GetDocument();
  194. ASSERT_VALID(pDoc);
  195. CStringList *pList = pDoc->GetLIst();
  196. if (m_pos)
  197. {
  198. pList->GetPrev(m_pos);
  199. }
  200. InvalidateRect(NULL, TRUE);
  201. }
  202. void CLCDManView::OnTimer(UINT nIDEvent)
  203. {
  204. if (nIDEvent == 1)
  205. {
  206. // Roll the message
  207. m_iTextPos += 5;
  208. InvalidateRect(&m_RectImg, FALSE);
  209. }
  210. else if (nIDEvent == 2)
  211. {
  212. // Recreate document
  213. CLCDManDoc* pDoc = GetDocument();
  214. ASSERT_VALID(pDoc);
  215. pDoc->InitDocument(NULL);
  216. InvalidateRect(&m_RectImg, FALSE);
  217. }
  218. CView::OnTimer(nIDEvent);
  219. }