16,472
社区成员
发帖
与我相关
我的任务
分享
#include"ENfont.h"
void ENfont::LHxxINITFONT(HFONT &font,LPCTSTR name,int width, int height)
{
font = CreateFont( height, // 字符高度(逻辑单位)
width, // 字符宽度(逻辑单位) 0为自动匹配
0, // 字符行角度
0, // 字符基线角度
400, // 0--1000 字体浓暗程度, 400为正常的
FALSE, // 是否为斜体字
FALSE, // 是否加下划线
0, // 是否加中划线
GB2312_CHARSET, // 指定字符集
OUT_DEFAULT_PRECIS, // 指定输出精度
CLIP_DEFAULT_PRECIS, // 指定剪切精度
DEFAULT_QUALITY, // 指定输出质量
DEFAULT_PITCH|FF_SWISS, // 指定间距, 字体族
name // 字体名
);
}
//Ddraw专用
void ENfont::LHxxDRAWFONT( HFONT &font,COLORREF RGB_value,char *info,int x,int y)
{
HDC hdc;
lpddsback->GetDC(&hdc);
SetBkMode(hdc, TRANSPARENT);
SelectObject( hdc, font );//选择字体
SetTextColor(hdc, RGB_value);
TextOut(hdc, x, y, info, strlen(info));
lpddsback->ReleaseDC(hdc);
}
void ENfont::LHxxSHOW_GDITEXT(HFONT &font,D3DXCOLOR RGB_back,COLORREF RGB_value,char *info,int x,int y)
{
//isalnum(window_char_message);
HDC hdc;
// get the dc
hdc = GetDC(hWnd);
// set the color
SetBkMode(hdc,OPAQUE);
SelectObject( hdc, font );//选择字体
SetTextColor(hdc,RGB_value);
//1.0f:不用底透明色,即:底为黑色;0.0f:则用底色
//色排列为:BGR.
//RGB_back D3DXCOLOR(200,100,100,1.0f);
SetBkColor(hdc,RGB_back);
// SetBkColor(hdc,D3DCOLOR_RGBA(0,0,0,0));
// print the message
TextOut(hdc,x,y,info,strlen(info));
// release the dc
ReleaseDC(hWnd,hdc);
}
void ENfont::LHxxFREEFONT(HFONT &font)
{
DeleteObject(font);
}
void ENfont::LHxxCREATE_FONT(LPD3DXFONT &m_pFont,int size_w,int size_h,char *name)
{
HDC hDC = GetDC( NULL );
ReleaseDC( NULL, hDC );
D3DXCreateFont( m_pd3dDevice, // D3D device
size_h, // Height
size_w, // Width
0, // Weight 0 FW_BOLD
0, // MipLevels, 0 = autogen mipmaps
FALSE, // Italic
DEFAULT_CHARSET, // CharSet
OUT_DEFAULT_PRECIS, // OutputPrecision
DEFAULT_QUALITY, // Quality
DEFAULT_PITCH | FF_SWISS, // PitchAndFamily FF_SWISS FF_DONTCARE
TEXT(name), // pFaceName TEXT("Arial")黑体
&m_pFont); // ppFont
// Restore the fonts
m_pFont->OnResetDevice();
}
void ENfont::LHxxSHOW_CHINATEXT(LPD3DXFONT &pFont,char *info,D3DXCOLOR RGB_value,int x,int y)
{
RECT rc;
SetRect( &rc, x, y, 0, 0 );
pFont->DrawText( NULL,info, -1, &rc, DT_NOCLIP,RGB_value);
// pFont->DrawText( NULL,info, -1, &rc, DT_NOCLIP, D3DXCOLOR( r, g, b, 1.0f ));
}
void ENfont::LHxxFREE_FONT(LPD3DXFONT &m_pFont)
{
if(m_pFont)
{
SAFE_DELETE( m_pFont );
}
}
CFont* hFont=new CFont;
hFont->CreateFont(m_Size,0,0,0,
FW_DONTCARE,
0,
0,
0,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_SWISS,
_T("宋体"));
CFont* hOldFont = pDC->SelectObject(hFont);
delete hFont;