pcssecure
asked on
Changing style of font displayed in static text control box
Hi experts, I've created a CDialog box and put a Static Text Control in it.
How do i change the font text to bold, the type of fonts and the font size for the text displayed in the control box?
Thanks.
How do i change the font text to bold, the type of fonts and the font size for the text displayed in the control box?
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
see the LOGFONT stucture
I have just change the Weight field but you can manipulate other fields to get desired font for your control.
I have just change the Weight field but you can manipulate other fields to get desired font for your control.
You can use CWnd::OnCtlColor to set dialog control font:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cwnd.3a3a.onctlcolor.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cwnd.3a3a.onctlcolor.asp
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi vijay, i've successfully changed the text to bold but i can't seems to change the font size.
I tried to change the font size using the following statement, but the size is still the same.
logFont.lfHeight = -MulDiv(20, dc->GetDeviceCaps(LOGPIXEL SY), 72);
Pls advice.
Thks!
I tried to change the font size using the following statement, but the size is still the same.
logFont.lfHeight = -MulDiv(20, dc->GetDeviceCaps(LOGPIXEL
Pls advice.
Thks!
In my code it is working fine.
do the following
HDC hdc = GetDC()->m_hDC ;
ASSERT(hdc);
int PointSize = 20;
int nHight = -MulDiv(PointSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
//check nHight here in my pc it is -27
LogFont.lfHeight = nHight ;
do the following
HDC hdc = GetDC()->m_hDC ;
ASSERT(hdc);
int PointSize = 20;
int nHight = -MulDiv(PointSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
//check nHight here in my pc it is -27
LogFont.lfHeight = nHight ;
Are you trying to change one specific static text item, or all of the text in the dialog to the same font?
If you want to change all of them, you can change the font, size, and weight by setting a dialog property. For VC++.Net, right-mouse on the dialog title bar in the resource editor, select properties. In the properties window is a Font section that lets you change the font attributes.
I think there is someething equivalent in VC++6.0.
If you want to change all of them, you can change the font, size, and weight by setting a dialog property. For VC++.Net, right-mouse on the dialog title bar in the resource editor, select properties. In the properties window is a Font section that lets you change the font attributes.
I think there is someething equivalent in VC++6.0.
void CTransparentDlg::OnButton1
{
// TODO: Add your control notification handler code here
CWnd *pWnd;
pWnd=this->GetDlgItem(IDC_
if (pWnd!=NULL) {
LOGFONT lf;
CFont *pOldFont;
CFont *pNewFont;
pOldFont=pWnd->GetFont();
pOldFont->GetLogFont(&lf);
lf.lfWeight=FW_BOLD;
pNewFont=new CFont;
pNewFont->CreateFontIndire
pWnd->SetFont(pNewFont);
delete pNewFont;
pWnd->SetFont(pOldFont,FAL
}
}