首页 > Windows开发 > 详细

win32-封装BeginPaint

时间:2020-05-08 10:59:56      阅读:77      评论:0      收藏:0      [点我收藏+]
Graphics* StartPaint(HWND win, HDC* hdc, PAINTSTRUCT* ps)
{
    *hdc = BeginPaint(win, ps);
    return new Graphics(*hdc);
}


 case WM_PAINT:
        {
            HDC hdc;
            PAINTSTRUCT ps;
            Graphics* g = StartPaint(hWnd, &hdc, &ps);           
            SolidBrush solidBrush(Color(255, 255, 0, 0));           
            Point point1 = Point(0, 0);
            Point point2 = Point(0, 10);
            Point point3 = Point(10, 10);
            Point point4 = Point(10, 0);
            Point points[4] = {point1,point2,point3,point4};
            g->FillPolygon(&solidBrush, points, 4);
            delete g;
            EndPaint(hWnd, &ps);
        }
        break;

更好的方法:

std::unique_ptr<Graphics> StartPaint(    ...) 
{ 
    ... 
    return std::make_unique<Graphics>(*hdc); 
}

auto g = StartPaint(...);

 

win32-封装BeginPaint

原文:https://www.cnblogs.com/strive-sun/p/12849101.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!