当前位置:网站首页>ELS timer
ELS timer
2022-07-28 03:10: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:
//GetLastError();
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、 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, 1000, NULL);
}
3、 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();
//
void OnReturn(HWND hWnd);
#endif
边栏推荐
- Docker高级篇-Docker容器内Redis集群配置
- TFX airflow experience
- 数据中台建设(三):数据中台架构介绍
- NPDP candidates! The exam requirements for July 31 are here!
- Redis AOF log persistence
- MySQL index learning
- Design and practice of unified security authentication for microservice architecture
- Collision and rebound of objects in unity (learning)
- Using pytorch's tensorboard visual deep learning indicators | pytorch series (25)
- 数据湖:数据库数据迁移工具Sqoop
猜你喜欢

TFX airflow experience
![[stream] basic knowledge of stream](/img/33/0bd85f7e029c81d0c20f463ebb972a.png)
[stream] basic knowledge of stream

汇总了50多场面试,4-6月面经笔记和详解(含核心考点及6家大厂)

Design and practice of unified security authentication for microservice architecture

Actual case of ROS communication

数据湖:海量日志采集引擎Flume

Job 7.27 IO process

Vscode debug displays multiple columns of data

Design of the multi live architecture in different places of the king glory mall

基于c8t6芯片开发RC522模块实现呼吸灯
随机推荐
[wechat applet development (V)] the interface is intelligently configured according to the official version of the experience version of the development version
Building of APP automation environment (I)
What "posture" does JD cloud have to promote industrial digitalization to climb to a "new level"?
QT专题1:实现一个简易计算器
谈一谈百度 科大讯飞 云知声的语音合成功能
[wechat applet development (VI)] draw the circular progress bar of the music player
【红队】ATT&CK - 文件隐藏
els 键盘信息
机器人工程是否有红利期
Web服务器
智能工业设计软件公司天洑C轮数亿元融资
使用PyTorch的TensorBoard-可视化深度学习指标 | PyTorch系列(二十五)
JS 事件对象 offsetX/Y clientX Y PageX Y
How to authenticate Youxuan database client
clientY vs pageY
Arm32 for remote debugging
style=“width: ___“ VS width=“___“
RTSP/Onvif协议EasyNVR视频平台一键升级方案的开发设计逻辑
What kind of job is social phobia suitable for? Can you do we media?
关于权重衰退和丢弃法