zoukankan      html  css  js  c++  java
  • 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  
  • 相关阅读:
    TestNG 入门教程
    Angularjs中文版本开发指南发布
    你是码农 还是优秀程序员?
    java牛人给新人的几点建议
    有一种毒药叫励志书
    牛人眼中如何精通spring?
    驯服你的Windows Server 2003
    windows 7 里面的iis在哪里
    神器 cmder
    亚信UED前端流程自动化构建工具
  • 原文地址:https://www.cnblogs.com/hui277/p/3487689.html
Copyright © 2011-2022 走看看