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