Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hi,
I create two CStatic controls. One property is set to transparent mode; another one is normal. After I change font size, one is OK, it is changed, but the set transparent mode one is not changed in size.

Does anybody know why ?

Thanks.

//////////////////////////////////////////////////
// Resource File
LTEXT "This Is Normal Text.",IDC_FONT2,7,119,303,21,WS_BORDER
LTEXT "This Include Transparent.",IDC_FONT,7,7,306,21,WS_BORDER | NOT WS_GROUP | WS_TABSTOP,WS_EX_TRANSPARENT


// FontTest.CPP
class CFontSizeDlg : public CDialogEx
{
public:
CStatic m_myFont;
CStatic m_myFont2;
}

// FontTest.CPP
void CFontSizeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_FONT, m_myFont);
DDX_Control(pDX, IDC_FONT2, m_myFont2);
}

void CFontSizeDlg::OnBnClickedButton2()
{
CFont hNewFont;
LOGFONT lf; // Used to create the CFont.

CFont *currentFont = GetFont();
currentFont->GetLogFont(&lf);
lf.lfHeight = 25;
lf.lfWidth = 10;

hNewFont.DeleteObject();
hNewFont.CreateFontIndirect(&lf); // Create the font.

// Use the font to paint a control.
m_myFont2.SetFont(&hNewFont);
m_myFont.SetFont(&hNewFont);

// hNewFont.Detach();
hNewFont.DeleteObject();
}
Posted
Updated 3-Feb-14 11:15am
v4

1 solution

You must not DeleteObject(); in your OnBnClickedButton2() method. The CFont hNewFont; variable must be defined as an instance variable of your CFontSizeDlg class and should be deleted when the class is destroyed. Read here[^], especially the comments section
 
Share this answer
 
Comments
wy737 4-Feb-14 12:26pm    
Thanks for your reply. My question is why difference between "Transparent mode" and "normal mode" in my case ?
chaau 4-Feb-14 13:16pm    
And I am replying: fix the bug first, and then see. May be the problem will go away
wy737 4-Feb-14 14:26pm    
Thanks, I got the solution . It is that to create New CStatic Class, and put new font routine in OnPaint Function.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900