www.pudn.com > 黑客帝国屏保.zip > MatrixString.cpp
// MatrixString.cpp: implementation of the CMatrixString class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MatrixString.h"
#include "constants.h"
#include "Matrix.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
LPCTSTR CMatrixString::m_pData = "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ"
"αβγδεζηθικλμνξοπρστυφχψω"
"1234567890abcdefghijklmnopqrstuvwxzy"
"ABCDEFGHIJKLMNOPQRSTUVWXZY";
int CMatrixString::m_nDataLen = strlen(m_pData); //必为偶数
CMatrixString::CMatrixString()
{
int k;
int nLen = rand() % STR_MAX_LEN;
int nPos;
for (k = 0; k < nLen; k += 2) {
nPos = rand() % (m_nDataLen - 2);
if (nPos % 2)
nPos++;
m_strMatrix += CString(m_pData[nPos]) + CString(m_pData[nPos + 1]);
}
nLen = rand() % STR_BLANK_TAIL;
if (nLen < STR_MIN_TAIL)
nLen = STR_MIN_TAIL;
if (nLen % 2) //奇数
nLen++;
for (k = 0; k < nLen; k++)
m_strMatrix += CString(" ");
m_nLen = 0;
}
CMatrixString::~CMatrixString()
{
}
CString CMatrixString::GetString()
{
return m_strMatrix;
}
int CMatrixString::GetLength(CDC *pDC)
{
if (m_nLen == 0) {
pDC->SelectObject(theMatrix.GetFont());
CSize sz = pDC->GetTextExtent(m_strMatrix);
m_nLen = sz.cx;
}
return m_nLen;
}