win32-封装BeginPaint

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

上一篇:宽带连接显示Windows安全中心输入用户名密码解决方式


下一篇:如何在Win10中查看WIFI密码?