Click here to Skip to main content
12,399,975 members (48,280 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ 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'ת' };
	// 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.
Posted 29-Jan-12 20:39pm
Updated 29-Jan-12 20:45pm
Rajesh Anuhya 30-Jan-12 2:45am
pre Tags added.

1 solution

Rate this: bad
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.

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

Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 30 Jan 2012
Copyright © CodeProject, 1999-2016
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