Don't step on the white. Zen Mode Windows program implementation

Source: Internet
Author: User
Tags textout

Don't step on the white. Zen Mode Windows program implementation

The code is as follows

#include <windows.h>lresult CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (//Program entry, WINAPI is a function calling convention that shows how to generate machine code that puts call parameters in the stack hinstance hinstance//instance handle, identifies the program, HINSTANCE hpreinstance//16 bits used to identify the previous instance of the program, 32 bits are no longer used, parameters are null, LPSTR szcmdline//call command line, int icmdshow)//window display method {static TCHAR szname[] = TEXT ("Hiyun"); HWND hwnd; MSG msg; Wndclass Wc;wc.style = Cs_vredraw | Cs_hredraw;wc.cbclsextra = 0;wc.cbwndextra = 0;wc.hbrbackground = (hbrush) getstockobject (WHITE_BRUSH); wc.hCursor = LoadCursor (null, idc_arrow); Wc.hicon = LoadIcon (null, idi_application); wc.hinstance = Hinstance;wc.lpfnwndproc = Wndproc;wc.lpszmenuname = Null;wc.lpszclassname = Szname;if (! RegisterClass (&AMP;WC)) {MessageBox (NULL, TEXT ("Registration failed!") "), TEXT (" failed "), MB_OK | Mb_iconerror);} hwnd = CreateWindow (SzName, TEXT ("Do not step on the white piece of Zen mode-Xianyunyehe production, QQ Group 116920287"), ws_overlappedwindow,400, +, +, 600,null, NULL, H Instance, NULL); ShowWindow (hwnd, icmdshow); UpdateWindow (HWND); while (GetMessage (&msg, NULL, 0, 0)) {TranslatemeSsage (&msg);D ispatchmessage (&msg);} return Msg.wparam;} LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {HDC hdc; Paintstruct PS; Rect rect; TCHAR szbuff[50];static Hbrush brushpass = CreateSolidBrush (RGB (223, 223, 223)), static int I, j, X, Y, TX, ty;static int R Uning, Cxchar, Cychar, Cxclient, Cyclient, Cxsquare, cysquare;static TCHAR playname[] = TEXT ("YUN"); static ULONG score = 0 , t;static int loc[20];switch (message) {case wm_create:runing = 0;HDC = GetDC (hwnd); Textmetric TM; GetTextMetrics (hdc, &AMP;TM); Cxchar = Tm.tmavecharwidth;cychar = Tm.tmheight + tm.tmexternalleading; ReleaseDC (hwnd, HDC); return 0;case wm_size:cxclient = loword (lparam); cyclient = HiWord (lparam); cxsquare = Cxclient/4;cy Square = (int) (Cxsquare * 1.5); for (i = 0; I <= cyclient/cysquare + 2; ++i) {Loc[i] = rand ()% 4;} return 0;case wm_lbuttondown:tx = x = LoWord (lparam), Ty = y = hiword (lparam); x/= cxsquare;y = (cyclient-y)/Cysquare;i F (loc[0] = = x && y = = 0 &&!runing) {runing = 1;invalidaterect (hwnd, NULL, True);}  else if (loc[1] = = x && y = = 1 && runing) {score++;for (i = 0; I <= cyclient/cysquare + 1; ++i) {Loc[i] = Loc[i + 1];} Loc[i] = rand ()% 4;invalidaterect (hwnd, NULL, True);} return 0;case WM_PAINT:HDC = BeginPaint (hwnd, &AMP;PS); SetBkMode (hdc, TRANSPARENT); SetTextColor (hdc, RGB (255, 0, 0)); for (i = 1; i < 4; ++i) {Movetoex (hdc, Cxsquare * I, 0, NULL); LineTo (HDC, Cxsquare * I, cyclient);} for (i = 0; I <= cyclient/cysquare + 1; ++i) {Movetoex (hdc, 0, Cyclient-cysquare * i, NULL); LineTo (hdc, cxclient, Cyclient-cysquare * i), j = loc[i];if (i = = 0 && runing) SelectObject (hdc, brushpass); Elsese Lectobject (hdc, Getstockobject (Black_brush)); Rectangle (HDC, J * Cxsquare, Cyclient-cysquare * (i + 1), Cxsquare * (j + 1) + 1, Cyclient-cysquare * i + 1); if (!runin G && i = = 0) {TextOut (hdc, J * cxsquare + CXSQUARE/2-Cxchar * 1.5, Cyclient-cysquare/2,szbuff, wsprintf (SzB Uff, TEXT ("Start")));}} TeXtout (hdc, Cxchar, Cychar, szbuff,wsprintf (Szbuff, Text ("player:%s"), playname)); t = wsprintf (Szbuff, Text ("Score:%ld" ), score); TextOut (HDC, cxclient-(t + 2) * Cxchar, Cychar, Szbuff, T); EndPaint (hwnd, &AMP;PS); return 0;case wm_destroy:postquitmessage (0); return 0;} Return DefWindowProc (HWND, message, wparam, lparam);}


Don't step on the white. Zen Mode Windows program implementation

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.