当前位置:网站首页>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);
}
边栏推荐
- Understand various paths
- Three ways of creating indexes in MySQL
- vm options、program arguments、environment property
- Groundwater, soil, geology and environment
- DVWA之SQL注入
- PCL 点云转强度图像
- Cloud native application comprehensive exercise
- Flink Postgres CDC
- PLATO上线LAAS协议Elephant Swap,用户可借此获得溢价收益
- DocuWare 移动劳动力解决方案可帮助您构建新的生产力模式:随时随地、任何设备
猜你喜欢
Expression evaluation
嵌入式分享合集23
Openpyxl merge cells
Openpyxl cell center
Use of resttemplate and Eureka
SQL question brushing: find the last of all employees who have been assigned departments_ Name and first_ Name and Dept_ no
围绕新市民金融聚焦差异化产品设计、智能技术提效及素养教育
nep 2022 cat
Oozie job scheduling
Nacos installation guide on win system
随机推荐
一文搞懂ES6基本全部语法
梅克尔工作室——HarmonyOS实现列表待办
易观分析:以用户为中心,提升手机银行用户体验,助力用户价值增长
Platofarm community ecological gospel, users can get premium income with elephant swap
[hcip] two mGRE networks are interconnected through OSPF (ENSP)
Understand all the basic grammar of ES6 in one article
mysql 创建索引的三种方式
AlphaFold揭示了蛋白质结构宇宙-从近100万个结构扩展到超过2亿个结构
Comprehensive upgrade, all you can imagine is here -- JD API interface
Django uses the existing data table method of MySQL database
Docker compose install MySQL
Main causes of IT hardware failures and best practices for prevention
【SQL之降龙十八掌】01——亢龙有悔:入门10题
nep 2022 cat
Expression evaluation
BOM系列之window对象
API stability guarantee of Prometheus
Lombook User Guide
Analysys analysis: focus on users, improve the user experience of mobile banking, and help the growth of user value
一篇万字博文带你入坑爬虫这条不归路 【万字图文】