www.pudn.com > no4scr.rar > ScrSaverWnd.cpp


// ScrSaverWnd.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "NO_4.h" 
#include "ScrSaverWnd.h" 
 
#include "global.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CScrSaverWnd 
 
//	======================================================================================== 
//	a-z,A-R,T,0-8 
 
char CScrSaverWnd::MatrixCode[200]="EDFG1237H3NNS23AHJTIK7AJKTH623427DJjhg56fjsadhg8763453455fjshfgsGHFHGFGHF2342134KJGHJGhj60sd54353h4fgdfjs768djsd5213426fhsdjsadfasDjthGHFGhh67ghajhfg87A234GHys12ay321asRG23423JGh1gdsahgQDF34523GAGD42"; 
 
int CScrSaverWnd::length[80]={	7, 9,30, 6, 7, 9, 5,20,10, 4, 7,17, 7,18,15, 5, 
								8, 8, 6, 5, 4,13,29, 7, 5, 8,25, 7, 4, 6, 9, 6, 
								7, 9,30, 6, 7, 9, 5,20,10, 4, 7,17, 7,18,15, 5, 
								8, 8, 6, 5, 4,13,29, 7, 5, 8,25, 7, 4, 6, 9, 6, 
								8, 8, 6, 5, 4,13,29, 7, 5, 8,25, 7, 4, 6, 9, 6}; 
 
int CScrSaverWnd::position[80]={	2, 5,12,43,27, 5,20, 7,13,10, 9,19,50, 4,37, 1, 
									4, 5,32,23,17, 5,34,20,13,10,49, 3,20,24, 7,20, 
									1, 5,12, 2, 7, 5, 2, 7, 3,40, 9,19, 2,54,57, 1, 
									3, 5, 2,23,17, 5,34,17, 1,10,59, 6,20,14, 7,10, 
									1, 5, 2, 3,20, 5, 2, 7, 3,10, 9, 9, 3, 4, 7, 1}; 
 
int CScrSaverWnd::cycle[80]={	72,85,92,63,87,75,80,67,53,70,59,59,60,44,47,41, 
								84,65,62,73,77,85,54,60,43,40,49,53,80,94,57,60, 
								41,35,72,52,67,75,82,67,53,60,49,89,82,84,97,31, 
								53,35,32,53,57,65,54,37,51,70,99,86,70,44,37,60, 
								71,35,32,43,80,75,62,67,33,30,39,39,43,44,37,31}; 
 
int CScrSaverWnd::pointer[80]={ 2, 5,12, 3,27, 5,20, 7,13,10, 9,19,10, 4,37, 1, 
								4, 5,22,23,17, 5,34,20,13,10,29, 3,20, 4, 7,20, 
								1, 5,12, 2, 7, 5, 2, 7, 3, 2, 9,19, 2,24,17, 1, 
								3, 5, 2,23,17, 5,34,17, 1,10,19, 6,20,14, 7,10, 
								1, 5, 2, 3,20, 5, 2, 7, 3,10, 9, 9, 3, 4, 7, 1}; 
 
//	==================================================================================== 
 
CScrSaverWnd::CScrSaverWnd() 
{ 
	lpszClassName=NULL; 
	ID_TIMER=1; 
	m_Point.x=-1; 
	m_Point.y=-1; 
	TextSrcY=1; 
	CountI=0; 
	CountJ=0; 
	CountK=0; 
	CountL=0; 
	CountA=0; 
	CountB=0; 
	CountC=0; 
	CountD=0; 
} 
 
CScrSaverWnd::~CScrSaverWnd() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CScrSaverWnd, CWnd) 
	//{{AFX_MSG_MAP(CScrSaverWnd) 
	ON_WM_PAINT() 
	ON_WM_KEYDOWN() 
	ON_WM_LBUTTONDOWN() 
	ON_WM_MBUTTONDOWN() 
	ON_WM_RBUTTONDOWN() 
	ON_WM_MOUSEMOVE() 
	ON_WM_SYSKEYDOWN() 
	ON_WM_DESTROY() 
	ON_WM_TIMER() 
	ON_WM_ACTIVATE() 
	ON_WM_ACTIVATEAPP() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CScrSaverWnd message handlers 
 
BOOL CScrSaverWnd::Create()  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	if (lpszClassName==NULL) 
	{ 
		lpszClassName=AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW, 
		::LoadCursor(AfxGetResourceHandle(),MAKEINTRESOURCE(IDC_NOCURSOR))); 
		 
		//注册类,IDC_NOCURSOR为新建光标的ID(需要用户自己绘制) 
		//这个光标没有任何图案 
	} 
 
	CRect rectS(	0,0,::GetSystemMetrics(SM_CXSCREEN), 
					::GetSystemMetrics(SM_CYSCREEN)); //得到显示屏的长度和宽度 
 
	CreateEx(	WS_EX_TOPMOST,lpszClassName,_T(""),WS_VISIBLE | WS_POPUP, 
				rectS.left,rectS.top,rectS.right-rectS.left,rectS.bottom-rectS.top, 
				GetSafeHwnd(),NULL,NULL);	//创建一个全屏窗口 
											//切记:默认字符集DEFAULT 
	Font1.CreateFont (	22,5,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET, 
						OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, 
						DEFAULT_PITCH|FF_MODERN,"mCode15"); 
 
	Font2.CreateFont (	40,40,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET, 
						OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, 
						DEFAULT_PITCH|FF_MODERN,"Matrix_vs_Miltown"); 
	 
	SetTimer(ID_TIMER,200,NULL); //设置定时器,0.2秒换一幅图 
	return TRUE; 
} 
 
// USER ====================================================  
 
void CScrSaverWnd::DrawBitmap(CDC& dc,int nIndex) 
{ 
 
	CDC dcMem; 
	dcMem.CreateCompatibleDC(&dc); 
	CBitmap m_Bitmap;  
	if (TextSrcY == 1) 
	{ 
		m_Bitmap.LoadBitmap(IDB_BITMAP1); 
		TextSrcY = 2; 
	} 
	else 
	{ 
		m_Bitmap.LoadBitmap(IDB_BITMAP2); 
		TextSrcY = 1; 
	} 
 
	dcMem.SelectObject(m_Bitmap); 
 
	//如果你的图片大小是1024×768,请把下面的800,600分别 
	//替换为1024*768 
	dc.BitBlt(0,0,1024,768,&dcMem,0,0,SRCCOPY); 
} 
// USER ===================================================== 
 
void CScrSaverWnd::OutputText(CDC &dc) 
{ 
/*	 
	CFont Font1; 
	CDC dc1; 
 
	Font1.CreateFont (	-50,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,GB2312_CHARSET, 
						OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, 
						DEFAULT_PITCH|FF_MODERN,"system"); 
 
	dc1.CreateCompatibleDC(&dc); 
	dc1.SelectStockObject (WHITE_PEN); 
	dc1.SetTextColor (RGB(0,255,0)); 
	dc1.SetBkColor (RGB(255,255,255)); 
	dc1.TextOut (8,8,"Matrix"); 
	dc1.MoveTo (20,20); 
	dc1.LineTo (50,50); 
	dc.BitBlt(0,0,1024,768,&dc1,0,0,SRCCOPY); 
*/ 
} 
 
 
//	USER ===================================================== 
//	矩阵  核心代码------- 
//    
//						 
//	Matrix 04                      
//                       
void CScrSaverWnd::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	// TODO: Add your message handler code here 
	CBrush brush(RGB(0,0,0)); 
	CRect rect; 
	CRect r_msgbox; 
	GetClientRect(rect); 
	if (CountJ == 0) 
		dc.FillRect(&rect,&brush);		//用黑色清屏,去掉这行为覆盖模式 
	dc.SetBkColor (RGB(0,0,0)); 
	dc.SelectObject (&Font1); 
	 
//	dc.SetTextColor (RGB(0,255,0)); 
//	for	(CountI=0;CountI<15;CountI++) 
//	{ 
//		dc.TextOut (0,CountI*25,"G"); 
//	} 
	for(CountK=0;CountK<64;CountK++) 
	{ 
		dc.SetTextColor (RGB(200,255,200)); 
		dc.TextOut (CountK*16,position[CountK]*24,_T(MatrixCode[CountJ+pointer[CountK]])); 
		 
		for(CountI=1;CountIcycle[CountI])position[CountI]=0; 
		position[CountI]++; 
*/	 
		position[CountK]++; 
 
		if (position[CountK]>cycle[CountK]) 
			position[CountK]=1; 
	} 
	CountJ++; 
	 
	if (CountJ>24&&CountJ<35) 
	{ 
		CountA++; 
		r_msgbox.bottom=150+CountA*5; 
		r_msgbox.top=150-CountA*5; 
		r_msgbox.left=512-CountA*30; 
		r_msgbox.right=512+CountA*30; 
		dc.FillRect (&r_msgbox,&brush); 
	} 
 
	if (CountJ>34&&CountJ<50) 
	{ 
		r_msgbox.bottom=200; 
		r_msgbox.top=100; 
		r_msgbox.left=212; 
		r_msgbox.right=812; 
		dc.FillRect (&r_msgbox,&brush); 
		dc.SelectObject (&Font2); 
		dc.SetTextColor (RGB(0,255,0)); 
		switch (CountB) 
		{ 
		case 0: 
			dc.TextOut (300,105,_T("THE")); 
			dc.TextOut (520,105,_T("MATRIX")); 
			dc.TextOut (365,150,_T("RELOADED")); 
			break; 
		case 1: 
			dc.TextOut (390,105,_T("HACK")); 
			dc.TextOut (340,150,_T("YOUR")); 
			dc.TextOut (570,150,_T("PC")); 
			break; 
		} 
	} 
 
	 
	if (CountJ>90) 
	{ 
		CountJ=0; 
		CountB++; 
	} 
	if (CountA>9) 
		CountA=0; 
	if (CountB>1) 
		CountB=0; 
	// Do not call CWnd::OnPaint() for painting messages 
} 
 
// KEY ================================================================= 
void CScrSaverWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)  
{ 
	// TODO: Add your message handler code here and/or call default 
	PostMessage(WM_CLOSE); 
	CWnd::OnKeyDown(nChar, nRepCnt, nFlags); 
} 
 
void CScrSaverWnd::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	PostMessage(WM_CLOSE); 
	CWnd::OnLButtonDown(nFlags, point); 
} 
 
void CScrSaverWnd::OnMButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	PostMessage(WM_CLOSE); 
	CWnd::OnMButtonDown(nFlags, point); 
} 
 
void CScrSaverWnd::OnRButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	PostMessage(WM_CLOSE); 
	CWnd::OnRButtonDown(nFlags, point); 
} 
 
void CScrSaverWnd::OnMouseMove(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	if (m_Point==CPoint(-1,-1)) 
	m_Point=point; 
	else  
		if (m_Point!=point) 
		PostMessage(WM_CLOSE); 
 
	CWnd::OnMouseMove(nFlags, point); 
} 
 
void CScrSaverWnd::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)  
{ 
	// TODO: Add your message handler code here and/or call default 
	PostMessage(WM_CLOSE); 
	CWnd::OnSysKeyDown(nChar, nRepCnt, nFlags); 
} 
 
void CScrSaverWnd::OnDestroy()  
{ 
	CWnd::OnDestroy(); 
	KillTimer(ID_TIMER); 
 
	// TODO: Add your message handler code here 
	 
} 
 
void CScrSaverWnd::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CClientDC dc(this); 
//	int n=2;	//你有几张图片就把n换成几,因为我 
				//做的屏保中只有两张图片因而n=2 
//	static int m_nIndex=0; 
//	m_nIndex%=n-1; 
 
	InvalidateRect(NULL,0);		//刷新屏幕repaint 
//	DrawBitmap(dc,m_nIndex++); 
//	OutputText(dc); 
	CWnd::OnTimer(nIDEvent); 
} 
 
void CScrSaverWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)  
{ 
	CWnd::OnActivate(nState, pWndOther, bMinimized); 
	 
	// TODO: Add your message handler code here 
	if (nState==WA_INACTIVE) 
	PostMessage(WM_CLOSE); 
} 
 
void CScrSaverWnd::OnActivateApp(BOOL bActive, HTASK hTask)  
{ 
	CWnd::OnActivateApp(bActive, hTask); 
	 
	// TODO: Add your message handler code here 
	if (!bActive) //is being deactivated 
	PostMessage(WM_CLOSE); 
} 
 
void CScrSaverWnd::PostNcDestroy() 
{ 
	delete this; 
} 
 
//==================================================================================== 
//为了防止同时运行两个相同的程序,下面两个函数是必需的 
 
//如果你不理解这段代码,不要管他们,只要把他们拷贝到你 
 
//的工程中就行了