Windows API for Star flow

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.