Click here to Skip to main content
15,908,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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'ת' };


	// 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);

	count = ++count % 26;

 //Done with the font. Delete the font object.
Updated 29-Jan-12 20:45pm
Rajesh Anuhya 30-Jan-12 2:45am    
pre Tags added.

1 solution

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.
Share this answer

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

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