void CMyLabel::OnPaint() { CPaintDC dc(this); // device context for painting DWORD dwFlags = DT_LEFT | DT_WORDBREAK; CRect rc; GetClientRect(rc); CString strText; GetWindowText(strText); CBitmap bmp; CDC* pDCMem; CBitmap* pOldBitmap = NULL; pDCMem = new CDC; pDCMem->CreateCompatibleDC(&dc); bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height()); pOldBitmap = pDCMem->SelectObject(&bmp); UINT nMode = pDCMem->SetBkMode(TRANSPARENT); COLORREF crText; if (IsWindowEnabled()) { crText = pDCMem->SetTextColor(m_textColor); } else { crText = pDCMem->SetTextColor(GetSysColor(COLOR_GRAYTEXT)); } CFont *pOldFont = pDCMem->SelectObject(&m_font); CBrush br; br.Attach(m_brush); pDCMem->FillRect(rc,&br); br.Detach(); pDCMem->DrawText(strText,rc,dwFlags); // Restore DC's State pDCMem->SetBkMode(nMode); pDCMem->SelectObject(pOldFont); pDCMem->SetTextColor(crText); dc.BitBlt(0,0,rc.Width(),rc.Height(),pDCMem,0,0,SRCCOPY); // continue DC restore pDCMem->SelectObject ( pOldBitmap ) ; delete pDCMem; }
void CLabel::OnPaint() { CPaintDC dc(this); // device context for painting DWORD dwFlags = 0; CRect rc; GetClientRect(rc); CString strText; GetWindowText(strText); CBitmap bmp; /////////////////////////////////////////////////////// // // Set up for double buffering... // CDC* pDCMem; CBitmap* pOldBitmap = NULL; if (!m_bTransparent) { pDCMem = new CDC; pDCMem->CreateCompatibleDC(&dc); bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height()); pOldBitmap = pDCMem->SelectObject(&bmp); } else { pDCMem = &dc; } UINT nMode = pDCMem->SetBkMode(TRANSPARENT); COLORREF crText = pDCMem->SetTextColor(m_crText); CFont *pOldFont = pDCMem->SelectObject(&m_font); // Fill in backgound if not transparent if (!m_bTransparent) { if (m_fillmode == Normal) { CBrush br; if (m_hBackBrush != NULL) br.Attach(m_hBackBrush); else br.Attach(m_hwndBrush); pDCMem->FillRect(rc,&br); br.Detach(); } else // Gradient Fill { DrawGradientFill(pDCMem, &rc, m_crLoColor, m_crHiColor, 100); } } // If the text is flashing turn the text color on // then to the color of the window background. LOGBRUSH lb; ZeroMemory(&lb,sizeof(lb)); // Stop Checking complaining if (m_hBackBrush) ::GetObject(m_hBackBrush,sizeof(lb),&lb); // Something to do with flashing if (!m_bState && m_Type == Text) pDCMem->SetTextColor(lb.lbColor); DWORD style = GetStyle(); switch (style & SS_TYPEMASK) { case SS_RIGHT: dwFlags = DT_RIGHT | DT_WORDBREAK; break; case SS_CENTER: dwFlags = SS_CENTER | DT_WORDBREAK; break; case SS_LEFTNOWORDWRAP: dwFlags = DT_LEFT; break; default: // treat other types as left case SS_LEFT: dwFlags = DT_LEFT | DT_WORDBREAK; break; } // Added to expand tabs... if(strText.Find(_T('\t')) != -1) dwFlags |= DT_EXPANDTABS; // If the text centered make an assumtion that // the will want to center verticly as well if (style & SS_CENTERIMAGE) { dwFlags = DT_CENTER; // Apply if (strText.Find(_T("\r\n")) == -1) { dwFlags |= DT_VCENTER; // And because DT_VCENTER only works with single lines dwFlags |= DT_SINGLELINE; } } // // 3333 DDDDD // 3 D D // 33 D D E F X // 3 D D // 3333 DDDDD // // if (m_bRotation) { int nAlign = pDCMem->SetTextAlign (TA_BASELINE); CPoint pt; GetViewportOrgEx (pDCMem->m_hDC,&pt) ; SetViewportOrgEx (pDCMem->m_hDC,rc.Width() / 2, rc.Height() / 2, NULL) ; pDCMem->TextOut (0, 0, strText) ; SetViewportOrgEx (pDCMem->m_hDC,pt.x / 2, pt.y / 2, NULL) ; pDCMem->SetTextAlign (nAlign); } else { pDCMem->DrawText(strText,rc,dwFlags); if (m_bFont3d) { pDCMem->SetTextColor(m_cr3DHiliteColor); if (m_3dType == Raised) rc.OffsetRect(-1,-1); else rc.OffsetRect(1,1); pDCMem->DrawText(strText,rc,dwFlags); m_3dType; } } // Restore DC's State pDCMem->SetBkMode(nMode); pDCMem->SelectObject(pOldFont); pDCMem->SetTextColor(crText); if (!m_bTransparent) { dc.BitBlt(0,0,rc.Width(),rc.Height(),pDCMem,0,0,SRCCOPY); // continue DC restore pDCMem->SelectObject ( pOldBitmap ) ; delete pDCMem; } }
void FeatureDistribution::OnPaint() { // TODO: Add your message handler code here // Do not call CStatic::OnPaint() for painting messages CPaintDC dc(this); // device context-ul pentru afisare RECT rectf; GetClientRect(&rectf); CBrush brush; brush.Attach(GetStockObject(LTGRAY_BRUSH)); dc.FillRect(&rectf, &brush); brush.Detach(); CPen pen(PS_SOLID, 1, RGB(255,0,0)); // definirea pen-ului de desenare cu culoare rosie CPen *pTempPen=dc.SelectObject(&pen); // selectarea pen-ului de afisare CRect rect; GetClientRect(rect); // obtine zona de afisare dreptunghiulara disponibila int height=rect.Height(); // inaltimea zonei de afisare int width=rect.Width(); // latimea zonei de afisare int upperOffset = 10; // se determina maximul sirului values[256] int i; int maxV=0; for (i=0;i<nbValues;i++) if (pdf[i]>maxV) maxV=pdf[i]; // se verifica daca este nevoie de scalare double scaleFactor=1.0; int heightOffset = 20; // facem intotdeauna scalarea; astfel incat la maxValue sa corespunda height; scaleFactor=(double)(height-heightOffset)/maxV; int intervalDim = width/(this->nbValues)-1; //find the dimension of an interval, and draw rectangles not lines; // se afiseaza pdf (eventual scalata) ca niste bare verticale for (i=0;i<nbValues;i++) { // determinarea lungimii liniei int lengthLine=(int)(scaleFactor*pdf[i]); for (int j = i*intervalDim+2; j < i*intervalDim+intervalDim-1; j++) { //afisarea dreptunghiului dc.MoveTo(j,height-heightOffset); dc.LineTo(j,height-heightOffset-lengthLine); } } dc.SelectObject(pTempPen); // restaurarea pen-ului de afisare #if 0 CPen pen2(PS_SOLID, 1, RGB(5,0,0)); // definirea pen-ului de desenare cu culoare rosie CPen *pTempPen2=dc.SelectObject(&pen2); // selectarea pen-ului de afisare dc.MoveTo(0, height-heightOffset); dc.LineTo(nbValues*intervalDim, height-heightOffset); dc.MoveTo(0, height-heightOffset); dc.LineTo(0, 0); CPoint pos ; int intervalDimReal = (maxValue - minValue)/nbValues; CString msg; for (i = 0; i < nbValues; i++) { pos.x = (i+1)*intervalDim - 3*intervalDim/4; pos.y = height - heightOffset; msg.Format("%d",(i+1)*intervalDimReal/2); dc.TextOut(pos.x, pos.y, msg); dc.MoveTo(0, height-heightOffset); dc.LineTo(nbValues*intervalDim, height-heightOffset); } dc.SelectObject(pTempPen2); // restaurarea pen-ului de afisare #endif }