Achieve the star flow effect
The code is as follows
#include <windows.h> #include <stdio.h>const int starnum = 300;void Drawstar (hwnd hwnd); int cxclient, Cyclient;short Arr[starnum][3]; HDC hdc;static int num= 0; LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM); int WINAPI WinMain (hinstance hinstance, HI Nstance hprevinstance, LPSTR lpcmdline, int ncmdshow) {static TCHAR szappname[] = TEXT ("Wndclass by Lxy"); Hwndhwnd; msgmsg; wndclasswndclass;//window class initialization wndclass.style= Cs_vredraw | cs_hredraw;wndclass.lpfnwndproc= wndproc;wndclass.cbclsextra= 0;wndclass.cbwndextra= 0;wndclass.hbrBackground= ( Hbrush) Getstockobject (White_brush); wndclass.hcursor= loadcursor (Null,idc_arrow); wndclass.hicon= LoadIcon (NULL, idi_application); wndclass.hinstance= hinstance;wndclass.lpszclassname= szappname;wndclass.lpszmenuname= NULL;// Register window class if (! RegisterClass (&wndclass)) {MessageBox (Null,text ("Allocation window class failed!"), szappname,mb_iconerror); return 0;} Create window hwnd = CreateWindow (Szappname,text ("Information display"), Ws_overlappedwindow,cw_usedefault, Cw_usedefAult,cw_usedefault, cw_usedefault,null, NULL, HINSTANCE, NULL); ShowWindow (hwnd,ncmdshow); UpdateWindow (HWND), while (TRUE) {if (PeekMessage (&msg, NULL, 0, 0, pm_remove)) {if (msg.message = = wm_quit) break; TranslateMessage (&msg);D ispatchmessage (&msg);} Else{drawstar (HWND);}} return Msg.wparam;} LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {switch (message) {Case wm_size:cxclient = LO WORD (lParam); cyclient = HiWord (lParam); int i;for (i = 0; i < Starnum; i++) {arr[i][0] = rand ()%cxclient;arr[i][1] = Rand ()%cyclient;arr[i][2] = rand ()%255;} return 0;case wm_destroy:postquitmessage (message); return 0;} return DefWindowProc (Hwnd,message,wparam,lparam);} void Drawstar (HWND hwnd) {int i;for (i = 0; i < Starnum; i++) {if (++arr[i][0] > Cxclient) {arr[i][0] = rand ()%cxclien T/3;ARR[I][1] = rand ()%cyclient;arr[i][2] = rand ()%255;}} HDC = GetDC (hwnd); SelectObject (hdc, Getstockobject (Black_brush)); Rectangle (hdc, 0, 0, cxclient, cyclient); SetBkMode (HDC, RGB (255,255,255)); for (i = 0; i < Starnum; i++) {SetPixel (hdc, arr[i][0], arr[i][1], RGB (arr[i][2],arr[i][2],arr[i][2]));} ReleaseDC (hwnd, HDC); Sleep (10);}
Windows API for Star flow