• Gdiplus双缓冲绘图


     1 WNDCLASSEX wcex = {0};
     2 
     3 wcex.cbSize = sizeof(WNDCLASSEX);
     4 wcex.lpszClassName = L"test";
     5 wcex.lpfnWndProc = Test::WndProc;
     6 
     7 RegisterClassEx(&wcex);
     8 m_hWnd = ::CreateWindowEx (WS_EX_LEFT, TEXT("test"), NULL, WS_CHILD | BS_OWNERDRAW, 0, 0, 200, 200, hParent, NULL, NULL, 0) ;
     9 
    10  
    11 
    12 HDC hDC = GetDC(hWnd);
    13 RECT wndRect;
    14 ::GetClientRect(hWnd, &wndRect);
    15 int nWidth = wndRect.right-wndRect.left;
    16 int nHeight = wndRect.bottom-wndRect.top;
    17 
    18 Gdiplus::Bitmap *pBmp = new Gdiplus::Bitmap(nWidth, nHeight);
    19 Gdiplus::Graphics graphics(pBmp);
    20 graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias); // 设置抗锯齿
    21 Gdiplus::Pen newPen(Gdiplus::Color( 255, 0, 0 ), 3); 
    22 Gdiplus::Font textFont(L"微软雅黑", 14, Gdiplus::FontStyleRegular);
    23 Gdiplus::SolidBrush solodWhiteBrush(Gdiplus::Color( 255, 255, 255 ));
    24 Gdiplus::Brush *pWhiteBrush= solodWhiteBrush.Clone();
    25 
    26 Gdiplus::SolidBrush solodBlackBrush(Gdiplus::Color( 60, 60, 60 ));
    27 Gdiplus::Brush *pBlackBrush = solodBlackBrush.Clone();
    28 
    29  
    30 
    31 graphics.FillRectangle(pWhiteBrush, 0, 0, nWidth , nHeight ); 
    32 graphics.FillPie(pBlackBrush , 0, 0, 150, 150, 0, 360); 
    33 // 画中间圆形
    34 graphics.FillEllipse(pWhiteBrush, 15, 15, 120, 120);
    35 
    36  
    37 
    38 Gdiplus::StringFormat stringformat(NULL);
    39 Gdiplus::RectF stringRect; 
    40 Gdiplus::RectF layoutRect(0, 0, 200, 200);
    41 
    42 std::wstring strText = "测量文字长度";
    43 graphics.MeasureString(strText.c_str(), strText.size(), &textFont, layoutRect, &stringformat, &stringRect);
    44 oriPoint.X = (200-stringRect.Width)/2;
    45 oriPoint.Y = 125;
    46 graphics.DrawString(strText.c_str(), strText.size(), &textFont, oriPoint, NULL, pBlackBrush );
    47 
    48 Gdiplus::Graphics graphicsHdc(hDC);
    49 /*Important! Create a CacheBitmap object for quick drawing*/
    50 Gdiplus::CachedBitmap cachedBmp(pBmp,&graphicsHdc);
    51 graphicsHdc.DrawCachedBitmap(&cachedBmp,0,0);
    52 
    53 
    54 ::ReleaseDC(hWnd, hDC);
    55 
    56  
  • 相关阅读:
    【Oracle】权限
    【Oracle】利用trace文件重建控制文件
    【Oracle】创建概要文件
    【Oracle】创建角色
    【Oracle】创建用户
    【Oracle】glogin.sql脚本模板
    夺命雷公狗---DEDECMS----1dedecms的安装过程
    夺命雷公狗---微信开发63----微信开发总结篇
    夺命雷公狗---微信开发62----所以memcache对access_token进行全局缓存优化
    夺命雷公狗---微信开发61----在线点播电影网2之电影网之个人中心
  • 原文地址:https://www.cnblogs.com/hui277/p/3487689.html
Copyright © 2020-2023  润新知