免费观看又色又爽又黄的小说免费_美女福利视频国产片_亚洲欧美精品_美国一级大黄大色毛片

518抽獎軟件源碼之:GDI+上下左右中對齊

518抽獎軟件源碼之:GDI+上下左右中對齊

在開發“518抽獎軟件”的時候,需要用到GDI+的寫文字功能。 GDI+在對齊方面比原來的GDI復雜些,主要是 StringFormat 的參數設置和行高的測定問題,詳情參考下面的源碼。

創新互聯公司2013年至今,先為云州等服務建站,云州等地企業,進行企業商務咨詢服務。為云州企業網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。

GDIPLUS(gdi+)對齊處理的函數源碼


//單行文本,rc內對齊,align是水平對齊,valign是垂直對齊
//
void Tapp::paint_str(HDC hDc, const WCHAR* str, LOGFONT& lf, COLORREF color, RECT& rc, WORD align, WORD valign)
{
	if (!str) return;
	if (rc.right - rc.left <= 1 || rc.bottom - rc.top <= 1) return;

	StringFormat fmt;
	fmt.SetFormatFlags(StringFormatFlagsNoWrap | StringFormatFlagsNoClip | StringFormatFlagsMeasureTrailingSpaces);

	if (align == ALIGN_NEAR) fmt.SetAlignment(StringAlignmentNear);
	else if (align == ALIGN_CENTER) fmt.SetAlignment(StringAlignmentCenter);
	else fmt.SetAlignment(StringAlignmentFar);
	fmt.SetLineAlignment(StringAlignmentNear);

	RectF rcF;
	rcF.X = rc.left;
	rcF.Y = rc.top;
	rcF.Width = rc.right - rc.left;
	rcF.Height = rc.bottom - rc.top;

	FontFamily ff(lf.lfFaceName);
	Font gfont(hDc, &lf);
	SolidBrush  bru(Color(GetRValue(color), GetGValue(color), GetBValue(color)));
	Graphics g(hDc);

	int style = FontStyleRegular;
	if (lf.lfItalic) style = FontStyleItalic;
	if (lf.lfWeight == FW_BOLD) style = FontStyleBold;
	if (lf.lfItalic && lf.lfWeight == FW_BOLD) style = FontStyleBoldItalic;
	double r = (double)(ff.GetCellAscent(style) + ff.GetCellDescent(style)) / (double)ff.GetLineSpacing(style);

	if (align == ALIGN_NEAR) rcF.Width += 500.0;
	else if (align == ALIGN_FAR) { rcF.X -= 500.0; rcF.Width += 500.0; }
	else { rcF.X -= 500.0; rcF.Width += 1000.0; }

	if (valign == ALIGN_NEAR) rcF.Height += 500.0;
	else if (valign == ALIGN_CENTER) {
		rcF.Y -= 500.0;
		rcF.Height += 1000.0;
		rcF.Y += ((rcF.Height - gfont.GetHeight(&g)*r) / 2.0);
	}
	else {
		rcF.Y -= 500.0;
		rcF.Height += 500.0;
		rcF.Y += (rcF.Height - gfont.GetHeight(&g)*r);
	}

	SetTextRenderingHint(TextRenderingHintAntiAlias);
	g.DrawString(str, -1, &gfont, rcF, &fmt, &bru);
}

網站標題:518抽獎軟件源碼之:GDI+上下左右中對齊
文章地址:http://m.newbst.com/article24/jeecce.html

成都網站建設公司_創新互聯,為您提供網站營銷網站建設搜索引擎優化品牌網站設計服務器托管網站維護

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都網頁設計公司