当前位置:网站首页>ELS square movement
ELS square movement
2022-07-29 01:38:00 【joker_ 0030】
1、 The main function (els.main.c)
#include<Windows.h>
#include"resource.h"
#include"els_h.h"
LRESULT CALLBACK PELouSi(HWND hWnd, UINT oMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,LPSTR ipCmdLine,int nCmdShow)
{
// Initialize window class .
WNDCLASSEX db;
HWND hWnd;
MSG msg;// Structural variable .
db.cbClsExtra = 0;
db.cbSize = sizeof(WNDCLASSEX);
db.cbWndExtra = 0;
db.hbrBackground = (HBRUSH)COLOR_BACKGROUND;// The background color .
// Return value : Handle of mouse .
// Parameters 1: If the system cursor is loaded ,NULL、 If you load a custom cursor , Fill in the real column handle ,hInstance; Parameters 2: System cursor , Fill in the defined macro directly 、 If you load a custom cursor , Just use MAKEINTRESOURCE(240) Load the corresponding resources ID.
//db.hCursor = LoadCursor(NULL,IDC_HAND);// Load the system defined cursor .
db.hCursor = LoadCursor(hInstance,MAKEINTRESOURCE (IDC_NODROP));// Customized cursor . Resource file -> add to -> resources ->Cursor->IDC_NODROP-> newly build .
// Return value : Handle to icon .
// Parameters 1: If the system cursor is loaded ,NULL、 If you load a custom cursor , Fill in the real column handle ,hInstance; Parameters 2: System cursor , Fill in the defined macro directly 、 If you load a custom cursor , Just use MAKEINTRESOURCE(240) Load the corresponding resources ID.
//db.hIcon = LoadIcon(NULL,IDI_ASTERISK);// Load the system defined cursor .
db.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));// Status bar icons .
//db.hIconSm = NULL;// The icon in the upper left corner is defined for this . If it is blank, it defaults to the status bar icon .
db.hIconSm = LoadIcon(NULL,IDI_HAND);
db.hInstance = hInstance;
db.lpfnWndProc = PELouSi;// Callback function name .
db.lpszClassName = "els";
db.lpszMenuName = NULL;
db.style = CS_HREDRAW | CS_VREDRAW;
if(0==RegisterClassEx(&db))
{
int a = GetLastError();
return 0;
}
// create a window .hWnd Window handle Failure to return NULL.
// Window style : Parameters 4.
hWnd=CreateWindowEx(WS_EX_TOPMOST,"els","els square ",WS_OVERLAPPEDWINDOW,100,100,500,600,NULL,NULL,hInstance,NULL);
if (NULL == hWnd)// Window handle . Unique identification of the window .
{
return 0;
}
// Display window
ShowWindow(hWnd, nCmdShow);
// Message loop . queue .
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
// Callback function
// Return value :LRESULT,CALLBACK Calling convention .
// Parameters 1: Window handle ; Parameters 2: news ID.
LRESULT CALLBACK PELouSi(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)// LRESULT:long type ;UINT: Unsigned integer , News ID.
{
PAINTSTRUCT pt;// Defining structure .
HDC hDc;
// Close window message
switch (nMsg)
{
case WM_CREATE:// The first message received by the window information handler , It is also the first message processed by the callback function ( by WM_CREATE). This message is generated only once , It is generally used to initialize some data .
//GetLastError();// Optimize .
Oncreate();// Game data initialization .
break;
case WM_TIMER:
OnTimer(hWnd);
break;
// Is the second message processed by the callback function ( by WM_PAINT).
// When a part of the display area of the window changes to ( Invalid ), So much so that ( Update the screen ) when , The program will be notified by this message .
// The last member of the window structure CS_HREDRAW|CS_VREDRAW, The purpose is when the window size changes , produce WM_PAINT news .
// When windows overlap , When the overlap gradually appears .
case WM_PAINT:
//GetLastError();// Optimize .
hDc=BeginPaint(hWnd,&pt);//getDC, Identification of window operable area .
// Draw the contents of the window in between .
// Draw squares .
OnPaint(hDc);// Increase code readability .
EndPaint(hWnd, &pt);// end .
break;
case WM_KEYDOWN:
switch (wParam)
{
case VK_RETURN:
OnReturn(hWnd);
break;
case VK_LEFT:
break;
case VK_RIGHT:
break;
case VK_UP:
break;
case VK_DOWN:
break;
}
break;
case WM_DESTROY:
KillTimer(hWnd, DEF_TIMER1);
PostQuitMessage(0);// call PostQuitMessage(0) This function emits WM_QUIT news .// The point and fork system generates WM_CLOSE,WM_DESTROY,WM_QUIT.
break;
}// Manually handle the cross off message .
return DefWindowProc(hWnd, nMsg, wParam, lParam);
//LRESULT a=DefWindowProc(hWnd, oMsg, wParam, lParam);// function
//return a;
}
2、 Head function (els.h)
#ifndef N_d
#define N_d
#include<Windows.h>
#include<time.h>
#define DEF_TIMER1 1234
void OnPaint(HDC hDc);
// Display box .
void PaintSqare(HDC hMemDC);
// Generate random blocks .
int CreateRandomSqare();
// Random blocks close to the background .
void CopySqareToBack();
void Oncreate();
// Enter key .
void OnReturn(HWND hWnd);
// The fall of the square .
void SqareDwon();
// Timer response function .
void OnTimer(HWND hWnd);
#endif
3、 Function implementation (els.c)
#include"els_h.h"
// Background array
char g_arrBackGroud[20][10] = {0};
char g_arrSqare[2][4] = {0};
void OnPaint(HDC hDc)
{
// Create compatibility DC.
HDC hMemDC = CreateCompatibleDC(hDc);// Memory id by :HMemDc, window id hDc.
// Create compatibility bitmap .
HBITMAP hBitmapBack= CreateCompatibleBitmap(hDc, 500, 600);
// Connect .
SelectObject(hMemDC, hBitmapBack);
PaintSqare(hMemDC);
// Pass on :
// Return value : Failure to return 0, Successfully returned non-zero .
// Parameters 1: The goal is DC, window DC
// Parameters 2,3: The starting position of the target , Attention is based on our window .
// Parameters 4,5: The size of the area .
// Parameters 6: Source DC, That is, our memory DC.
// Parameters 7,8: The starting position of the memory picture .
// Parameters 9: delivery .
//
BitBlt(hDc, 0, 0, 300, 600, hMemDC, 0, 0, SRCCOPY);
// Release DC
DeleteObject(hBitmapBack);
DeleteDC(hMemDC);
}
void Oncreate()
{
srand((unsigned int)time(NULL));// Only once .
CreateRandomSqare();
CopySqareToBack();
}
void PaintSqare(HDC hMemDC)
{
int i = 0,
j = 0;
// Draw a big square .
Rectangle(hMemDC, 0, 0, 300, 600);// The coordinates of the starting position and the ending position of the rectangular box from the running window .
// Specify a square .
/*g_arrBackGroud[2][4] = 1;
g_arrBackGroud[3][3] = 1;
g_arrBackGroud[3][4] = 1;
g_arrBackGroud[3][5] = 1;*/
// Traverse
for (i=0 ; i < 20; i++)
{
for (j=0 ; j < 10; j++)
{
if (1 == g_arrBackGroud[i][j])
{
// Draw squares .
Rectangle(hMemDC, j*30, i*30, j*30 + 30, i*30 + 30);// The coordinates of the starting position and the ending position of the rectangular box from the running window .
}
}
}
}
// Create random block .
int CreateRandomSqare()
{
int nIndex=rand()%7;
switch (nIndex)
{
case 0:
g_arrBackGroud[0][0] = 1, g_arrBackGroud[0][1] = 1, g_arrBackGroud[0][2] = 0, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 0, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 1, g_arrBackGroud[1][3] = 0;
break;
case 1:
g_arrBackGroud[0][0] = 0, g_arrBackGroud[0][1] = 1, g_arrBackGroud[0][2] = 1, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 1, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 0, g_arrBackGroud[1][3] = 0;
break;
case 2:
g_arrBackGroud[0][0] = 1, g_arrBackGroud[0][1] = 0, g_arrBackGroud[0][2] = 0, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 1, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 1, g_arrBackGroud[1][3] = 0;
break;
case 3:
g_arrBackGroud[0][0] = 0, g_arrBackGroud[0][1] =0 , g_arrBackGroud[0][2] = 1, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 1, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 1, g_arrBackGroud[1][3] = 0;
break;
case 4:
g_arrBackGroud[0][0] = 0, g_arrBackGroud[0][1] = 1, g_arrBackGroud[0][2] = 0, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 1, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 1, g_arrBackGroud[1][3] = 0;
break;
case 5:
g_arrBackGroud[0][0] = 0, g_arrBackGroud[0][1] = 1, g_arrBackGroud[0][2] = 1, g_arrBackGroud[0][3] = 0;
g_arrBackGroud[1][0] = 0, g_arrBackGroud[1][1] = 1, g_arrBackGroud[1][2] = 1, g_arrBackGroud[1][3] = 0;
break;
case 6:
g_arrBackGroud[0][0] = 1, g_arrBackGroud[0][1] = 1, g_arrBackGroud[0][2] = 1, g_arrBackGroud[0][3] = 1;
g_arrBackGroud[1][0] = 0, g_arrBackGroud[1][1] = 0, g_arrBackGroud[1][2] = 0, g_arrBackGroud[1][3] = 0;
break;
}
return nIndex;
}
void CopySqareToBack()
{
int i = 0,
j = 0;
for (i = 0; i < 2; i++)
{
for (j = 0; j < 4; j++)
{
g_arrBackGroud[i][j + 3] = g_arrSqare[i][j];
}
}
}
void OnReturn(HWND hWnd)
{
// Start timer
// Return value : Successfully returned non-zero .
// Parameters 1: Window handle hWnd,NUL
// Parameters 2: Timer ID Ignore
// Parameters 3: Time interval between , millisecond 1000ms=1s.
// Parameters 4: Set to NULL Address of processing function .
SetTimer(hWnd, DEF_TIMER1, 500, NULL);
}
void SqareDwon()
{
int i = 0,
j = 0;
for (i = 19; i >=0; i--)
{
for (j = 0; j < 10; j++)
{
if (1==g_arrBackGroud[i][j])
{
g_arrBackGroud[i + 1][j] = g_arrBackGroud[i][j];
g_arrBackGroud[i][j]=0;
}
}
}
}
void OnTimer(HWND hWnd)
{
HDC hDc=GetDC(hWnd);// Kernel object .
SqareDwon();
// Display box :
//PaintSqare(hDc);
OnPaint(hDc);
ReleaseDC(hWnd, hDc);
}
边栏推荐
- Bracket matching test
- Analysys analysis: focus on users, improve the user experience of mobile banking, and help the growth of user value
- Lombook User Guide
- C语言犄角旮旯的知识之形参、实参、main函数参数、数组或指针做函数参数等
- Openpyxl cell center
- 拼多多众多 API 接口皆可使用
- ELMO,BERT和GPT简介
- vm options、program arguments、environment property
- File “manage.py“, line 14 ) from exc
- Log4j dynamic loading configuration file
猜你喜欢

Flink SQL Hudi actual combat

Linux redis source code installation

一篇万字博文带你入坑爬虫这条不归路 【万字图文】

地下水、土壤、地质、环境人看过来

AlphaFold揭示了蛋白质结构宇宙-从近100万个结构扩展到超过2亿个结构

Cloud native application comprehensive exercise

一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力

Test / development programmers rely on technology to survive the midlife crisis? Improve your own value

Window object of BOM series

Teach you a text to solve the problem of JS digital accuracy loss
随机推荐
mysql 创建索引的三种方式
【HCIP】MPLS 基础
Self-attention neural architecture search for semantic image segmentation
Test / development programmers rely on technology to survive the midlife crisis? Improve your own value
我们总结了 3 大Nacos使用建议,并首次公开 Nacos 3.0 规划图 Nacos 开源 4 周年
BOM系列之window对象
[unity project practice] synthetic watermelon
Canal实时解析mysql binlog数据实战
【HCIP】MGRE环境下OSPF实验,含多进程双向重发布及OSPF特殊区域
明日无限计划,2022某公司元宇宙产品发布会活动概念策划方案
After understanding the composition of the URL of the website, we use the URL module, querystring module and mime module to improve the static website
什么是原码、反码和补码
vm options、program arguments、environment property
Docuware mobile labor solution can help you build a new productivity model: anytime, anywhere, any device
瑞吉外卖项目实战Day01
Error installing mysqlclient module on MAC system
What are source code, inverse code and complement code
Code generator
Flink SQL Hudi 实战
PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益