Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC10.0
I am new to this vc++. I want to change the font size in my edit control. Here is what I have written. It compiles and runs but does not change the font size. My project has one edit box and one button.
 
void CHebrewDlg::OnBnClickedNext()
{
	CEdit *pCtrl = (CEdit*) GetDlgItem(IDC_EDIT1);
	int static count = 0;
	wchar_t hebrew_ch[30] = 
           { L'א', L'בּ', L'ב', L'ג', L'ד', L'ה', L'ו', L'ז', L'ח', L'ט', 
	     L'י', L'כּ', L'כ', L'ל', L'מ', L'נ', L'ס', L'ע', L'פּ', L'פ',        
	     L'צ', L'ק', L'ר', L'שׁ', L'שׂ', L'ת' };
 
	LOGFONT lf;
 
	// clear out structure
	memset(&lf, 0, sizeof(LOGFONT)); 
 
	// request a 12-pixel-height font
	lf.lfHeight = 24;                
 
	// request a face name "Arial"
	_tcsncpy_s(lf.lfFaceName, LF_FACESIZE, _T("Arial"), 7);
 
	CFont font1;
	font1.CreateFontIndirect(&lf);  // create the font

	// CFont::operator HFONT automatically converts font1 from 
	// CFont* to HFONT.
	CFont* font2 = CFont::FromHandle(font1);
 
	//send to the target window
	SendMessage((UINT)pCtrl, WM_SETFONT, (WPARAM)font2);
 
	pCtrl->SetWindowTextW((CString)hebrew_ch[count]);
	count = ++count % 26;
 
 //Done with the font. Delete the font object.
 font1.DeleteObject();
}
Posted 29-Jan-12 21:39pm
Edited 29-Jan-12 21:45pm
v2
Comments
Rajesh Anuhya at 30-Jan-12 2:45am
   
pre Tags added.
--RA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to make the CFont object persist for the life of the control. Do not destroy it until the window that contains the control goes out of scope.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 295
1 OriginalGriff 274
2 Shweta N Mishra 216
3 PIEBALDconsult 184
4 CPallini 155
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 30 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100