win32-封装BeginPaint

时间:2020-05-08 10:59:56   收藏:0   阅读:82
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(...);

 

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!