在logfont结构中有lfWidth的属性,但如果是一个设定好字体和字号的单行编辑框,如何获取对应的font的lfwidth/?最好是基于win32api的实现,,多谢1!
解决方案 »
- 谁能帮忙写一个小例子:通过ecx传递this指针的例子
- SumatraPDF在win98下面运行时菜单条丢失
- 我这段画CListCtrl控件的代码哪里有问题?为什么总出现些怪问题??
- 关于windows字体问题
- 如何提取网页中选取的内容?
- 请问下面的代码的最后那条语句为什么会出现内存不能读的异常
- char * 或者CString 如何转化为 DWORD,CString的 FFFFFF 如何转化为COLORREF
- 請問:哪里有modem驅動編程方面的資料?
- RS码的问题~~有程序~~但是有错误
- ::DeleteObject()的问题;
- 如何把一个Doc里的某Node复制到另外一个Doc里?
- [求助]谁有用CSocket或CAsyncSocket类写的基于TCP的聊天通信小程序
pfont = GetDlgItem(IDC_EIDT1)->GetFont();
LOGFONT logfont;
pfont->GetLogFont(&logfont);
logfont里的lfWidth就是
LOGFONT logFont;
GetObject(hFont , sizeof(LOGFONT), &logFont);
LOGFONT logFont;
GetObject(hFont , sizeof(LOGFONT), &logFont);
但只有在CDC类中使用(它内部是要获取当前dc的字体信息)
HOWTO: Change the Font Used by Dialog Controls in Windows Q74737
--------------------------------------------------------------------------------
The information in this article applies to:Microsoft Win32 Software Development Kit (SDK)
Microsoft Windows Software Development Kit (SDK) 3.1--------------------------------------------------------------------------------
SUMMARY
In Windows 3.x, there are two ways to specify the font used by dialog controls: The FONT statement can be used in the dialog template to specify the font used by ALL the controls in the dialog box.
The WM_SETFONT message can be sent to one or more dialog controls during the processing of the WM_INITDIALOG message.
If a font is specified in the dialog template, the controls will use a bold version of that font. The following code demonstrates how to change the font used by dialog box controls to a nonbold font using WM_SETFONT. The font should be deleted with DeleteObject() when the dialog box is closed.
Sample Code HWND hDlg;
HFONT hDlgFont;
LOGFONT lFont; case WM_INITDIALOG:
/* Get dialog font and create non-bold version */
hDlgFont = NULL;
if ((hDlgFont = (HFONT)SendMessage(hDlg, WM_GETFONT, 0, 0L))
!= NULL)
{
if (GetObject(hDlgFont, sizeof(LOGFONT), (LPSTR)&lFont)
!= NULL)
{
lFont.lfWeight = FW_NORMAL;
if ((hDlgFont = CreateFontIndirect(&lFont)) != NULL)
{
SendDlgItemMessage(hDlg, CTR1, WM_SETFONT, hDlgFont, 0L);
// Send WM_SETFONT message to desired controls
}
}
}
else // user did not specify a font in the dialog template
{ // must simulate system font
lFont.lfHeight = 13;
lFont.lfWidth = 0;
lFont.lfEscapement = 0;
lFont.lfOrientation = 0;
lFont.lfWeight = 200; // non-bold font weight
lFont.lfItalic = 0;
lFont.lfUnderline = 0;
lFont.lfStrikeOut = 0;
lFont.lfCharSet = ANSI_CHARSET;
lFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
lFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lFont.lfQuality = DEFAULT_QUALITY;
lFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
lFont.lfFaceName[0] = NULL;
hDlgFont = CreateFontIndirect(&lFont); SendDlgItemMessage(hDlg, CTR1, WM_SETFONT, hDlgFont,
(DWORD)TRUE);
// Send WM_SETFONT message to desired controls
} return TRUE;
break; Additional query words: Keywords : kbDlg kbNTOS kbWinOS2000 kbSDKWin32 kbGrpUser kbWinOS
Issue type : kbhowto
Technology : kbvcSearch
Last Reviewed: July 7, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
HDC hdc;
hdc = GetDC(Edit1->Handle) ;
LOGFONT font;
LONG i;
SIZE lstr_Size;
char s[50],ss[20]; font.lfHeight = 15;
font.lfWidth = 10;
font.lfWeight = 400;
font.lfCharSet = GB2312_CHARSET;//'0' ;
strcpy(font.lfFaceName,"ËÎÌå");
HFONT af,of;
af = CreateFontIndirect ( &font );
of = SelectObject(hdc,af);
LOGFONT logFont;
GetObject(of , sizeof(LOGFONT), &logFont);
i = logFont.lfWidth;
itoa(i,ss,10) ;
ShowMessage( ss) ;edit11的字体无论用24或者是18返回值都是7,麻烦帮看看什么地方错了,多谢!
{
// retrieve title font
CFont* pOldFont = pDC->SelectObject(pFont);
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
// get average character width and title bar height
*pCharWidth = tm.tmAveCharWidth;
*pCharHeight = tm.tmHeight + tm.tmExternalLeading;
pDC->SelectObject(pOldFont);
}