数字雨
#include "windows.h" #include "stdlib.h" #include "stdio.h" #include "time.h" #include "string.h" #define ID_TIMER 1 #define STRMAXLEN 25 #define STRMINLEN 8 LRESULT CALLBACK WndProc (HWND,UINT,WPARAM,LPARAM); typedef struct tagCharChain { struct tagCharChain*prev; TCHAR ch; struct tagCharChain*next; }CharChain,*pCharChain; typedef struct tagCharColumn { CharChain *head,*current,*point; int x,y,iStrLen; int iStopTimes,iMustStopTimes; }CharColumn,*pCharColumn; int main(HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow) { static TCHAR szAppName[] = TEXT ("matrix") ; HWND hwnd; MSG msg; WNDCLASS wndclass; 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); return 0;} 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); return msg.wParam; } TCHAR randomChar(){ return (TCHAR)(rand()%(126-33)+33); } int init(CharColumn *cc,int cyScreen,int x){ int j; cc->iStrLen=rand()%(STRMAXLEN-STRMINLEN)+STRMINLEN; cc->x=x+3; cc->y=rand()%3?rand()%cyScreen:0; 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->current->prev = cc->point; cc->current->ch = '