VOID DUI_ImageButton::Draw(DUI_Status s) { m_MemDC->Clear(); if (m_bVisialbe) { if (s == S_Invalid) { s = m_CurState; } Image* pImg; if (m_StatusImage[0] == nullptr) { pImg = m_StatusImage[s]; //ASSERT(pImg != nullptr); m_MemDC->graphics->DrawImage(pImg, 0, 0); } else { pImg = m_StatusImage[0]; if (s == S_Focus || s == S_Disabled) { s = S_Normal; } m_MemDC->graphics->DrawImage(pImg, RectF(0.0, 0.0, m_Rect->Width, m_Rect->Height), m_Start + (s - 1)*m_Rect->Width, 0.0, m_Rect->Width, m_Rect->Height, UnitPixel); } if (m_Text != nullptr) { SolidBrush TextBrush(*m_Text->color); INT offset = (m_bMouseDown) ? 1 : 0; m_MemDC->graphics->DrawString(m_Text->string->GetString(), m_Text->string->GetLength(), m_Text->font, RectF(m_Text->rect->X + offset, m_Text->rect->Y + offset, m_Text->rect->Width, m_Text->rect->Height), m_Text->format, &TextBrush); } DUI_ControlBase::Draw(); } return VOID(); }
void CDrawWarn::Draw(CDC* pDC) { ASSERT_VALID(this); CRect rect = m_position; rect.NormalizeRect(); if(rect.Width() < 10 || rect.Height()<10) return; Rect GdiRect (rect.TopLeft().x,rect.TopLeft().y,rect.Size().cx,rect.Size().cy); Color crBackColor,crTitleColor,crLineColor,crTextColor ; crBackColor.SetFromCOLORREF(m_ctlBackColor); crTitleColor.SetFromCOLORREF(m_ctlTitleColor ); crLineColor.SetFromCOLORREF(m_ctlLineColor); crTextColor.SetFromCOLORREF(m_ctlTextColor); Graphics graphics (pDC->m_hDC); graphics.SetSmoothingMode (SmoothingModeHighSpeed); Graphics Textgraphics (pDC->m_hDC); SolidBrush solidBrush(crBackColor); SolidBrush TitleBrush(crTitleColor); SolidBrush TextBrush(crTextColor); Pen pen(crLineColor,1); graphics.FillRectangle(&solidBrush,GdiRect); BSTR bstr = m_fontName.AllocSysString(); /// BSTR bstr = _com_util::ConvertStringToBSTR(m_fontName); FontFamily fontFamily(bstr); SysFreeString(bstr); Font font(&fontFamily, m_fontSize, m_fontStyle, UnitPoint); for(int j =1; j<= m_nColCount; j++) { m_nCellWidth = 0; for(int i=1; i<= m_nRowCount; i++) { CRect rc = rect; if(m_bIsAutoSize) { m_nCellWidth = rect.Width()/m_nRowCount; m_nCellHeight = rect.Height()/m_nColCount; rc.TopLeft().x += (i-1)*m_nCellWidth; rc.TopLeft().y += (j-1)*m_nCellHeight; m_CellRect = CRect(rc.TopLeft(),CSize(m_nCellWidth,m_nCellHeight)); m_CellRect.NormalizeRect(); } else { rc.TopLeft().x += m_nCellWidth; m_nCellWidth += rect.Width()*m_nPercent[i-1]/100; m_nCellHeight = rect.Height()/m_nColCount; rc.TopLeft().y += (j-1)*m_nCellHeight; m_CellRect = CRect(rc.TopLeft(),CSize(rect.Width()*m_nPercent[i-1]/100,m_nCellHeight)); m_CellRect.NormalizeRect(); } Rect CellRect(m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); graphics.DrawRectangle(&pen,CellRect); if(j == m_nColCount) //画标题 { StringFormat stringFormat; stringFormat.SetAlignment(StringAlignmentCenter); stringFormat.SetLineAlignment(StringAlignmentCenter); stringFormat.SetFormatFlags(StringFormatFlagsDirectionRightToLeft); stringFormat.SetTrimming(m_trimmingSyle); CString m_strButton; if(i == 1) m_strButton = "点号"; if(i == 2) m_strButton = "数据"; if(i == 3) m_strButton = "说明"; if(i == 4) m_strButton = "报警原因"; if(i == 5) m_strButton = "时间"; m_strButton.TrimRight(); bstr = m_strButton.AllocSysString(); /// bstr = _com_util::ConvertStringToBSTR(m_strButton); RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); Matrix matrix(1,0,0,-1,0,0); Textgraphics.SetTransform(&matrix); theRect.Y *=-1; theRect.Height*=-1; Normallize (theRect); Textgraphics.FillRectangle(&TitleBrush,theRect); Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush); SysFreeString(bstr); } else { //画文字 m_CStrWarn pStrWarn StringFormat stringFormat; stringFormat.SetAlignment(StringAlignmentNear); stringFormat.SetLineAlignment(StringAlignmentNear); CString strWarn; /* if(i == 1) strWarn = m_CStrWarn[j].strPoint; if(i == 2) strWarn = m_CStrWarn[j].strDate; if(i == 3) strWarn = m_CStrWarn[j].strTime; if(i == 4) strWarn = m_CStrWarn[j].strText; if(i == 5) strWarn = m_CStrWarn[j].strWarn; */ strWarn.TrimRight(); bstr = strWarn.AllocSysString(); /// bstr = _com_util::ConvertStringToBSTR(strWarn); RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); Matrix matrix(1,0,0,-1,0,0); Textgraphics.SetTransform(&matrix); theRect.Y *=-1; theRect.Height*=-1; Normallize (theRect); Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush); SysFreeString(bstr); } } } graphics.ReleaseHDC(pDC->m_hDC); }
void CDrawWarn::Draw(CDC* pDC) { ASSERT_VALID(this); CRect rect = m_position; rect.NormalizeRect(); if(rect.Width() < 10 || rect.Height()<10) return; pStrWarn = new STRWARN[m_nColCount]; AddWarn("1","2004/12/12","12:00","高报警","电压过低"); AddWarn("2","2004/12/12","12:00","高报警","电压过低"); AddWarn("3","2004/12/12","12:00","高报警","电压过低"); AddWarn("4","2004/12/12","12:00","高报警","电压过低"); AddWarn("5","2004/12/12","12:00","高报警","电压过低"); AddWarn("6","2004/12/12","12:00","高报警","电压过低"); AddWarn("7","2004/12/12","12:00","高报警","电压过低"); AddWarn("8","2004/12/12","12:00","高报警","电压过低"); AddWarn("9","2004/12/12","12:00","高报警","电压过低"); AddWarn("10","2004/12/12","12:00","高报警","电压过低"); AddWarn("11","2004/12/12","12:00","高报警","电压过低"); AddWarn("12","2004/12/12","12:00","高报警","电压过低"); Rect GdiRect (rect.TopLeft().x,rect.TopLeft().y,rect.Size().cx,rect.Size().cy); Color crBackColor,crTitleColor,crLineColor,crTextColor ; crBackColor.SetFromCOLORREF(m_ctlBackColor); crTitleColor.SetFromCOLORREF(m_ctlTitleColor ); crLineColor.SetFromCOLORREF(m_ctlLineColor); crTextColor.SetFromCOLORREF(m_ctlTextColor); Graphics graphics (pDC->m_hDC); Graphics Textgraphics (pDC->m_hDC); SolidBrush solidBrush(crBackColor); SolidBrush TitleBrush(crTitleColor); SolidBrush TextBrush(crTextColor); Pen pen(crLineColor,1); graphics.FillRectangle(&solidBrush,GdiRect); BSTR bstr = _com_util::ConvertStringToBSTR(m_fontName); /// WCHAR *fn = new unsigned short[m_fontName.GetLength()+1];; /// wcscpy(fn,bstr); FontFamily fontFamily(bstr); Font font(&fontFamily, m_fontSize, m_fontStyle, UnitPoint); for(int j =1; j<= m_nColCount; j++) { m_nCellWidth = 0; for(int i=1; i<= m_nRowCount; i++) { CRect rc = rect; if(m_bIsAutoSize) { m_nCellWidth = rect.Width()/m_nRowCount; m_nCellHeight = rect.Height()/m_nColCount; rc.TopLeft().x += (i-1)*m_nCellWidth; rc.TopLeft().y += (j-1)*m_nCellHeight; m_CellRect = CRect(rc.TopLeft(),CSize(m_nCellWidth,m_nCellHeight)); m_CellRect.NormalizeRect(); } else { rc.TopLeft().x += m_nCellWidth; m_nCellWidth += rect.Width()*m_nPercent[i-1]/100; m_nCellHeight = rect.Height()/m_nColCount; rc.TopLeft().y += (j-1)*m_nCellHeight; m_CellRect = CRect(rc.TopLeft(),CSize(rect.Width()*m_nPercent[i-1]/100,m_nCellHeight)); m_CellRect.NormalizeRect(); } Rect CellRect(m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); graphics.DrawRectangle(&pen,CellRect); if(j == m_nColCount) //画标题 { StringFormat stringFormat; stringFormat.SetAlignment(StringAlignmentCenter); stringFormat.SetLineAlignment(StringAlignmentCenter); stringFormat.SetFormatFlags(StringFormatFlagsDirectionRightToLeft); stringFormat.SetTrimming(m_trimmingSyle); CString m_strButton; if(i == 1) m_strButton = "点号"; if(i == 2) m_strButton = "数据"; if(i == 3) m_strButton = "说明"; if(i == 4) m_strButton = "报警原因"; if(i == 5) m_strButton = "时间"; m_strButton.TrimRight(); /// int len = m_strButton.GetLength(); bstr = _com_util::ConvertStringToBSTR(m_strButton); /// WCHAR *strButton = new unsigned short[len]; /// wcscpy(strButton,bstr); RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); Matrix matrix(1,0,0,-1,0,0); Textgraphics.SetTransform(&matrix); theRect.Y *=-1; theRect.Height*=-1; Normallize (theRect); Textgraphics.FillRectangle(&TitleBrush,theRect); Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush); } else //画文字 { StringFormat stringFormat; stringFormat.SetAlignment(StringAlignmentNear); stringFormat.SetLineAlignment(StringAlignmentNear); CString strWarn; if(i == 1) strWarn = pStrWarn[j].strPoint; if(i == 2) strWarn = pStrWarn[j].strDate; if(i == 3) strWarn = pStrWarn[j].strTime; if(i == 4) strWarn = pStrWarn[j].strText; if(i == 5) strWarn = pStrWarn[j].strWarn; strWarn.TrimRight(); /// int len = strWarn.GetLength(); bstr = _com_util::ConvertStringToBSTR(strWarn); /// WCHAR *strButton = new unsigned short[len]; /// wcscpy(strButton,bstr); RectF theRect (m_CellRect.TopLeft().x,m_CellRect.TopLeft().y,m_CellRect.Size().cx,m_CellRect.Size().cy); Matrix matrix(1,0,0,-1,0,0); Textgraphics.SetTransform(&matrix); theRect.Y *=-1; theRect.Height*=-1; Normallize (theRect); Textgraphics.DrawString(bstr,-1,&font, theRect,&stringFormat, &TextBrush); } } } graphics.ReleaseHDC(pDC->m_hDC); }