本文主要是介绍字模,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://bbs.bccn.net/thread-291042-1-1.html
#include <tchar.h>
#include <malloc.h>
#include <windows.h>WINBASEAPI HWND WINAPI GetConsoleWindow();
//
// 把 double 型转换成 FIXED 型数据
FIXED FixedFromDouble(double d)
{long l;l = (long)(d * 65536L);return *(FIXED*)&l;
}// 初始化单位矩阵
BOOL MatrixIdentity(MAT2* pMatrix, double dbZoom)
{if(pMatrix){pMatrix->eM11 = FixedFromDouble(dbZoom);pMatrix->eM12 = FixedFromDouble(0);pMatrix->eM21 = FixedFromDouble(0);pMatrix->eM22 = FixedFromDouble(dbZoom);return TRUE;}return FALSE;
}// 初始化字体
HFONT InitFont()
{LOGFONT lf = { -20, 16, 0, 0, 1, 0, 0, 0,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH,_T("宋体") };return CreateFontIndirect(&lf);
}// 打印字符
BOOL PrintCharacter(HDC hDC, UINT ch)
{if(hDC){GLYPHMETRICS gm;MAT2 matrix;DWORD dwSize;// 放大2倍矩阵if(!MatrixIdentity(&matrix, 2.0f)) return FALSE;// 测试需要申请的空间dwSize = GetGlyphOutline(hDC, ch, GGO_BITMAP, &gm, 0, NULL, &matrix);if(dwSize > 0 && dwSize < 0xFFFF){LPBYTE lpBuffer = (LPBYTE)malloc(dwSize);if(lpBuffer){// 获得字形if(GetGlyphOutline(hDC, ch, GGO_BITMAP, &gm, dwSize, lpBuffer, &matrix)){int i, j, k;int nByteCount;// 每行字节数nByteCount = ((gm.gmBlackBoxX + 31) >> 5) << 2;// 遍历行for(i = 0; i < gm.gmBlackBoxY; i++){// 遍历列for(j = 0; j < nByteCount; j++){BYTE code = lpBuffer[i * nByteCount + j];// 遍历位for(k = 0; k < 8; k++){if(code & (0x80 >> k)) _tprintf(_T("+"));else _tprintf(_T(" "));}}_tprintf(_T("\r\n"));}}}free(lpBuffer);return TRUE;}}return FALSE;
}int PrintString(HDC hDC, LPCTSTR pString)
{if(pString){TCHAR* p = pString;while(*p){if(!PrintCharacter(hDC, *p)) break;_tprintf(_T("\r\n"));p += 1;}return p - pString;}return 0;
}int main()
{// 获得当前控制台设备句柄HWND hWnd = GetConsoleWindow();HDC hDC = GetDC(hWnd);HFONT hFont = InitFont();HFONT hOldFont = SelectObject(hDC, hFont);int cnt = PrintString(hDC, _T("FlyingBlue园林"));SelectObject(hDC, hOldFont);DeleteObject(hFont);ReleaseDC(hWnd, hDC);return 0;
}
这篇关于字模的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!