www.pudn.com > scrnsaverTY23.zip > Matrix.cpp
// Matrix.cpp: implementation of the CMatrix class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include#include "Matrix.h" #include #include #include #include #include "constants.h" #include "MatrixColumn.h" #include "MatrixString.h" #include "SaverConfigDialog.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CMatrix theMatrix; CMatrix::CMatrix() { } CMatrix::~CMatrix() { } void CMatrix::LoadMatrix(HWND hWnd) { m_nCols = CSaverConfigDialog::GetCols(); m_color = CSaverConfigDialog::GetColor(); RECT rect; ::GetClientRect(hWnd, &rect); m_left = rect.left; m_top = rect.top; m_right = rect.right; m_bottom = rect.bottom; LOGFONT lf; lf = GetLogfont(); m_font.CreateFontIndirect(&lf); srand((unsigned)time(NULL)); CMatrixColumn *pCol; int n; int y; int height = m_bottom - m_top; for (n = 0; n < m_nCols; n++) { y = rand() % height; pCol = new CMatrixColumn(y); m_aArray.Add(pCol); } m_brBlack.CreateSolidBrush(RGB(0, 0, 0)); } CRect CMatrix::GetBorder() { return CRect(m_left, m_top, m_right, m_bottom); } LOGFONT CMatrix::GetLogfont() { LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); strcpy(lf.lfFaceName, "ºÚÌå");// lf.lfWidth = -((m_right - m_left + 1) / m_nCols + 2); // lf.lfHeight = lf.lfWidth * 174 / 80; lf.lfEscapement = 900; lf.lfCharSet = DEFAULT_CHARSET; return lf; } CFont* CMatrix::GetFont() { return &m_font; } void CMatrix::DestroyMatrix() { int n; CMatrixColumn *pCol; for (n = 0; n < m_aArray.GetSize(); n++) { pCol = (CMatrixColumn*)m_aArray[n]; delete pCol; } m_aArray.RemoveAll(); m_brBlack.DeleteObject(); m_font.DeleteObject(); } void CMatrix::MatrixGO(CDC *pDC) { EraseBackGround(pDC); int n; CMatrixColumn *pCol; for (n = 0; n < m_aArray.GetSize(); n++) { pCol = (CMatrixColumn*)m_aArray[n]; pCol->Fall(pDC); } DrawMatrix(pDC); } void CMatrix::EraseBackGround(CDC *pDC) { CRect rect = GetBorder(); // pDC->FillRect(&rect, &m_brBlack); } void CMatrix::DrawMatrix(CDC *pDC) { //draw a frame int n, m; CMatrixColumn *pCol; CMatrixString *pStr; CString str; pDC->SetBkColor(RGB(0, 0, 0)); int wid; pDC->SelectObject(&m_font); CSize sz = pDC->GetTextExtent("M", 1); wid = sz.cy; int k; CRect rect = GetBorder(); k = (m_right - m_left) / sz.cy; for (n = 0; n < k; n++) { pCol = (CMatrixColumn*)m_aArray[n]; int y = pCol->GetPos(); for (m = 0; m < pCol->GetArray()->GetSize(); m++) { int i = 1; pStr = (CMatrixString*)pCol->GetArray()->GetAt(m); CString s1, s2; str = pStr->GetString(); s1 = str[0] + str[1]; s2 = ""; pDC->SetBkColor(RGB(0, 0, 0)); s2 = str.Right(str.GetLength() - 2); pDC->SetTextColor(RGB(255, 255, 255)); pDC->TextOut(wid * n, y, s1); pDC->SetTextColor(m_color); CSize sz = pDC->GetTextExtent(s1); pDC->TextOut(wid * n, y - sz.cx, s2); y -= pStr->GetLength(pDC); if (y < m_top) { break; } i++; } } }