I use C ++ to floating the snow special effect procedure on the desktop (now here! Come back next year.

xiaoxiao2021-03-06  25

Christmas last month! I have a MM to send me a program I am running a good program that is on the desktop snow! Yesterday afternoon final exam just finished! I bought a train ticket in advance and stayed in the school. So, I didn't have anything in the afternoon. I went to the Delphi box. I saw the procedure for the snow special effects written by Liu Xiong. I put it down! Rewriting with C and SDK (Liu brother is also written with SDK): The effect picture of my run is as follows: Time is too short! Ugh! I am painless, I can't become a counter. . . . . I have to put it on the next semester. I have no computer to touch it! There is an industry in the code! #include #include #include #include

Const int snowNumber = 500; // Snowpoint quantity

Struct Snownode {POINT Post POSTION; // Snow Point Position Int iColor; // Previous Color INT ISPEED; // Drop Speed ​​Int Imove; // Drop Int Istick; // Paste};

SnowNode Snownodes [SnowNumber]; // Snow Point Array INT HTIMER = 0; INT CRWIND = 0; INT CRSTEP = 0; // Current Circular Drawn (for Speed) INT ScreenWidth = 0; // Screen Width Int ScreenHeight = 0; // screen height

Void getScreensize (); Void Callback TimerProc (Handle Hwnd, Uint UMSG, UINT IDEVENT, DWORD DWTIME); Void INITSNOWNODES (); void movesnownotes ();

Int WinApi Winmain (Hinstance Hinstance, Hinstance Hprevinstance, LPSTR LPCMDLINE, INT NCMDSHOW) {

Msg msg; // Standard Windows Message Large_integer frequency; // High Performance Timer Frequency Large_integer start, endct; // High Performance Timer count FLOAT ELAPSEDTIME; // Time Interval SRAND ((Unsigned) Time (NULL)); GetScreensize INITSNOWNODES (); queryperformancefrequency; htimer = settimer (0, 0.0, rand ()% 5 * 500, (TimerProc) TimerProc); if (htimer == 0) {MessageBox (0, Text ("creation timing Failure "), Text (" Tips "), MB_OK | MB_ICONInformation; Return -1;} RegisterhotKey (0, 0, MOD_CONTROL, (INT) 'L'); While (1) {queryperformancecounter (& Startct); // Perform calculation before count value IF (PeekMessage (& MSG, 0, 0, 0)) {switch (msg.Message) {Case WM_TIMER: TIMERPROC (0, 0, 0); Break; // Preset wind direction change Time has arrived to Case WM_HOTKEY: KILLTIMER (0, htimer); // Remove the random wind mode unregisterhotkey (0, 0); // Delete Exit Hotkey InvalidateRect (0, Null, True); exit (1); Break; Case WM_DISPLAYCHANGE: GetScreensize (); // Re-Take the screen of the size inIitsnode (); // Initialize the array of snow points;}} movesnode (); queryperformancecounter (& End); // After performing the count value ELAPSEDTIME = (Endct. Quadpart-startct.quadpart) / frequency .Quadpart; if ((ELAPSEDTIME <0.0005)) Sleep (2); // Simple speed ELSE IF (ELAPSEDTIME <0.0010) Sleep (1); ELSE IF (ElapsedTime <0.0015) Sleep (3);

} // MessageBox (0, TEXT ( "message"), TEXT ( "message"), MB_OK | MB_ICONINFORMATION); return 0;} void GetScreenSize () {ScreenWidth = GetSystemMetrics (SM_CXSCREEN); ScreenHeight = GetSystemMetrics (SM_CYSCREEN); return }

Void Callback TimerProc (Handle Hwnd, DWORD DWTIME) {// MessageBox (0, Text ("Message"), Text ("Message"), MB_OK | MB_ICONInformation; SRAND (NULL) TIME )); If (htimer == 0) {MessageBox (0, text ("Create Timer Failed"), Text ("Tips"), MB_OK | MB_ICONInInformation; Return;} Settimer (0, Htimer, (((((RAND) )% 27 4) * 500), (TimerProc); Reset the next wind direction change time // Modify the wind to IF (crwind! = 0) crwind = 0; else crwind = rand ()% 3-1; Return } void initsnode () {HSCREENDC = 0; INT J = 0; hscreendc = createdc ("Display", NULL, NULL, NULL); if (hscreendc == null) {MessageBox (0, "Get screen DC failed! "," Information ", MB_ok | MB_ICONERROR); return;} SRAND (NULL)); for (j = 0; j

Void MoveSnowNode () {// MessageBox (0, Text ("message"), Text ("message"), MB_OK | MB_ICONINFORMATION; HDC hscreendc = 0; SRAND (NULL); int x = 0 , y = 0, i = 0; hscreendc = createdc ("Display", NULL, NULL, NULL); if (hscreendc == null) {MessageBox (0, "Get screen DC failed!", "Information", MB_OK | MB_ICONERROR); return;} // textout (HScreenDC, 0, 0, "Although the big check Shun Yixiang", 0); for (i = 0; I

// Snow (Stop) Effect Processing IF ((Crstep% Snownodes [i] .istic == 0) && ((Getpixel (HScReendc, x, y))! = (Getpixel (HScreenDC, X, Y 1 ))) && (HScReendc, X-1, Y))! = (Getpixel (HScReendc, X-1, Y 1)) && ((Getpixel (HScReendc, x 1, y)! = Getpixel (HScreenDC, X 1, Y 1)))) {// Slightly adjust the coordinate IF (Getpixel (HScReendc, X, Y-1) == Getpixel (HscreenDC, X, Y-2)) {y--; } Else {IF (getPixel (HScreenDC, X, Y-1) == getpixel (HScreenDC, X, Y-2)) y ; x = crwind;} // draw three snowflake points setpixel (hscreendc, x, y, 0xfffff); setpixel (HScreenDC, X 1, Y 1, 0xffff); setpixel (HScreenDC, X-1, Y 1, 0xffff); // Reborn snow point Snownodes [i] .POSTION.X = rand () % ScreenWidth; Snownodes [i] .POSTION.Y = rand ()% 10; Snownodes [i] .icolor = getpixel (hscreendc, snownloads [i] .post.x, snownloads [i] .position.y);} else {IF ((x <0) || (x> screenwidth) || (y> screenheight)) {snowNodes [i] .POSTION.X = (rand ()% 10); Snownodes [i] .post.y = (RAND ()% screenwidth; snowNodes [i] .icol = getpixel (hscreendc, snownodes [i] .POSTION.X, SNOWNODES [i] .POSTION.Y) } Else {// Save color and draw snow spots Snownodes [i] .icolor = getpixel (hscreendc, x, y); setpixel (HScReendc, x, y, 0xffff); // Save new snow point position Snownodes [i ] .POSTION.X = X; Snownodes [i] .POSTION.Y = Y;}}} delededc (hscreendc); Crstep ;} full of text!

转载请注明原文地址:https://www.9cbs.com/read-65442.html

New Post(0)