void wxsDrawingWindow::OnPaint(wxPaintEvent& event) { if ( !m_DuringFetch ) { wxPaintDC PaintDC(this); PrepareDC(PaintDC); if ( m_IsBlockFetch || NoNeedToRefetch() ) { if ( m_Bitmap ) { wxBitmap BmpCopy = m_Bitmap->GetSubBitmap(wxRect(0,0,m_Bitmap->GetWidth(),m_Bitmap->GetHeight())); wxBufferedDC DC(&PaintDC,BmpCopy); PaintExtra(&DC); } } else { StartFetchingSequence(); } } else { event.Skip(); } }
void CPictureWnd::OnPaint() { CPaintDC PaintDC(this); CRect ClientArea; GetClientRect(ClientArea); m_Picture.Paint(&PaintDC,ClientArea,m_AnimFrames); }
void CSkinStatic::OnPaint(CDCHandle dc) { CPaintDC PaintDC(m_hWnd); CRect rcClient; GetClientRect(&rcClient); CMemoryDC MemDC(PaintDC.m_hDC, rcClient); Draw(MemDC.m_hDC); }
void CTextProgressCtrl::OnPaint() { if (m_nMin >= m_nMax) return; CRect LeftRect, RightRect, ClientRect; GetClientRect(ClientRect); double Fraction = (double)(m_nPos - m_nMin) / ((double)(m_nMax - m_nMin)); CPaintDC PaintDC(this); // device context for painting CMyMemDC dc(&PaintDC); //CPaintDC dc(this); // device context for painting (if not double buffering) LeftRect = RightRect = ClientRect; LeftRect.right = LeftRect.left + (int)((LeftRect.right - LeftRect.left)*Fraction); dc.FillSolidRect(LeftRect, m_colFore); RightRect.left = LeftRect.right; dc.FillSolidRect(RightRect, m_colBk); if (m_bShowText) { CString str; if (m_strText.GetLength()) str = m_strText; else str.Format(_T("%d%%"), (int)(Fraction*100.0)); dc.SetBkMode(TRANSPARENT); CRgn rgn; rgn.CreateRectRgn(LeftRect.left, LeftRect.top, LeftRect.right, LeftRect.bottom); dc.SelectClipRgn(&rgn); dc.SetTextColor(m_colTextBk); dc.DrawText(str, ClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); rgn.DeleteObject(); rgn.CreateRectRgn(RightRect.left, RightRect.top, RightRect.right, RightRect.bottom); dc.SelectClipRgn(&rgn); dc.SetTextColor(m_colTextFore); dc.DrawText(str, ClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); } }
void CFaceCtrl::OnPaint(CDCHandle dc) { CPaintDC PaintDC(m_hWnd); CRect rcClient; GetClientRect(&rcClient); CMemoryDC MemDC(PaintDC.m_hDC, rcClient); MemDC.FillSolidRect(&rcClient, m_clrBg); DrawLine(MemDC.m_hDC); CRect rcItem, rcImage; int nRow = 0, nCol = 0; int nLeft = 0, nTop = 0; for (int i = 0; i < (int)m_arrImage.size(); i++) { rcItem = CRect(nLeft, nTop, nLeft+m_nItemWidth, nTop+m_nItemHeight); CGifImage * lpImage = m_arrImage[i]; if (lpImage != NULL) { CalcCenterRect(rcItem, lpImage->GetWidth(), lpImage->GetHeight(), rcImage); lpImage->Draw(MemDC.m_hDC, rcImage, 0); } if (m_nHoverIndex == i) DrawFocusBorder(MemDC.m_hDC, rcItem); nLeft += m_nItemWidth; nCol++; if (nCol >= m_nCol) { nCol = 0; nRow++; if (nRow > m_nRow) break; nLeft = 0; nTop += m_nItemHeight; } } if (m_nHoverIndex != -1) DrawZoomImage(MemDC.m_hDC); }
void CWeekTimePicker::OnPaint() { CRect rcClient; GetClientRect(&rcClient); CPaintDC dc(this); HDC hdc = ::CreateCompatibleDC(dc.GetSafeHdc()); HBITMAP hBmp = ::CreateCompatibleBitmap(dc.GetSafeHdc(), rcClient.Width(), rcClient.Height()); HBITMAP hOldBmp = (HBITMAP)::SelectObject(hdc, hBmp); ::FillRect(hdc, &rcClient, (HBRUSH)m_brushDlgBack.GetSafeHandle()); ::SetBkMode(hdc, TRANSPARENT); PaintDC(hdc); ::BitBlt(dc.GetSafeHdc(), 0, 0, rcClient.Width(), rcClient.Height(), hdc, 0, 0, SRCCOPY); ::SelectObject(hdc, hBmp); ::DeleteObject(hBmp); ::DeleteDC(hdc); //CDialogEx::OnPaint(); }
void CFaceSelDlg::OnPaint(CDCHandle dc) { CPaintDC PaintDC(m_hWnd); HDC hDC = PaintDC.m_hDC; CRect rcClient; GetClientRect(&rcClient); HPEN hPen = ::CreatePen(PS_SOLID, 1, RGB(72,121,184)); HBRUSH hBrush = ::CreateSolidBrush(RGB(233,246,254)); HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen); HBRUSH hOldBrush = (HBRUSH)::SelectObject(hDC, hBrush); ::Rectangle(hDC, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); ::SelectObject(hDC, hOldBrush); ::SelectObject(hDC, hOldPen); ::DeleteObject(hPen); ::DeleteObject(hBrush); }
LRESULT FProgress::OnPaint(UINT, WPARAM, LPARAM, BOOL&) { CPaintDC PaintDC(m_hWnd); FRect rcPaint, rcClient; GetClientRect(&rcClient); rcPaint = rcClient; CDC dcCompat; dcCompat.CreateCompatibleDC(PaintDC); CBitmap bmCompat;bmCompat.CreateCompatibleBitmap(PaintDC, rcPaint.Width(), rcPaint.Height()); dcCompat.SelectBitmap(bmCompat); dcCompat.FillRect(&rcPaint, m_BgBrush); dword dwStyle = GetWindowLong(GWL_STYLE); if (dwStyle & PROG_DRAW_EDGE) dcCompat.DrawEdge(&rcPaint, EDGE_ETCHED, BF_RECT | BF_ADJUST); DrawMeter(dcCompat, rcPaint); PaintDC.BitBlt(0, 0, rcClient.Width(), rcClient.Height(), dcCompat, 0, 0, SRCCOPY); return 0; }
BOOL CSkinProgress::ConvertBitmap( CBitmap *pDestBmp, CBitmap *pSrcBmp, CDC *pDC) { BITMAP SrcBmpInfo; BITMAPINFO sBmpInfoSrc; HBITMAP BMPInfo; unsigned char *pDataBmp; DWORD dwDataCount; int nResult; pDataBmp = NULL; if (pDestBmp != NULL && pSrcBmp != NULL) { if (pDC == NULL) { CPaintDC PaintDC(m_hWnd); pDC = &PaintDC; } pSrcBmp->GetBitmap(&SrcBmpInfo); if (SrcBmpInfo.bmBitsPixel == GetDeviceCaps(*pDC, BITSPIXEL)) { nResult = (int) CopyBitmap(pDestBmp, pSrcBmp); }else { dwDataCount = SrcBmpInfo.bmWidthBytes * SrcBmpInfo.bmHeight; pDataBmp = new unsigned char[dwDataCount]; if (pDataBmp != NULL) { pSrcBmp->GetBitmapBits(dwDataCount, pDataBmp); SrcBmpInfo.bmBits = pDataBmp; sBmpInfoSrc.bmiColors[0].rgbBlue = 0; sBmpInfoSrc.bmiColors[0].rgbGreen = 0; sBmpInfoSrc.bmiColors[0].rgbRed = 0; sBmpInfoSrc.bmiColors[0].rgbReserved = 0; sBmpInfoSrc.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); sBmpInfoSrc.bmiHeader.biWidth = SrcBmpInfo.bmWidth; sBmpInfoSrc.bmiHeader.biHeight = 0 - SrcBmpInfo.bmHeight; sBmpInfoSrc.bmiHeader.biPlanes = SrcBmpInfo.bmPlanes; sBmpInfoSrc.bmiHeader.biBitCount = SrcBmpInfo.bmBitsPixel; sBmpInfoSrc.bmiHeader.biCompression = BI_RGB; sBmpInfoSrc.bmiHeader.biSizeImage = 0; sBmpInfoSrc.bmiHeader.biXPelsPerMeter = 0; sBmpInfoSrc.bmiHeader.biYPelsPerMeter = 0; sBmpInfoSrc.bmiHeader.biClrUsed = 0; sBmpInfoSrc.bmiHeader.biClrImportant = 0; BMPInfo = CreateDIBitmap(pDC->m_hDC, &sBmpInfoSrc.bmiHeader, CBM_INIT, pDataBmp, &sBmpInfoSrc, DIB_RGB_COLORS); CBitmap TempBmp(BMPInfo); nResult = (int) CopyBitmap(pDestBmp, &TempBmp); DeleteObject(BMPInfo); delete[] pDataBmp; if (nResult != 0) { return true; } } } } return false; }
BOOL CSkinProgress::SetBitmap( CBitmap *pTempBitmap, BOOL bDisplay) { BITMAP sBmpSrc; HBITMAP hOldBitmap; HBITMAP hOldStretch; CRect WndRect; CDC BmpDC; CDC StretchDC; mPaintRect.SetRect(0, 0, 0, 0); GetClientRect(&WndRect); CPaintDC PaintDC(m_hWnd); if (mpBaseBmp != NULL) delete mpBaseBmp; mpBaseBmp = new CBitmap; if (mpCompatibleBmp != NULL) delete mpCompatibleBmp; mpCompatibleBmp = new CBitmap; if (pTempBitmap == NULL) return FALSE; CopyBitmap(mpBaseBmp, pTempBitmap); ConvertBitmap(mpCompatibleBmp, mpBaseBmp, &PaintDC); mpCompatibleBmp->GetBitmap(&sBmpSrc); mnBmpWidth = sBmpSrc.bmWidth / SKIN_PROGRESS_BITMAP_COUNT; mnBmpHeight = sBmpSrc.bmHeight; if (mpStretchBmp != NULL) delete mpStretchBmp; mpStretchBmp = new CBitmap; mpStretchBmp->CreateCompatibleBitmap(PaintDC, sBmpSrc.bmWidth, WndRect.Height() - 2); BmpDC.CreateCompatibleDC(PaintDC); hOldBitmap = BmpDC.SelectBitmap(*mpCompatibleBmp); StretchDC.CreateCompatibleDC(PaintDC); hOldStretch = StretchDC.SelectBitmap(*mpStretchBmp); StretchDC.SetStretchBltMode(HALFTONE); StretchDC.StretchBlt(0, 0, sBmpSrc.bmWidth, WndRect.Height() - 2, BmpDC, 0, 0, sBmpSrc.bmWidth, sBmpSrc.bmHeight, SRCCOPY); StretchDC.SelectBitmap(hOldStretch); StretchDC.DeleteDC(); BmpDC.SelectBitmap(hOldBitmap); BmpDC.DeleteDC(); mpStretchBmp->GetBitmap(&sBmpSrc); mnBmpWidth = sBmpSrc.bmWidth / SKIN_PROGRESS_BITMAP_COUNT; mnBmpHeight = sBmpSrc.bmHeight; mBarImageList.Destroy(); if(!mBarImageList.Create(mnBmpWidth, mnBmpHeight, ILC_COLOR32, 0, 0)) { return false; }else { mBarImageList.Add(*mpStretchBmp, RGB(0, 255, 255)); if (bDisplay != false) { OnCalcPos(); } return true; } }
void CTextProgressCtrl::OnPaint() { if (m_nMin >= m_nMax) return; CPaintDC PaintDC(this); // device context for painting CMemDC dc(&PaintDC); // memory device context // get colors to use COLORREF crBarColor = (COLORREF)OnGetBarColor(0, 0); COLORREF crBarBkColor = (COLORREF)OnGetBarBkColor(0, 0); COLORREF crTextColor = (COLORREF)OnGetTextColor(0, 0); COLORREF crTextBkColor = (COLORREF)OnGetTextBkColor(0, 0);; // select progress bar font if there is one, else select parent font if (GetFont()) dc.SelectObject(GetFont()); else dc.SelectObject(GetParent()->GetFont()); // draw bar BOOL bLeft = true, bMiddle = true, bRight = true; CRect LeftRect, MiddleRect, RightRect, ClientRect; GetClientRect(&ClientRect); LeftRect = MiddleRect = RightRect = ClientRect; // compute the fractional position double dFraction = (double)(m_nPos - m_nMin) / ((double)(m_nMax - m_nMin)); // get the control style DWORD dwStyle = GetStyle(); // create a vertical font if needed if ((dwStyle & PBS_VERTICAL) && (!m_VerticalFont.m_hObject)) CreateVerticalFont(); if (dwStyle & PBS_MARQUEE) { if (dwStyle & PBS_VERTICAL) { MiddleRect.top = MiddleRect.bottom - (int)((MiddleRect.Height()) * dFraction); MiddleRect.bottom = MiddleRect.top + (((LeftRect.Height() * m_nMarqueeSize) + 50) / 100); if (MiddleRect.bottom >= LeftRect.bottom) { bLeft = false; MiddleRect.bottom = LeftRect.bottom; } else LeftRect.top = MiddleRect.bottom; if (MiddleRect.top <= RightRect.top) { bRight = false; MiddleRect.top = RightRect.top; } else RightRect.bottom = MiddleRect.top; } else { MiddleRect.right = MiddleRect.left + (int)((MiddleRect.Width()) * dFraction); MiddleRect.left = MiddleRect.right - (((LeftRect.Width() * m_nMarqueeSize) + 50) / 100); if (MiddleRect.left <= LeftRect.left) { bLeft = false; MiddleRect.left = LeftRect.left; } else LeftRect.right = MiddleRect.left; if (MiddleRect.right >= RightRect.right) { bRight = false; MiddleRect.right = RightRect.right; } else RightRect.left = MiddleRect.right; } } else { bLeft = false; if (dwStyle & PBS_VERTICAL) { MiddleRect.top = MiddleRect.bottom - (int)((MiddleRect.Height()) * dFraction); RightRect.bottom = MiddleRect.top; } else { MiddleRect.right = MiddleRect.left + (int)((MiddleRect.Width()) * dFraction); RightRect.left = MiddleRect.right; } } if (bLeft) dc.FillSolidRect(LeftRect, crBarBkColor); if (bMiddle) dc.FillSolidRect(MiddleRect, crBarColor); if (bRight) dc.FillSolidRect(RightRect, crBarBkColor); // draw text if needed CString str; GetWindowText(str); if (m_bShowPercent) str.AppendFormat("%d%%", (int)((dFraction * 100.0) + 0.5)); if (str.GetLength()) { CFont *pOldFont = NULL; CPoint ptStart; CSize szText; if (dwStyle & PBS_VERTICAL) { pOldFont = (CFont*)dc.SelectObject(&m_VerticalFont); szText = dc.GetOutputTextExtent(str); switch (m_dwTextStyle) { case DT_LEFT: ptStart.y = ClientRect.bottom - 1 - EDGE_SPACE; break; case DT_RIGHT: ptStart.y = ClientRect.top + szText.cx + EDGE_SPACE; break; case DT_CENTER: default: ptStart.y = ClientRect.top + szText.cx + (ClientRect.Height() - szText.cx) / 2; break; } ptStart.x = ClientRect.left + ((ClientRect.Width() - szText.cy) / 2); } else { szText = dc.GetOutputTextExtent(str); switch (m_dwTextStyle) { case DT_LEFT: ptStart.x = ClientRect.left + EDGE_SPACE; break; case DT_RIGHT: ptStart.x = ClientRect.right - szText.cx - 1 - EDGE_SPACE; break; case DT_CENTER: default: ptStart.x = ClientRect.left + ((ClientRect.Width() - szText.cx) / 2); break; } ptStart.y = ClientRect.top + ((ClientRect.Height() - szText.cy) / 2); } dc.SetBkMode(TRANSPARENT); CRgn rgn; if (bLeft) { rgn.CreateRectRgn(LeftRect.left, LeftRect.top, LeftRect.right, LeftRect.bottom); dc.SelectClipRgn(&rgn); dc.SetTextColor(crTextColor); dc.ExtTextOut(ptStart.x, ptStart.y, ETO_CLIPPED, &ClientRect, str, NULL); rgn.DeleteObject(); } if (bMiddle) { rgn.CreateRectRgn(MiddleRect.left, MiddleRect.top, MiddleRect.right, MiddleRect.bottom); dc.SelectClipRgn(&rgn); dc.SetTextColor(crTextBkColor); dc.ExtTextOut(ptStart.x, ptStart.y, ETO_CLIPPED, &ClientRect, str, NULL); rgn.DeleteObject(); } if (bRight) { rgn.CreateRectRgn(RightRect.left, RightRect.top, RightRect.right, RightRect.bottom); dc.SelectClipRgn(&rgn); dc.SetTextColor(crTextColor); dc.ExtTextOut(ptStart.x, ptStart.y, ETO_CLIPPED, &ClientRect, str, NULL); rgn.DeleteObject(); } if (pOldFont) dc.SelectObject(pOldFont); } }
void CSkinDialog::OnPaint(CDCHandle dc) { CPaintDC PaintDC(m_hWnd); CRect rcClient; GetClientRect(&rcClient); int cx = 0, cy = 0; if (m_hMemBmp != NULL) { BITMAP bmpInfo = {0}; ::GetObject(m_hMemBmp, sizeof(BITMAP), &bmpInfo); cx = bmpInfo.bmWidth; cy = bmpInfo.bmHeight; } if (rcClient.Width() != cx || rcClient.Height() != cy) { if (m_hMemDC != NULL && m_hMemBmp != NULL) { ::SelectObject(m_hMemDC, m_hOldBmp); ::DeleteObject(m_hMemBmp); } m_hMemBmp = ::CreateCompatibleBitmap(PaintDC.m_hDC, rcClient.Width(), rcClient.Height()); m_hOldBmp = (HBITMAP)::SelectObject(m_hMemDC, m_hMemBmp); } CDCHandle MemDC(m_hMemDC); if (m_lpBgImg != NULL && !m_lpBgImg->IsNull()) // 填充背景图片 { m_lpBgImg->Draw2(MemDC.m_hDC, rcClient); } else // 填充背景颜色 { MemDC.FillSolidRect(&rcClient, m_clrBg); } if (m_lpTitleBarBgImg != NULL && !m_lpTitleBarBgImg->IsNull()) // 填充标题栏背景图片 { m_lpTitleBarBgImg->Draw2(MemDC.m_hDC, m_rcTitleBar); } // HPEN hPen = ::CreatePen(PS_SOLID | PS_INSIDEFRAME, 1, RGB(62, 114, 132)); // HPEN hOldPen = MemDC.SelectPen(hPen); // HBRUSH hOldBrush = MemDC.SelectBrush((HBRUSH)::GetStockObject(NULL_BRUSH)); // MemDC.RoundRect(rcClient.left, rcClient.top, // rcClient.right, rcClient.bottom, 4, 4); // MemDC.SelectPen(hOldPen); // MemDC.SelectBrush(hOldBrush); // ::DeleteObject(hPen); if (m_bHasMinBtn) // 绘制最小化按钮 { if (m_bMinBtnPress) { if (m_lpMinSysBtnImgD != NULL && !m_lpMinSysBtnImgD->IsNull()) m_lpMinSysBtnImgD->Draw(MemDC.m_hDC, m_rcMinBtn); } else if(m_bMinBtnHover) { if (m_lpMinSysBtnImgH != NULL && !m_lpMinSysBtnImgH->IsNull()) m_lpMinSysBtnImgH->Draw(MemDC.m_hDC, m_rcMinBtn); } else { if (m_lpMinSysBtnImgN != NULL && !m_lpMinSysBtnImgN->IsNull()) m_lpMinSysBtnImgN->Draw(MemDC.m_hDC, m_rcMinBtn); } } if (m_bHasMaxBtn) // 绘制最大化按钮 { if (IsZoomed()) // 窗口最大化标志 { if (m_bMaxBtnPress) { if (m_lpRestoreSysBtnImgD != NULL && !m_lpRestoreSysBtnImgD->IsNull()) m_lpRestoreSysBtnImgD->Draw(MemDC.m_hDC, m_rcMaxBtn); } else if(m_bMaxBtnHover) { if (m_lpRestoreSysBtnImgH != NULL && !m_lpRestoreSysBtnImgH->IsNull()) m_lpRestoreSysBtnImgH->Draw(MemDC.m_hDC, m_rcMaxBtn); } else { if (m_lpRestoreSysBtnImgN != NULL && !m_lpRestoreSysBtnImgN->IsNull()) m_lpRestoreSysBtnImgN->Draw(MemDC.m_hDC, m_rcMaxBtn); } } else { if (m_bMaxBtnPress) { if (m_lpMaxSysBtnImgD != NULL && !m_lpMaxSysBtnImgD->IsNull()) m_lpMaxSysBtnImgD->Draw(MemDC.m_hDC, m_rcMaxBtn); } else if(m_bMaxBtnHover) { if (m_lpMaxSysBtnImgH != NULL && !m_lpMaxSysBtnImgH->IsNull()) m_lpMaxSysBtnImgH->Draw(MemDC.m_hDC, m_rcMaxBtn); } else { if (m_lpMaxSysBtnImgN != NULL && !m_lpMaxSysBtnImgN->IsNull()) m_lpMaxSysBtnImgN->Draw(MemDC.m_hDC, m_rcMaxBtn); } } } if (m_bHasCloseBtn) // 绘制关闭按钮 { if (m_bCloseBtnPress) { if (m_lpCloseSysBtnImgD != NULL && !m_lpCloseSysBtnImgD->IsNull()) m_lpCloseSysBtnImgD->Draw(MemDC.m_hDC, m_rcCloseBtn); } else if(m_bCloseBtnHover) { if (m_lpCloseSysBtnImgH != NULL && !m_lpCloseSysBtnImgH->IsNull()) m_lpCloseSysBtnImgH->Draw(MemDC.m_hDC, m_rcCloseBtn); } else { if (m_lpCloseSysBtnImgN != NULL && !m_lpCloseSysBtnImgN->IsNull()) m_lpCloseSysBtnImgN->Draw(MemDC.m_hDC, m_rcCloseBtn); } } int nTitleTextLen = m_strTitleText.GetLength(); if (nTitleTextLen > 0) { //DrawEclosionText(MemDC.m_hDC, m_strTitleText, _T("微软雅黑"), 12); CRect rcText(m_rcTitleBar); rcText.left += 8; NONCLIENTMETRICS nif; //创建标题栏字体对象 nif.cbSize = sizeof(nif); ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &nif, 0); HFONT hFont = ::CreateFontIndirect(&nif.lfSmCaptionFont); int nMode = ::SetBkMode(MemDC.m_hDC, TRANSPARENT); HFONT hOldFont = (HFONT)::SelectObject(MemDC.m_hDC, hFont); ::DrawText(MemDC.m_hDC, m_strTitleText, nTitleTextLen, &rcText, DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_END_ELLIPSIS); ::SelectObject(MemDC.m_hDC, hOldFont); ::SetBkMode(MemDC.m_hDC, nMode); ::DeleteObject(hFont); } ::BitBlt(PaintDC.m_hDC, 0, 0, rcClient.Width(), rcClient.Height(), m_hMemDC, 0, 0, SRCCOPY); }
void CSkinHyperLink::OnPaint(CDCHandle dc) { CPaintDC PaintDC(m_hWnd); Draw(PaintDC.m_hDC); }
void CSkinPictureBox::OnPaint(CDCHandle dc) { CPaintDC PaintDC(m_hWnd); CRect rcClient; GetClientRect(&rcClient); CMemoryDC MemDC(PaintDC.m_hDC, rcClient); if (m_bTransparent) DrawParentWndBg(MemDC.m_hDC); int nMode = ::SetStretchBltMode(MemDC.m_hDC, HALFTONE); if (m_lpImage != NULL && !m_lpImage->IsNull()) { if (DRAW_MODE_CENTER == m_nDrawMode) { int cx = m_lpImage->GetWidth(); int cy = m_lpImage->GetHeight(); CRect rcCenter; CalcCenterRect(rcClient, cx, cy, rcCenter); m_lpImage->Draw(MemDC.m_hDC, rcCenter); } else if (DRAW_MODE_STRETCH == m_nDrawMode) { m_lpImage->Draw(MemDC.m_hDC, rcClient); } } else if (m_lpGifImage != NULL) { if (DRAW_MODE_CENTER == m_nDrawMode) { int cx = m_lpGifImage->GetWidth(); int cy = m_lpGifImage->GetHeight(); CRect rcCenter; CalcCenterRect(rcClient, cx, cy, rcCenter); m_lpGifImage->Draw(MemDC.m_hDC, rcCenter); } else if (DRAW_MODE_STRETCH == m_nDrawMode) { m_lpGifImage->Draw(MemDC.m_hDC, rcClient); } } ::SetStretchBltMode(MemDC.m_hDC, nMode); if (m_bPress) // 鼠标左键按下状态 { if (m_lpBgImgD != NULL && !m_lpBgImgD->IsNull()) m_lpBgImgD->Draw(MemDC.m_hDC, rcClient); } else if (m_bHover) // 鼠标悬停状态 { if (m_lpBgImgH != NULL && !m_lpBgImgH->IsNull()) m_lpBgImgH->Draw(MemDC.m_hDC, rcClient); } else // 普通状态 { if (m_lpBgImgN != NULL && !m_lpBgImgN->IsNull()) m_lpBgImgN->Draw(MemDC.m_hDC, rcClient); } }
void CTextProgressCtrl::OnPaint() { if (m_nMin >= m_nMax) return; COLORREF crBarColour, crBgColour; crBarColour = (m_crBarClr == CLR_DEFAULT)? ::GetSysColor(COLOR_HIGHLIGHT) : m_crBarClr; crBgColour = (m_crBgClr == CLR_DEFAULT)? ::GetSysColor(COLOR_WINDOW) : m_crBgClr; CRect LeftRect, RightRect, ClientRect; GetClientRect(ClientRect); double Fraction = (double)(m_nPos - m_nMin) / ((double)(m_nMax - m_nMin)); CPaintDC PaintDC(this); // device context for painting CMemDC dc(&PaintDC); //CPaintDC dc(this); // device context for painting (if not double buffering) dc.SelectObject(GetParent()->GetFont()); // pja July 1, 2001 // Draw Bar LeftRect = RightRect = ClientRect; #ifdef PBS_VERTICAL DWORD dwStyle = GetStyle(); if (dwStyle & PBS_VERTICAL) { LeftRect.top = LeftRect.bottom - (int)((LeftRect.bottom - LeftRect.top)*Fraction); RightRect.bottom = LeftRect.top; } else #endif { LeftRect.right = LeftRect.left + (int)((LeftRect.right - LeftRect.left)*Fraction); RightRect.left = LeftRect.right; } dc.FillSolidRect(LeftRect, crBarColour); dc.FillSolidRect(RightRect, crBgColour); // Draw Text if not vertical if (m_bShowText #ifdef PBS_VERTICAL && (dwStyle & PBS_VERTICAL) == 0 #endif ) { CString str; if (m_strText.GetLength()) str = m_strText; else str.Format("%d%%", (int)(Fraction*100.0)); dc.SetBkMode(TRANSPARENT); DWORD dwTextStyle = DT_CENTER | DT_VCENTER | DT_SINGLELINE; // If we are drawing vertical, then create a new verticla font // based on the current font (only works with TrueType fonts) CFont font, *pOldFont = NULL; #ifdef PBS_VERTICAL if (dwStyle & PBS_VERTICAL) { LOGFONT lf; GetFont()->GetLogFont(&lf); lf.lfEscapement = lf.lfOrientation = 900; font.CreateFontIndirect(&lf); pOldFont = (CFont*) dc.SelectObject(&font); dwTextStyle = DT_VCENTER|DT_CENTER|DT_SINGLELINE; } #endif CRgn rgn; rgn.CreateRectRgn(LeftRect.left, LeftRect.top, LeftRect.right, LeftRect.bottom); dc.SelectClipRgn(&rgn); dc.SetTextColor(m_crTextClr == CLR_DEFAULT ? crBgColour : m_crTextClr); dc.DrawText(str, ClientRect, dwTextStyle); rgn.DeleteObject(); rgn.CreateRectRgn(RightRect.left, RightRect.top, RightRect.right, RightRect.bottom); dc.SelectClipRgn(&rgn); dc.SetTextColor(m_crTextClr == CLR_DEFAULT ? crBarColour : m_crTextClr); dc.DrawText(str, ClientRect, dwTextStyle); if (pOldFont) { dc.SelectObject(pOldFont); font.DeleteObject(); } } }
int CSkinProgress::CompactText( ATL::CString *psString, CDC *pDC, int nMaxWidth, int nAddWidth) { int nLenString; int nLenDots; int nCountChar; TCHAR nFirstChar; if (psString != NULL) { if (pDC == NULL) { CPaintDC PaintDC(m_hWnd); pDC = &PaintDC; } nLenString = psString->GetLength(); if (psString->Right(3) == "...") { nLenString -= 3; *psString = psString->Left(nLenString); } CSize TextSize; pDC->GetTextExtent(*psString, nLenString, &TextSize); if ((nLenString == 0) || ((TextSize.cx + nAddWidth) <= nMaxWidth)) { return 0; }else { nFirstChar = psString->GetAt(0); pDC->GetTextExtent(gsThreeDots, (sizeof(gsThreeDots) / sizeof(WCHAR)) - 1, &TextSize); nLenDots = TextSize.cx; pDC->GetTextExtent(*psString, nLenString, &TextSize); CSize TextSize2; pDC->GetTextExtent(&nFirstChar, sizeof(nFirstChar), &TextSize2); if (TextSize.cx <= TextSize2.cx + nLenDots) { return (0 - nLenString); }else { nCountChar = 0; pDC->GetTextExtent(*psString, nLenString, &TextSize); while ( (nLenString > 1) && ( (TextSize.cx + (nLenDots >> 1) + nAddWidth) > nMaxWidth) ) { *psString = psString->Left(psString->GetLength() - 1); psString->TrimRight(); nLenString = psString->GetLength(); nCountChar += 1; } *psString += gsThreeDots; return nCountChar; } } }else { return 0;
void ECommentPane::OnPaint() { CRect cr; GetClientRect(&cr); CPaintDC PaintDC(this); CDC* pDC = &PaintDC; // // // //---------------- // flicker //---------------- CDC* pParsedDC = pDC; CDC MemDC; CBitmap MemBM; MemBM.CreateCompatibleBitmap(pParsedDC,cr.Width(),cr.Height()); MemDC.CreateCompatibleDC(pParsedDC); MemDC.SelectObject(&MemBM); pDC = &MemDC; //---------------- CRect r = cr; CFont f; pDC->SetBkColor(RGB(255,255,255)); CRect rlef = r; CRect rrig = r; rlef.right = 17; rrig.left = rlef.right; pDC->FillSolidRect( r , ::GetSysColor(COLOR_3DFACE )); m_pPropWnd->DrawFrame( pDC , r , true , m_pPropWnd->GetColorPaneKey() ); rrig.DeflateRect(2,2); r.DeflateRect(5,3); CRect TextAreaRect = r; // // // CString sTitle = "-"; CString sNoComments = "-"; // // // int nWeight = FW_MEDIUM; //m_bMinimized ? FW_BOLD : FW_MEDIUM; f.CreateFont(13,0,0,0,nWeight,0,0,0,0,0,0,0,0,"tahoma"); pDC->SelectObject(&f); if( m_pCommentHost!=NULL ) { CString sName; CString s = m_pCommentHost->GetCurrentComment( sName ); UINT nFlags = DT_LEFT | DT_WORDBREAK; if( s.GetLength()==0 ) { s = sNoComments; nFlags = DT_SINGLELINE | DT_CENTER | DT_VCENTER; } else { while( true ) { CRect TrimmedTextRect = TextAreaRect; pDC->DrawText( s , TrimmedTextRect , DT_WORDBREAK | DT_CALCRECT ); if( TrimmedTextRect.Height() <= TextAreaRect.Height() ) { break; } if( s.GetLength() <= 4 ) { s = "..."; break; } s = s.Left( s.GetLength()-4 ); s += "..."; } } pDC->DrawText( s , TextAreaRect , nFlags ); } //-------------------------- // flicker //-------------------------- MemDC.SetViewportOrg(0,0); pParsedDC->BitBlt( 0 , 0 , cr.Width() , cr.Height() , &MemDC , 0 , 0 , SRCCOPY ); //-------------------------- }
void CTextProgressCtrl::OnPaint() { if (m_nMin >= m_nMax) return; CRect LeftRect, RightRect, ClientRect; GetClientRect(ClientRect); double Fraction = (double)(m_nPos - m_nMin) / ((double)(m_nMax - m_nMin)); CPaintDC PaintDC(this); // device context for painting CMemDC dc(&PaintDC); //CPaintDC dc(this); // device context for painting (if not double buffering) LeftRect = RightRect = ClientRect; LeftRect.right = LeftRect.left + (int)((LeftRect.right - LeftRect.left)*Fraction); dc.FillSolidRect(LeftRect, m_colFore); RightRect.left = LeftRect.right; dc.FillSolidRect(RightRect, m_colBk); if (m_bShowText) { CString str; CFont font; VERIFY(font.CreateFont( m_fontSize, // nHeight 0, // nWidth 0, // nEscapement 0, // nOrientation FW_NORMAL, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision PROOF_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily _T("Arial"))); // lpszFacename CFont* def_font = dc.SelectObject(&font); if (m_showMyText==false) { if (m_strText.GetLength()) str = m_strText; else str.Format(_T("%d%%"), (int)(Fraction*100.0)); } else { str=m_myText; } dc.SetBkMode(TRANSPARENT); CRgn rgn; rgn.CreateRectRgn(LeftRect.left, LeftRect.top, LeftRect.right, LeftRect.bottom); dc.SelectClipRgn(&rgn); dc.SetTextColor(m_colTextBk); dc.DrawText(str, ClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); rgn.DeleteObject(); rgn.CreateRectRgn(RightRect.left, RightRect.top, RightRect.right, RightRect.bottom); dc.SelectClipRgn(&rgn); dc.SetTextColor(m_colTextFore); dc.DrawText(str, ClientRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE); dc.SelectObject(def_font); } }