本文整理汇总了C++中StringFormat::SetLineAlignment方法的典型用法代码示例。如果您正苦于以下问题:C++ StringFormat::SetLineAlignment方法的具体用法?C++ StringFormat::SetLineAlignment怎么用?C++ StringFormat::SetLineAlignment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringFormat
的用法示例。
在下文中一共展示了StringFormat::SetLineAlignment方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DrawControl
void CDuiListCtrl::DrawControl(CDC &dc, CRect rcUpdate)
{
// 列表画图方法:
// 1.列表的虚拟高度为每一行高度*行数
// 2.列表显示的top坐标由scroll控件记录
// 3.重画时候,根据top坐标位置计算出显示的第一行的序号,根据显示高度计算出显示的最后一行的序号
// 4.根据计算出的显示的行,画相应的内容到内存dc中
// 5.计算出显示的top坐标进行内存dc的拷贝
int nWidth = m_rc.Width() - m_nScrollWidth; // 减去滚动条的宽度
int nHeightAll = (int)m_vecRowInfo.size()*m_nRowHeight; // 总的虚拟高度 //m_rc.Height();
CScrollV* pScrollV = (CScrollV*)m_pControScrollV;
int nCurPos = pScrollV->GetScrollCurrentPos(); // 当前top位置
int nMaxRange = pScrollV->GetScrollMaxRange();
m_nVirtualTop = (nMaxRange > 0) ? nCurPos*(nHeightAll-m_rc.Height())/nMaxRange : 0; // 当前滚动条位置对应的虚拟的top位置
if(m_nVirtualTop < 0)
{
m_nVirtualTop = 0;
pScrollV->SetScrollCurrentPos(0);
}
m_nFirstViewRow = m_nVirtualTop / m_nRowHeight; // 显示的第一行序号
m_nLastViewRow = (m_nVirtualTop + m_rc.Height()) / m_nRowHeight; // 显示的最后一行序号
if(m_nLastViewRow >= (int)m_vecRowInfo.size())
{
m_nLastViewRow = (int)m_vecRowInfo.size() - 1;
}
if(m_nLastViewRow < 0)
{
m_nLastViewRow = 0;
}
int nHeightView = (m_nLastViewRow - m_nFirstViewRow +1) * m_nRowHeight; // 显示涉及到的虚拟高度
int nYViewPos = m_nVirtualTop - (m_nFirstViewRow * m_nRowHeight); // 内存dc显示到屏幕时候的top位置
if(nYViewPos < 0)
{
nYViewPos = 0;
}
if(!m_bUpdate)
{
UpdateMemDC(dc, nWidth, nHeightView);
Graphics graphics(m_memDC);
m_memDC.BitBlt(0, 0, nWidth, nHeightView, &dc, m_rc.left ,m_rc.top, WHITENESS); // 画白色背景
DrawVerticalTransition(m_memDC, dc, CRect(0, nYViewPos, nWidth, m_rc.Height()+nYViewPos), // 背景透明度
m_rc, m_nBkTransparent, m_nBkTransparent);
BSTR bsFontTitle = m_strFontTitle.AllocSysString();
FontFamily fontFamilyTitle(bsFontTitle);
Font fontTitle(&fontFamilyTitle, (REAL)m_nFontTitleWidth, m_fontTitleStyle, UnitPixel);
::SysFreeString(bsFontTitle);
BSTR bsFont = m_strFont.AllocSysString();
FontFamily fontFamily(bsFont);
Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
::SysFreeString(bsFont);
SolidBrush solidBrush(m_clrText); // 正常文字画刷
SolidBrush solidBrushH(m_clrTextHover); // 热点文字画刷
SolidBrush solidBrushD(m_clrTextDown); // 当前行画刷
SolidBrush solidBrushT(m_clrTitle); // 标题文字画刷
SolidBrush solidBrushS(m_clrSeperator); // 分割线画刷
graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );
// 普通文字的对齐方式
StringFormat strFormat;
strFormat.SetAlignment(StringAlignmentNear); // 左对齐
if(m_uVAlignment == VAlign_Top)
{
strFormat.SetLineAlignment(StringAlignmentNear); // 上对其
}else
if(m_uVAlignment == VAlign_Middle)
{
strFormat.SetLineAlignment(StringAlignmentCenter); // 中间对齐
}else
if(m_uVAlignment == VAlign_Bottom)
{
strFormat.SetLineAlignment(StringAlignmentFar); // 下对齐
}
strFormat.SetTrimming(StringTrimmingEllipsisWord); // 以单词为单位去尾,略去部分使用省略号
//strFormat.SetFormatFlags( StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces);
if(!m_bTextWrap)
{
strFormat.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces); // 不换行
}
// 时间字段采用右对齐
StringFormat strFormatRight;
strFormatRight.SetAlignment(StringAlignmentFar); // 右对齐
if(m_uVAlignment == VAlign_Top)
{
strFormatRight.SetLineAlignment(StringAlignmentNear); // 上对其
}else
if(m_uVAlignment == VAlign_Middle)
{
strFormatRight.SetLineAlignment(StringAlignmentCenter); // 中间对齐
}else
if(m_uVAlignment == VAlign_Bottom)
{
//.........这里部分代码省略.........
示例2: PaintText
void CLabelUI::PaintText(HDC hDC)
{
if( m_dwTextColor == 0 ) m_dwTextColor = m_pManager->GetDefaultFontColor();
if( m_dwDisabledTextColor == 0 ) m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor();
RECT rc = m_rcItem;
rc.left += m_rcTextPadding.left;
rc.right -= m_rcTextPadding.right;
rc.top += m_rcTextPadding.top;
rc.bottom -= m_rcTextPadding.bottom;
if(!GetEnabledEffect())
{
if( m_sText.IsEmpty() ) return;
int nLinks = 0;
if( IsEnabled() ) {
if( m_bShowHtml )
CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \
NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle);
else
CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \
m_iFont, DT_SINGLELINE | m_uTextStyle);
}
else {
if( m_bShowHtml )
CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \
NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle);
else
CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \
m_iFont, DT_SINGLELINE | m_uTextStyle);
}
}
else
{
Font nFont(hDC,m_pManager->GetFont(GetFont()));
Graphics nGraphics(hDC);
nGraphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
StringFormat format;
StringAlignment sa = StringAlignment::StringAlignmentNear;
if ((m_uTextStyle & DT_VCENTER) != 0) sa = StringAlignment::StringAlignmentCenter;
else if( (m_uTextStyle & DT_BOTTOM) != 0) sa = StringAlignment::StringAlignmentFar;
format.SetAlignment((StringAlignment)sa);
sa = StringAlignment::StringAlignmentNear;
if ((m_uTextStyle & DT_CENTER) != 0) sa = StringAlignment::StringAlignmentCenter;
else if( (m_uTextStyle & DT_RIGHT) != 0) sa = StringAlignment::StringAlignmentFar;
format.SetLineAlignment((StringAlignment)sa);
RectF nRc((float)rc.left,(float)rc.top,(float)rc.right-rc.left,(float)rc.bottom-rc.top);
RectF nShadowRc = nRc;
nShadowRc.X += m_ShadowOffset.X;
nShadowRc.Y += m_ShadowOffset.Y;
int nGradientLength = GetGradientLength();
if(nGradientLength == 0)
nGradientLength = (rc.bottom-rc.top);
LinearGradientBrush nLineGrBrushA(Point(GetGradientAngle(), 0),Point(0,nGradientLength),ARGB2Color(GetTextShadowColorA()),ARGB2Color(GetTextShadowColorB() == -1?GetTextShadowColorA():GetTextShadowColorB()));
LinearGradientBrush nLineGrBrushB(Point(GetGradientAngle(), 0),Point(0,nGradientLength),ARGB2Color(GetTextColor()),ARGB2Color(GetTextColor1() == -1?GetTextColor():GetTextColor1()));
if (GetEnabledLuminous())
{
// from http://bbs.csdn.net/topics/390346428
int iFuzzyWidth = (int)(nRc.Width/GetLuminousFuzzy());
if (iFuzzyWidth < 1) iFuzzyWidth = 1;
int iFuzzyHeight = (int)(nRc.Height/GetLuminousFuzzy());
if (iFuzzyHeight < 1) iFuzzyHeight = 1;
RectF nTextRc(0.0f, 0.0f, nRc.Width, nRc.Height);
Bitmap Bit1((INT)nRc.Width, (INT)nRc.Height);
Graphics g1(&Bit1);
g1.SetSmoothingMode(SmoothingModeAntiAlias);
g1.SetTextRenderingHint(TextRenderingHintAntiAlias);
g1.SetCompositingQuality(CompositingQualityAssumeLinear);
Bitmap Bit2(iFuzzyWidth, iFuzzyHeight);
Graphics g2(&Bit2);
g2.SetInterpolationMode(InterpolationModeHighQualityBicubic);
g2.SetPixelOffsetMode(PixelOffsetModeNone);
FontFamily ftFamily;
nFont.GetFamily(&ftFamily);
int iLen = wcslen(m_pWideText);
g1.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushB);
g2.DrawImage(&Bit1, 0, 0, (int)iFuzzyWidth, (int)iFuzzyHeight);
g1.Clear(Color(0));
g1.DrawImage(&Bit2, (int)m_ShadowOffset.X, (int)m_ShadowOffset.Y, (int)nRc.Width, (int)nRc.Height);
g1.SetTextRenderingHint(TextRenderingHintAntiAlias);
nGraphics.DrawImage(&Bit1, nRc.X, nRc.Y);
}
if(GetEnabledStroke() && GetStrokeColor() > 0)
{
LinearGradientBrush nLineGrBrushStroke(Point(GetGradientAngle(),0),Point(0,rc.bottom-rc.top+2),ARGB2Color(GetStrokeColor()),ARGB2Color(GetStrokeColor()));
#ifdef _UNICODE
nRc.Offset(-1,0);
nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
nRc.Offset(2,0);
//.........这里部分代码省略.........
示例3: LayerDraw
void CNotification::LayerDraw(CDIB *dib)
{
if(!dib)
{
dib = CNotification::dib;
}
CRect rect;
GetWindowRect(&rect);
dib->Resize(rect.Width(), rect.Height());
if(!dib->Ready())
{
return;
}
RectF rf(0.0f, 0.0f, (REAL)dib->Width(), (REAL)dib->Height());
rf.Width -= SHADOW_SIZE;
rf.Height -= SHADOW_SIZE;
Graphics g(dib->dc);
g.SetCompositingMode(CompositingModeSourceOver);
g.SetSmoothingMode(SmoothingModeAntiAlias);
GraphicsPath *path = new GraphicsPath();
float radius = rf.Height;
path->AddArc(rf.X + rf.Width - radius, rf.Y + rf.Height - radius, radius - 1, radius - 1, 0, 90);
path->AddArc(rf.X, rf.Y + rf.Height - radius, radius - 1, radius - 1, 90, 90);
path->AddArc(rf.X, rf.Y, radius - 1, radius - 1, 180, 90);
path->AddArc(rf.X + rf.Width - radius, rf.Y, radius - 1, radius - 1, 270, 90);
path->CloseFigure();
g.TranslateTransform(SHADOW_SIZE, SHADOW_SIZE);
g.ScaleTransform((rf.Width - SHADOW_SIZE) / rf.Width, (rf.Height - SHADOW_SIZE) / rf.Height);
SolidBrush brush2(0xf0000000);
g.FillPath(&brush2, path);
g.ResetTransform();
dib->Blur(dib->Rect(), CRect(0, 0, 0, 0), SHADOW_SIZE);
brush2.SetColor(0xffffffff);
g.FillPath(&brush2, path);
rf.X += rf.Height * 0.1f;
rf.Y += rf.Height * 0.1f;
rf.Width -= rf.Height * 0.2f;
rf.Height -= rf.Height * 0.2f;
radius = rf.Height;
path->Reset();
path->AddArc(rf.X + rf.Width - radius, rf.Y + rf.Height - radius, radius - 1, radius - 1, 0, 90);
path->AddArc(rf.X, rf.Y + rf.Height - radius, radius - 1, radius - 1, 90, 90);
path->AddArc(rf.X, rf.Y, radius - 1, radius - 1, 180, 90);
path->AddArc(rf.X + rf.Width - radius, rf.Y, radius - 1, radius - 1, 270, 90);
path->CloseFigure();
LinearGradientBrush brush(rf, 0xff6fa6de, 0xff1e6cbb, LinearGradientModeVertical);
g.FillPath(&brush, path);
delete path;
Font font(L"Arial", rect.Height() * 0.6f, FontStyleRegular, UnitPixel);
StringFormat *stringFormat = new StringFormat();
stringFormat->SetAlignment(StringAlignmentCenter);
stringFormat->SetLineAlignment(StringAlignmentCenter);
stringFormat->SetFormatFlags(StringFormatFlagsLineLimit);
stringFormat->SetTrimming(StringTrimmingEllipsisCharacter);
CString s;
GetWindowText(s);
g.DrawString(s.GetBuffer(), s.GetLength(), &font, rf, stringFormat, &brush2);
delete stringFormat;
}
示例4: DrawShipDesignMenue
/////////////////////////////////////////////////////////////////////////////////////////
// Hier die Funktion zum Zeichnen des Schiffsdesignmenüs
/////////////////////////////////////////////////////////////////////////////////////////
void CShipDesignMenuView::DrawShipDesignMenue(Graphics* g)
{
CBotEDoc* pDoc = resources::pDoc;
ASSERT(pDoc);
CMajor* pMajor = m_pPlayersRace;
ASSERT(pDoc);
if (!pMajor)
return;
CString fontName = "";
Gdiplus::REAL fontSize = 0.0;
// Rassenspezifische Schriftart auswählen
CFontLoader::CreateGDIFont(pMajor, 2, fontName, fontSize);
// Schriftfarbe wählen
Gdiplus::Color normalColor;
CFontLoader::GetGDIFontColor(pMajor, 3, normalColor);
StringFormat fontFormat;
fontFormat.SetAlignment(StringAlignmentNear);
fontFormat.SetLineAlignment(StringAlignmentCenter);
fontFormat.SetFormatFlags(StringFormatFlagsNoWrap);
Color penColor;
penColor.SetFromCOLORREF(pMajor->GetDesign()->m_clrListMarkPenColor);
Color markColor;
markColor.SetFromCOLORREF(pMajor->GetDesign()->m_clrListMarkTextColor);
if (bg_designmenu)
g->DrawImage(bg_designmenu, 0, 0, 1075, 750);
SolidBrush fontBrush(normalColor);
// Links im Bild die veränderbaren Schiffklassen zeichnen (bis jetzt darf man keine Stationen verändern,
// weil deren Baukosten allein von den Industriekosten berechnet werden. Diese aber nicht steigen wenn
// man die Hülle oder Schilde verbessert. Somit könnte man bessere Stationen für den gleichen Preis bauen.
// Schiffsinfoarray durchgehen und nach zum Imperium gehörende baubare Schiffe suchen
short j = 0;
short counter = m_iClickedOnShip - 23 + m_iOldClickedOnShip;
short oldClickedShip = m_iClickedOnShip;
BYTE researchLevels[6] =
{
pMajor->GetEmpire()->GetResearch()->GetBioTech(),
pMajor->GetEmpire()->GetResearch()->GetEnergyTech(),
pMajor->GetEmpire()->GetResearch()->GetCompTech(),
pMajor->GetEmpire()->GetResearch()->GetPropulsionTech(),
pMajor->GetEmpire()->GetResearch()->GetConstructionTech(),
pMajor->GetEmpire()->GetResearch()->GetWeaponTech()
};
m_pShownShip = NULL;
m_nSizeOfShipDesignList = 0;
// Es gehen nur 21 Einträge auf die Seite, deshalb muss abgebrochen werden
for (int i = 0; i < pDoc->m_ShipInfoArray.GetSize(); i++)
if (pDoc->m_ShipInfoArray.GetAt(i).GetRace() == pMajor->GetRaceShipNumber())
if (!pDoc->m_ShipInfoArray.GetAt(i).IsStation())
if (pDoc->m_ShipInfoArray.GetAt(i).IsThisShipBuildableNow(researchLevels))
{
// wurde dieses Schiff durch kein anderes jetzt baubares Schiff schon obsolet?
BOOLEAN foundObsolet = FALSE;
for (int m = 0; m < pDoc->m_ShipInfoArray.GetSize(); m++)
if (pDoc->m_ShipInfoArray.GetAt(m).GetRace() == pMajor->GetRaceShipNumber())
if (pDoc->m_ShipInfoArray.GetAt(m).GetObsoleteShipClass() == pDoc->m_ShipInfoArray.GetAt(i).GetShipClass())
if (pDoc->m_ShipInfoArray.GetAt(m).IsThisShipBuildableNow(researchLevels))
{
foundObsolet = TRUE;
break;
}
if (foundObsolet)
continue;
m_nSizeOfShipDesignList++;
if (counter > 0)
{
m_iClickedOnShip--;
counter--;
continue;
}
if (j < 24)
{
fontBrush.SetColor(normalColor);
// Wenn wir ein Schiff gefunden haben, dann zeichnen wir dieses in die Liste (max. 21)
// Wenn wir das Schiff markiert haben, dann die Markierung zeichnen, haben wir kein spezielles Schiff
// angeklickt, so wird das 1. Schiff in der Liste markiert
if (j == m_iClickedOnShip || m_iClickedOnShip == -1)
{
fontBrush.SetColor(markColor);
// Wenn wir nix angeklickt haben und nur das erste Schiff markiert war, dann automatisch
m_iClickedOnShip = j;
if (oldClickedShip == -1)
//.........这里部分代码省略.........
示例5: DrawControl
void CDuiEdit::DrawControl(CDC &dc, CRect rcUpdate)
{
Graphics graphics(dc);
DrawImageFrame(graphics, m_pImage, m_rc, m_EditState * m_sizeImage.cx, 0, m_sizeImage.cx, m_sizeImage.cy, 4);
if(m_pLeftImage)
{
CRect rc;
rc.left = m_rc.left + 2;
rc.top = m_rc.top + (m_rc.Height() - m_sizeLeftImage.cy) / 2;
rc.right = rc.left + m_sizeLeftImage.cx;
rc.bottom = rc.top + m_sizeLeftImage.cy;
if(m_nLeftImageCount > m_buttonState)
{
graphics.DrawImage(m_pLeftImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()),
(Gdiplus::REAL)(m_buttonState * m_sizeLeftImage.cx), 0, (Gdiplus::REAL)m_sizeLeftImage.cx, (Gdiplus::REAL)m_sizeLeftImage.cy, UnitPixel);
}else
{
graphics.DrawImage(m_pLeftImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()),
0, 0, (Gdiplus::REAL)m_sizeLeftImage.cx, (Gdiplus::REAL)m_sizeLeftImage.cy, UnitPixel);
}
}
if(m_pSmallImage)
{
CRect rc;
rc.left = m_rc.right - m_sizeSmallImage.cx - 2;
rc.top = m_rc.top + (m_rc.Height() - m_sizeSmallImage.cy) / 2;
rc.right = rc.left + m_sizeSmallImage.cx;
rc.bottom = rc.top + m_sizeSmallImage.cy;
if(m_nSmallImageCount > m_buttonState)
{
graphics.DrawImage(m_pSmallImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()),
(Gdiplus::REAL)(m_buttonState * m_sizeSmallImage.cx), 0, (Gdiplus::REAL)m_sizeSmallImage.cx, (Gdiplus::REAL)m_sizeSmallImage.cy, UnitPixel);
}else
{
graphics.DrawImage(m_pSmallImage, RectF((Gdiplus::REAL)rc.left , (Gdiplus::REAL)rc.top, (Gdiplus::REAL)rc.Width(), (Gdiplus::REAL)rc.Height()),
0, 0, (Gdiplus::REAL)m_sizeSmallImage.cx, (Gdiplus::REAL)m_sizeSmallImage.cy, UnitPixel);
}
}
BSTR bsFont = m_strFont.AllocSysString();
FontFamily fontFamily(bsFont);
Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
SolidBrush solidBrush(m_clrText);
SolidBrush solidBrushTip(m_clrTooltip);
graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );
::SysFreeString(bsFont);
StringFormat strFormat;
strFormat.SetAlignment(StringAlignmentNear); // 水平方向左对齐
if(!m_bMultiLine)
{
// 单行文字
strFormat.SetLineAlignment(StringAlignmentCenter); // 垂直方向中间对齐
strFormat.SetFormatFlags( StringFormatFlagsNoWrap | StringFormatFlagsMeasureTrailingSpaces);
}else
{
strFormat.SetLineAlignment(StringAlignmentNear); // 垂直方向上对齐
}
RectF rect((Gdiplus::REAL)m_rcText.left, (Gdiplus::REAL)(m_rcText.top+2), (Gdiplus::REAL)m_rcText.Width(), (Gdiplus::REAL)(m_rcText.Height()-2));
if(!m_strTitle.IsEmpty())
{
// 文字非空
CString strTitle = m_strTitle;
if(m_bPassWord)
{
int nlen = strTitle.GetLength();
strTitle = "";
for(int i = 0; i < nlen; i++)
{
strTitle += '*';
}
}
BSTR bsTitle = strTitle.AllocSysString();
graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrush);
::SysFreeString(bsTitle);
}else
if(!m_strTooltip.IsEmpty())
{
// 如果没有文字,但设置了tooltip,则显示tooltip
BSTR bsTooltip = m_strTooltip.AllocSysString();
graphics.DrawString(bsTooltip, (INT)wcslen(bsTooltip), &font, rect, &strFormat, &solidBrushTip);
::SysFreeString(bsTooltip);
}
}
示例6: Draw
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();
//.........这里部分代码省略.........
示例7: DrawWindow
// 画文字信息
void CPopupList::DrawWindow(CDC &dc, CRect rcClient)
{
int nItemCount = m_vecItem.size();
CRect rcItem, rcText;
Graphics graphics(dc);
BSTR bsFont = m_strFont.AllocSysString();
FontFamily fontFamily(bsFont);
Font font(&fontFamily, (REAL)m_nFontWidth, m_fontStyle, UnitPixel);
graphics.SetTextRenderingHint( TextRenderingHintClearTypeGridFit );
::SysFreeString(bsFont);
StringFormat strFormat;
strFormat.SetAlignment(StringAlignmentNear); // 左对齐
strFormat.SetLineAlignment(StringAlignmentCenter); // 中间对齐
for(int i = 0; i < nItemCount; i++)
{
EditListItem &editListItem = m_vecItem.at(i);
rcItem = editListItem.rcItem;
int nLeftStart = 47;
if(editListItem.pImage == NULL) // 没有图片,左边距
{
nLeftStart = 5;
}else
if(m_bSingleLine) // 单行,左边距减少一些
{
nLeftStart = 25;
}
// 显示当前项
if((i == m_nHoverItem) && !editListItem.strDesc.IsEmpty())
{
SolidBrush brushHover(m_clrHover);
graphics.FillRectangle(&brushHover, rcItem.left, rcItem.top, rcItem.Width(), rcItem.Height());
// 显示name和desc
SolidBrush solidBrushTitle(editListItem.clrText);
SolidBrush solidBrushDesc(editListItem.clrDesc);
RectF rect((Gdiplus::REAL)(rcItem.left + nLeftStart), (Gdiplus::REAL)(rcItem.top + 1), (Gdiplus::REAL)(rcItem.Width() - nLeftStart -2), (Gdiplus::REAL)(rcItem.Height()/2));
BSTR bsTitle = editListItem.strName.AllocSysString();
graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrushTitle);
::SysFreeString(bsTitle);
rect.Offset(0, (Gdiplus::REAL)(rcItem.Height() / 2));
BSTR bsDesc = editListItem.strDesc.AllocSysString();
graphics.DrawString(bsDesc, (INT)wcslen(bsDesc), &font, rect, &strFormat, &solidBrushDesc);
::SysFreeString(bsTitle);
}
else
{
if(i == m_nHoverItem)
{
SolidBrush brushHover(m_clrHover);
graphics.FillRectangle(&brushHover, rcItem.left, rcItem.top, rcItem.Width(), rcItem.Height());
}
// 只显示name
SolidBrush solidBrushTitle(editListItem.clrText);
RectF rect((Gdiplus::REAL)(rcItem.left + nLeftStart), (Gdiplus::REAL)rcItem.top, (Gdiplus::REAL)(rcItem.Width() - nLeftStart -2), (Gdiplus::REAL)rcItem.Height());
BSTR bsTitle = editListItem.strName.AllocSysString();
graphics.DrawString(bsTitle, (INT)wcslen(bsTitle), &font, rect, &strFormat, &solidBrushTitle);
::SysFreeString(bsTitle);
}
}
}
示例8: DrawString
/*
** Draws the string or calculates it's size
**
*/
bool CMeterString::DrawString(Graphics& graphics, RectF* rect)
{
if (m_Font == NULL) return false;
LPCWSTR string = m_String.c_str();
int stringLen = (int)m_String.length();
StringFormat stringFormat;
if (m_AntiAlias)
{
graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
}
else
{
graphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit);
}
switch (m_Align)
{
case ALIGN_CENTERCENTER:
stringFormat.SetAlignment(StringAlignmentCenter);
stringFormat.SetLineAlignment(StringAlignmentCenter);
break;
case ALIGN_RIGHTCENTER:
stringFormat.SetAlignment(StringAlignmentFar);
stringFormat.SetLineAlignment(StringAlignmentCenter);
break;
case ALIGN_LEFTCENTER:
stringFormat.SetAlignment(StringAlignmentNear);
stringFormat.SetLineAlignment(StringAlignmentCenter);
break;
case ALIGN_CENTERBOTTOM:
stringFormat.SetAlignment(StringAlignmentCenter);
stringFormat.SetLineAlignment(StringAlignmentFar);
break;
case ALIGN_RIGHTBOTTOM:
stringFormat.SetAlignment(StringAlignmentFar);
stringFormat.SetLineAlignment(StringAlignmentFar);
break;
case ALIGN_LEFTBOTTOM:
stringFormat.SetAlignment(StringAlignmentNear);
stringFormat.SetLineAlignment(StringAlignmentFar);
break;
case ALIGN_CENTER: // Same as CenterTop
stringFormat.SetAlignment(StringAlignmentCenter);
stringFormat.SetLineAlignment(StringAlignmentNear);
break;
case ALIGN_RIGHT: // Same as RightTop
stringFormat.SetAlignment(StringAlignmentFar);
stringFormat.SetLineAlignment(StringAlignmentNear);
break;
case ALIGN_LEFT: // Same as LeftTop
stringFormat.SetAlignment(StringAlignmentNear);
stringFormat.SetLineAlignment(StringAlignmentNear);
break;
}
if (m_ClipString)
{
stringFormat.SetTrimming(StringTrimmingEllipsisCharacter);
}
else
{
stringFormat.SetTrimming(StringTrimmingNone);
stringFormat.SetFormatFlags(StringFormatFlagsNoClip | StringFormatFlagsNoWrap);
}
CharacterRange range(0, stringLen);
stringFormat.SetMeasurableCharacterRanges(1, &range);
REAL x = (REAL)GetX();
REAL y = (REAL)GetY();
if (rect)
{
PointF pos(x, y);
graphics.MeasureString(string, stringLen, m_Font, pos, &stringFormat, rect);
}
else
{
RectF rcDest(x, y, (REAL)m_W, (REAL)m_H);
m_Rect = rcDest;
if (m_Angle != 0.0f)
{
graphics.TranslateTransform((Gdiplus::REAL)CMeter::GetX(), y);
graphics.RotateTransform(CONVERT_TO_DEGREES(m_Angle));
//.........这里部分代码省略.........