GDI简单介绍

https://blog.csdn.net/zhoumin4576/article/details/102565308

对于GDI的理解
GDI:在物理设备上显示图形,可以理解为一个程序(对比有界面的)画图工具软件

2.GDI座标

 

 

 

3.GDI画图

 

4.测试原码GDITest.cpp

#include <windows.h>

LRESULT CALLBACK pfnWndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
MSG stMsg;
memset(&stMsg, 0, sizeof (stMsg));
HWND stHwnd;
memset(&stHwnd, 0, sizeof (stHwnd));
WNDCLASS stWndClass;
memset(&stWndClass, 0, sizeof (stWndClass));
const TCHAR szAppName[] = TEXT("SCROLL TEST");

stWndClass.style = CS_HREDRAW | CS_VREDRAW;
stWndClass.lpfnWndProc = pfnWndProc;
stWndClass.cbClsExtra = 0;
stWndClass.cbWndExtra = 0;

stWndClass.hInstance = hInstance;
stWndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
stWndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
stWndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
stWndClass.lpszMenuName = NULL;
stWndClass.lpszClassName = szAppName;

if (!RegisterClass(&stWndClass))
{
MessageBox(NULL, TEXT("Regiester failure"), szAppName, MB_ICONERROR);
return 0;
}

stHwnd = CreateWindow(szAppName,
TEXT("SCROLL TEST"),
WS_OVERLAPPEDWINDOW | WS_VSCROLL /*| WS_HSCROLL*/,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);

ShowWindow(stHwnd, iCmdShow);
UpdateWindow(stHwnd);

while (GetMessage(&stMsg, NULL, 0, 0))
{
TranslateMessage(&stMsg);
DispatchMessage(&stMsg);
}

return stMsg.wParam;
}

LRESULT CALLBACK pfnWndProc(HWND stHwnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{
HDC stHdc;
memset(&stHdc, 0, sizeof (stHdc));
PAINTSTRUCT stPs;
memset(&stPs, 0, sizeof (stPs));
RECT stRect;
memset(&stRect, 0, sizeof (stRect));
POINT astPoint[5] = { { 100, 100 }, { 200, 100 }, { 200, 200 }, { 100, 200 }, { 100, 100 } };
POINT astBezier[4] = { {100, 100}, {200, 150}, {200, 200}, {100, 300} };

switch (uiMsg)
{
case WM_CREATE:

return 0;

case WM_SIZE:

return 0;

case WM_VSCROLL:

return 0;

case WM_PAINT:
stHdc = BeginPaint(stHwnd, &stPs);
GetClientRect(stHwnd, &stRect);
#if 0 //用线画矩形
for (int ixPoint = 0; ixPoint < stRect.right; ixPoint += 100)
{
MoveToEx(stHdc, ixPoint, 0, NULL);
LineTo(stHdc, ixPoint, stRect.bottom);
}
#endif

#if 0 //用线画矩形
//Polyline(stHdc, astPoint, sizeof (astPoint) / sizeof (astPoint[0]));
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
MoveToEx(stHdc, astPoint[0].x, astPoint[0].y, NULL);
PolylineTo(stHdc, astPoint + 1, sizeof (astPoint) / sizeof (astPoint[0]) - 1);
#endif

#if 0 //矩形, 椭圆, 圆角矩形
Rectangle(stHdc, 10, 10, 300, 200); //矩形
Ellipse(stHdc, 10, 300, 300, 500);//椭圆
RoundRect(stHdc, 400, 300, 700, 500, 10, 20);//圆角矩形
#endif

#if 1 //贝塞尔曲线

PolyBezier(stHdc, astBezier, sizeof (astBezier) / sizeof (astBezier[0]));
#endif
EndPaint(stHwnd, &stPs);
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;

default:
return DefWindowProc(stHwnd, uiMsg, wParam, lParam);
}
}
5.GDI函式及应用将后续添加(特别对文字,对图片的加载等),GDI及GDI+的对比。

posted @ 2023-04-17 17:32  yinghualeihenmei  阅读(120)  评论(0编辑  收藏  举报