question about font size
-
i do the following to change the font size of my CEdit control.But it doesn't work well,Who can tell me what's the wrong BOOL CDlgBase::OnInitDialog() { CDialog::OnInitDialog(); CFont *m_Font; CFont m_newFont; LOGFONT m_lf; memset(&m_lf,0,sizeof(LOGFONT)); m_Font = GetFont(); m_Font->GetLogFont(&m_lf); CClientDC dc(this); m_lf.lfHeight = -MulDiv( 8,dc.GetDeviceCaps( LOGPIXELSY ), 72 ); m_newFont.CreateFontIndirect(&m_lf); m_edit.SetFont(&m_newFont); return true; } gucy
-
i do the following to change the font size of my CEdit control.But it doesn't work well,Who can tell me what's the wrong BOOL CDlgBase::OnInitDialog() { CDialog::OnInitDialog(); CFont *m_Font; CFont m_newFont; LOGFONT m_lf; memset(&m_lf,0,sizeof(LOGFONT)); m_Font = GetFont(); m_Font->GetLogFont(&m_lf); CClientDC dc(this); m_lf.lfHeight = -MulDiv( 8,dc.GetDeviceCaps( LOGPIXELSY ), 72 ); m_newFont.CreateFontIndirect(&m_lf); m_edit.SetFont(&m_newFont); return true; } gucy
You're must
CFont m_newFont
move to the header file as global object Best regards, Eugene Pustovoyt -
i do the following to change the font size of my CEdit control.But it doesn't work well,Who can tell me what's the wrong BOOL CDlgBase::OnInitDialog() { CDialog::OnInitDialog(); CFont *m_Font; CFont m_newFont; LOGFONT m_lf; memset(&m_lf,0,sizeof(LOGFONT)); m_Font = GetFont(); m_Font->GetLogFont(&m_lf); CClientDC dc(this); m_lf.lfHeight = -MulDiv( 8,dc.GetDeviceCaps( LOGPIXELSY ), 72 ); m_newFont.CreateFontIndirect(&m_lf); m_edit.SetFont(&m_newFont); return true; } gucy
-
You're must
CFont m_newFont
move to the header file as global object Best regards, Eugene Pustovoythi : After i move the CFont declaration out of the function,it works well. But what i wonder is that i have used these code int the function CMainFrame::OnCreate to change the edit control'size on the toolbar. i also declare the CFont as local vaiable and it works perfect. Why i must delare it as global variable here. gucy
-
As Eugene Pustovoyt said, the font variable needs to be a global variable. It really doesn't matter if it works for you (no offense) or for anyone else. It won't work all the time. MSDN says that the font variable MUST be a global variable and I learned that the hard way. // Afterall, I realized that even my comment lines have bugs