当前位置:网站首页>Visual programming - drawing assignment
Visual programming - drawing assignment
2022-04-23 03:22:00 【Tang Encheng_ hhhc】
The operation code is as follows
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpsszCmdLine, int nCmdShow)
{
HWND hwnd;
MSG Msg;
WNDCLASS wndclass;
TCHAR lpszClassName[] = L"My_Drawing";
TCHAR lpszTitle[] = L" Basic drawing ";
wndclass.style = 0;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = lpszClassName;
if (!RegisterClass(&wndclass))
{
MessageBeep(0);
return FALSE;
}
hwnd = CreateWindow(lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HPEN hP; // Define brush handle
HBRUSH hB; // Define brush handle
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SetMapMode(hdc, MM_TEXT);
Rectangle(hdc, 130, 60, 270, 200);
hB = CreateHatchBrush(HS_CROSS, RGB(255, 0, 0));
SelectObject(hdc, hB);
Ellipse(hdc, 130, 70, 270, 190);
hP = CreatePen(PS_DASHDOT, 1, RGB(0, 255, 0));
SelectObject(hdc, hP);
MoveToEx(hdc, 100, 130, NULL);
LineTo(hdc, 300, 130);
MoveToEx(hdc, 200, 30, NULL);
LineTo(hdc, 200, 230);
EndPaint(hwnd, &ps);
DeleteObject(hP);
DeleteObject(hB);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
All the code to draw on the window should be added wndproc Functional case WM_PAINT: in
Brush brush first define , Then select hwnd in , Then it can be realized with various drawing functions , Finally, delete the mural brush .
tips: Draw hollow with a brush , Draw solid or filled with grid inside with brush . If both brush and brush are defined , Then it is to draw the outline with a brush , Fill the interior with a brush .
版权声明
本文为[Tang Encheng_ hhhc]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220621319679.html
边栏推荐
- 批量下载文件----压缩后再下载
- This new feature of C 11, I would like to call it the strongest!
- MySQL keyword group_ Concat, combined connection query
- Five tips for cross-border e-commerce in 2022
- Using swagger in. Net5
- oracle 查询外键含有逗号分隔的数据
- Preview of converting doc and PDF to SWF file
- Explication détaillée des fonctions send () et recv () du programme Socket
- Fiddler use
- General testing technology [1] classification of testing
猜你喜欢
Iotos IOT middle platform is connected to the access control system of isecure center
C WPF UI framework mahapps switching theme
New ORM framework -- Introduction to beetlsql
Log4net is in Net core usage
超好用的Excel异步导出功能
2022g2 boiler stoker examination question bank and online simulation examination
How to achieve centralized management, flexible and efficient CI / CD online seminar highlights sharing
When migrating tslib_ setup: No such file or directory、ts_ open: No such file or director
一文了解全面静态代码分析
[Mysql] LEFT函数 | RIGHT函数
随机推荐
2022g2 boiler stoker examination question bank and online simulation examination
The most understandable life cycle of dependency injection
QT dynamic translation of Chinese and English languages
WinForm allows the form form to switch between the front and active states
There is no index in the database table. When inserting data, SQL statements are used to prevent repeated addition (Reprint)
Five tips for cross-border e-commerce in 2022
Supersocket is Used in net5 - command
12. < tag linked list and common test site synthesis > - lt.234 palindrome linked list
Quartz. Www. 18fu Used in net core
Idea view history [file history and project history]
Do you really understand hashcode and equals???
一套组合拳,打造一款 IDEA 护眼方案
POI create and export Excel based on data
Ide-idea-problem
Flink实时数仓项目—DWS层设计与实现
软件测试相关知识~
Téléchargement en vrac de fichiers - téléchargement après compression
Scenario Title: how does system a use the page of system B
Detailed explanation of socket programming send() and recv() functions
When migrating tslib_ setup: No such file or directory、ts_ open: No such file or director