黑客帝国数字雨源代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#include<windows.h>#defineID_TIMER1#defineSTRMAXLEN25//Ò»¸öÏÔʾÁеÄ×î´ó³¤¶È#defineSTRMINLEN8//Ò»¸öÏÔʾÁеÄ×îС³¤¶ÈLRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////typedefstructtagCharChain//Õû¸öµ±×÷ÆÁÄ»µÄÒ»¸öÏÔʾÁÐ,ÕâÊǸöË«ÏòÁбí{structtagCharChain*prev;//Á´±íµÄÇ°¸öÔªËØTCHARch;//Ò»¸öÏÔʾÁÐÖеÄÒ»¸ö×Ö·ûstructtagCharChain*next;//Á´±íµÄºó¸öÔªËØ}CharChain,*pCharChain;typedefstructtagCharColumn{CharChain*head,*current,*point;intx,y,iStrLen;//ÏÔʾÁеĿªÊ¼ÏÔʾµÄx,y×ø±ê,iStrLenÊÇÕâ¸öÁеij¤¶ÈintiStopTimes,iMustStopTimes;//ÒѾ­Í£Ö͵ĴÎÊýºÍ±ØÐëÍ£Ö͵ĴÎÊý,±ØÐëÍ£Ö͵ĴÎÊýÊÇËæ»úµÄ}CharColumn,*pCharColumn;intmain(HINSTANCEhInstance,HINSTANCEhPrevInstance,PSTRszCmdLine,intiCmdShow){staticTCHARszAppName[]=TEXT("matrix");HWNDhwnd;MSGmsg;WNDCLASSwndclass;wndclass.style=CS_HREDRAW|CS_VREDRAW;wndclass.lpfnWndProc=WndProc;wndclass.cbClsExtra=0;wndclass.cbWndExtra=0;wndclass.hInstance=hInstance;wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);wndclass.lpszMenuName=NULL;wndclass.lpszClassName=szAppName;if(!RegisterClass(&wndclass)){MessageBox(NULL,TEXT("´Ë³ÌÐò±ØÐëÔËÐÐÔÚNTÏÂ!"),szAppName,MB_ICONERROR);return0;}hwnd=CreateWindow(szAppName,NULL,WS_DLGFRAME|WS_THICKFRAME|WS_POPUP,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hInstance,NULL);ShowWindow(hwnd,SW_SHOWMAXIMIZED);//×î´ó»¯ÏÔʾUpdateWindow(hwnd);ShowCursor(FALSE);//Òþ²ØÊó±ê¹â±êsrand((int)GetCurrentTime());//³õʼ»¯Ëæ»úÊý·¢ÉúÆ÷while(GetMessage(&msg,NULL,0,0)){TranslateMessage(&msg);DispatchMessage(&msg);}ShowCursor(TRUE);//ÏÔʾÊó±ê¹â±êreturnmsg.wParam;}TCHARrandomChar()//Ëæ»ú×Ö·û²úÉúº¯Êý{return(TCHAR)(rand()%(126-33)+33);//33µ½126Ö®¼ä}intinit(CharColumn*cc,intcyScreen,intx)//³õʼ»¯{intj;cc->iStrLen=rand()%(STRMAXLEN-STRMINLEN)+STRMINLEN;//ÏÔʾÁеij¤¶Ècc->x=x+3;//ÏÔʾÁеĿªÊ¼ÏÔʾµÄx×ø±êcc->y=rand()%3?rand()%cyScreen:0;//ÏÔʾÁеĿªÊ¼ÏÔʾµÄy×ø±êcc->iMustStopTimes=rand()%6;cc->iStopTimes=0;cc->head=cc->current=(pCharChain)calloc(cc->iStrLen,sizeof(CharChain));//Éú³ÉÏÔʾÁÐfor(j=0;j<cc->iStrLen-1;j++){cc->current->prev=cc->point;//cc->pointÒ»¸öÏÔʾÁеÄÇ°¸öÔªËØcc->current->ch='\0';cc->current->next=cc->current+1;//cc->current+1Ò»¸öÏÔʾÁеĺó¸öÔªËØcc->point=cc->current++;//cc->point=cc->current;cc->current++;}cc->current->prev=cc->point;//×îºóÒ»¸ö½Úµãcc->current->ch='\0';cc->current->next=cc->head;cc->head->prev=cc->current;//Í·½ÚµãµÄÇ°Ò»¸öΪ´ËÁ´µÄ×îºóÒ»¸öÔªËØcc->current=cc->point=cc->head;//freeµôÉêÇëµÄÄÚ´æÒªÓÃcurrentµ±²ÎÊýcc->head->ch=randomChar();//¶ÔÁ´±íÍ·µÄÔªËØÌî³äreturn0;}LRESULTCALLBACKWndProc(HWNDhwnd,UINTmessage,WPARAMwParam,LPARAMlParam){HDChdc;//ctnÓÃÀ´È·¶¨Ò»¸öÏÔʾÁ´ÊÇ·ñÏòÏÂÇ°½ø,Èç¹ûµÈ´ý´ÎÊý³¬¹ý±ØÐëµÈ´ýµÄ´ÎÊý,ctn¾Í´ú±íÒªÏòÏÂÇ°½øinti,j,temp,ctn;//jΪһ¸öÏÔʾÁ´ÖгýÁ´±íÍ·ÍâµÄÔÚÆÁÄ»ÉÏÏÔʾµÄy×ø±ê,tempÂÌÉ«¹ý¶Èµ½ºÚÉ«Ö®ÓÃstaticHDChdcMem;HFONThFont;staticHBITMAPhBitmap;staticintcxScreen,cyScreen;//ÆÁÄ»µÄ¿í¶È¸ß¶È.staticintiFontWidth=10,iFontHeight=15,iColumnCount;//×ÖÌåµÄ¿í¶È¸ß¶È,ÁÐÊýstaticCharColumn*ccChain;switch(message){caseWM_CREATE:cxScreen=GetSystemMetrics(SM_CXSCREEN);//ÆÁÄ»¿í¶ÈcyScreen=GetSystemMetrics(SM_CYSCREEN);SetTimer(hwnd,ID_TIMER,10,NULL);hdc=GetDC(hwnd);hdcMem=CreateCompatibleDC(hdc);hBitmap=CreateCompatibleBitmap(hdc,cxScreen,cyScreen);SelectObject(hdcMem,hBitmap);ReleaseDC(hwnd,hdc);//´´½¨×ÖÌåhFont=CreateFont(iFontHeight,iFontWidth-5,0,0,FW_BOLD,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DRAFT_QUALITY,FIXED_PITCH|FF_SWISS,TEXT("Fixedsys"));SelectObject(hdcMem,hFont);DeleteObject(hFont);SetBkMode(hdcMem,TRANSPARENT);//ÉèÖñ³¾°Ä£Ê½ÎªÍ¸Ã÷iColumnCount=cxScreen/(iFontWidth*3/2);//ÆÁÄ»ËùÏÔʾ×ÖĸÓêµÄÁÐÊýccChain=(pCharColumn)calloc(iColumnCount,sizeof(CharColumn));for(i=0;i<iColumnCount;i++){init(ccChain+i,cyScreen,(iFontWidth*3/2)*i);}return0;caseWM_TIMER:hdc=GetDC(hwnd);PatBlt(hdcMem,0,0,cxScreen,cyScreen,BLACKNESS);//½«ÄÚ´æÉ豸ӳÏñË¢³ÉºÚÉ«for(i=0;i<iColumnCount;i++){ctn=(ccChain+i)->iStopTimes++>(ccChain+i)->iMustStopTimes;//(ccChain+i)->point=(ccChain+i)->head;//pointÓÃÓÚ±éÀúÕû¸öÏÔʾÁÐ//µÚÒ»¸ö×Ö·ûÏÔʾΪ°×É«SetTextColor(hdcMem,RGB(255,255,255));TextOut(hdcMem,(ccChain+i)->x,(ccChain+i)->y,&((ccChain+i)->point->ch),1);j=(ccChain+i)->y;(ccChain+i)->point=(ccChain+i)->point->next;//±éÀúÕû¸öÏÔʾÁÐ,½«Õâ¸öÏÔʾÁÐÀïµÄ×Ö·û´ÓÏÂÍùÉÏÏÔʾtemp=0;//tempÂÌÉ«¹ý¶Èµ½ºÚÉ«Ö®ÓÃwhile((ccChain+i)->point!=(ccChain+i)->head&&(ccChain+i)->point->ch){SetTextColor(hdcMem,RGB(0,255-(255*(temp++)/(ccChain+i)->iStrLen),0));TextOut(hdcMem,(ccChain+i)->x,j-=iFontHeight,&((ccChain+i)->point->ch),1);(ccChain+i)->point=(ccChain+i)->point->next;}if(ctn)(ccCh

1 / 6
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功