当前位置:网站首页>D2dengine edible tutorial (1) -- the simplest program
D2dengine edible tutorial (1) -- the simplest program
2022-07-23 11:19:00 【dgaf】
The goal is : Create a window with a blue background
1. First the D2DEngine Four files of are added to the project
Right click on the item -> add to -> Existing items
2. Set the compliance mode to no (/permissive)
project -> attribute ->C/C+±> Language -> The compliance mode is set to no
If the mode is not set, an error will be reported . My understanding is that , Because Microsoft is VS2019 After starting, the requirements for value transfer become stricter , Image is not allowed by default char turn const char Such narrowing conversion , May cause memory leak . Here we don't need , Just turn it off .
3. Code
Let's start with Templates , This template is for all D2DEngine The programs are Universal
#include<windows.h>
#include"D2D_DRAW.h" // Directly reference the header file
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {
};
WNDCLASSEX wcex = {
};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS; // Get rid of ReDraw Redraw
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
// Set to NULL_BRUSH, No need to come from GDI Any drawing of
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
// WS_OVERLAPPEDWINDOW Will trigger OnSize news , Don't deal with this message for the time being
0, 0, 640, 480,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
// because CS_GLOBALCLASS, It must be used. ShowWindow Display window
//————————————————————————————————————————————————————————————————————
//TODO: Do it here Direct2D Rendering
//————————————————————————————————————————————————————————————————————
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
This program only needs to render in TODO part ( See note ) Just write it .
| Member functions | effect |
|---|---|
| bool Initialize( hwnd, BrushColor) | D2DEngine Initialization of the device , Anything to do with D2DEngine All operations must go through this step first . Otherwise rendering fails . The parameters are :hwnd Handle ( Required ),BrushColor Brush color ( optional , Default white ) |
| void BeginDraw() | The signal that the program begins to draw ,D2DEngine The draw ( Rendering ) Operation can only be carried out after this function , Otherwise it will not work |
| void Clear(ClearColor) | ( Rendering ) Clear the screen and render the target background color , Parameters :ClearColor Background color ( optional , Default white ) |
| void EndDraw() | The signal that the program stops drawing , Every time BeginDraw One time must end with this function . |
Be careful : belt ( Rendering ) The function of must be in BeginDraw() And EndDraw() It can only take effect between , Like the following code :
Engine->BeginDraw();Engine->Clear(); // Rendering functionEngine->EndDraw();
D2D.CPP
#include<windows.h>
#include"D2D_DRAW.h"
using namespace D2D1;
LRESULT CALLBACK CallBackFunc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hin, HINSTANCE, LPSTR, int CmdShow)
{
MSG msg = {
};
WNDCLASSEX wcex = {
};
memset(&wcex, 0, sizeof(wcex));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.lpfnWndProc = CallBackFunc;
wcex.lpszClassName = L"D2D";
wcex.hInstance = hin;
wcex.style = CS_GLOBALCLASS;
wcex.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
RegisterClassEx(&wcex);
HWND hwnd = CreateWindowW(wcex.lpszClassName, L"D2D",
WS_OVERLAPPED | WS_SYSMENU,
0, 0, 640, 480,
nullptr,
nullptr,
hin,
nullptr
);
ShowWindow(hwnd, CmdShow);
//————————————————————————————————————————————————————————————————————
D2DEngine* Engine = new D2DEngine; // establish D2DEngine object
Engine->Initialize(hwnd); // Initialize with handle D2DEngine
Engine->BeginDraw();
Engine->Clear(ColorF::Blue); // Empty the window and render it blue
Engine->EndDraw();
//————————————————————————————————————————————————————————————————————
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
D2DEngine Resource link :https://blog.csdn.net/DGAF2198588973/article/details/125909836
If you like, please like it
边栏推荐
- Understanding of closures of JS
- SQL常见面试题目与答案整理
- Redis数据库和项目框架
- 【无标题】
- 【pyradiomics】bugFix:GLCM特征时:IndexError: arrays used as indices must be of integer (or boolean) type
- 大厂面试机器学习算法(0):特征工程 | 数据预处理
- 频谱聚类|拉普拉斯矩阵
- [pytho-flask筆記5]藍圖簡單使用
- slice()和splice()区别
- When v-show is used with display:flex in the uni app applet, v-show does not take effect!
猜你喜欢

Redis database and project framework
![[监控部署实操]基于granfana展示Prometheus的图表和loki+promtail的图表](/img/34/b7a05bff05e1d3a1daef4fb2b98a92.png)
[监控部署实操]基于granfana展示Prometheus的图表和loki+promtail的图表

py程序可以运行,但打包出的exe运行提示错误:加载“cv2”二进制扩展时检测到递归。请检查OpenCV安装。

Flask blueprint

JDBC Learning and simple Encapsulation

my_strcpy的实现(经典,简单,实用,收藏)

Fun code rain, share it online~-

【无标题】

Pytorch white from zero uses North pointing

Large factory interview machine learning algorithm (0): Feature Engineering | data preprocessing
随机推荐
Spectral clustering | Laplace matrix
第一篇博客
The attribution of branch and loop statements in C language
Oracle创建数据库“监听程序未启动或数据库服务未注册”错误处理
高阶函数的应用:手写Promise源码(三)
Flask blueprint
构造函数,原型链,instanceOf
Common errors in C language debugging -- brief answer
Use of views
MySQL statement queries all child nodes of a level node
Keras saves the best model in the training process
View set and route
大厂面试机器学习算法(5)推荐系统算法
PyGame realizes the airplane war game
【uiautomation】键指令大全(以及三种调用方式)+常用鼠标动作+SendKeys+Inspect学习
js的call、apply、bind
Understanding of closures of JS
Constructor, prototype chain, instanceof
【6.28】
Uscd pedestrian anomaly data set user guide | quick download