Solved

Wizard -> Change Font

Posted on 1998-10-20
3
508 Views
Last Modified: 2013-12-03
How to change the font face & size for the item in the wizard?? I'm using CPropertySheet & CPropertyPage....

I've tried to change font in the resource view of its property page... but still cannot...

Anyone know how to??? Please provide a small sample code...

Thanks :-)
0
Comment
Question by:samyee
  • 2
3 Comments
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
1. Use WM_SETFONT messae. send it to each control you wanna change (e..g. in OnInitDialog)

For example to change an edit control.

// A. get old font  (do before changing the font) - see note #2 below
HFONT hOldFont = m_edit.SendMessage( WM_GETFONT, 0, 0 ) ;
// B. Set hFont to an HFONT you want to use, e.g.
HFONT hFont = (HFONT)::GetStockObject( SYSTEM_FIXED_FONT ) ;
// C. Change the control's font
m_edit.SendMessage( WM_SETFONT, (WPARAM)hFont MAKELPARAM(TRUE,0) ) ;


2. You should also set the font back before you exit (use WM_GETFONT to get the old font before setting the new one - see #1 comment A)


// restore font (do before exiting)
m_edit.SendMessage( WM_SETFONT, (WPARAM)hOldFont MAKELPARAM(TRUE,0) ) ;


2. If you create a font (by calling ::CreateFont or ::CreateFontIndirect - instead of GetStockObject), delete the font after restoring the old font (using DeleteObject(hFont) ; ) or you will leak memory.


0
 

Author Comment

by:samyee
Comment Utility
Thanks Answer2000..... But still cannot work... The font did change but it could not be other font than fixed font???
the following is my code.... I have derived another control class which inherited from CListCtrl
//================================
// in the control class itself
CFont *pFont = new CFont();
pFont->CreateFont(20, 0, 0, 0, 0,
      false, false,0,0,0,0,0,0, "Comic Sans MS");
SendMessage( WM_SETFONT, (WPARAM)pFont, MAKELPARAM(TRUE,0) ) ;
delete pFont;

//=======
Though the font has enlarged but still not the Comic Sans MS font... Anything wrong with the above code???
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 50 total points
Comment Utility
>> The font did change but it could not be other font than fixed font???

It can be any font

(1) Fill out the CreateFont params properly (look it up in the help - I won't duplicate it - for example font weight should FW_NORMAL or FW_BOLD

(2) your SendMessage is wrong
SendMessage( WM_SETFONT, (WPARAM)(HFONT)(pFont->m_hObject), MAKELPARAM(TRUE,0) )
-- see note (3)

a CFont * is not the same as an HFONT.  CFont has an operator to convert to HFONT - use that;  or use m_hFont public member of CFont's base class (CGdiObject)
- above uses m_hObject, the version below uses the operator HFONT()

(3) Don't delete the font till your dialog exits,  when you do delete you should set back the old font first.

i. Add class members to class
HFONT m_hOldFont ;
CFont m_Font ; // see comments in ii and iii

ii. When you set the new font, do this

m_Font.CreateFont( ...etc...) ;
m_hOldFont = SendMessage( WM_GETFONT, 0, 0 ) ;
SendMessage( WM_SETFONT, (WPARAM)(HFONT)(m_Font), MAKELPARAM(TRUE,0) )
By making m_Font a CFont rather than CFont*, it's easier to use operator HFONT() member of CFont.

iii. When you control dies, e.g. WM_DESTROY - set back old font

SendMessage( WM_SETFONT, (WPARAM)(HFONT)(m_hOldFont), MAKELPARAM(TRUE,0) )

Because m_Font is a member of your class, it gets deleted automatically when the object is deleted, no need for an explicit delete (if you were to make it a pointer, you "new" then you have to delete it)




0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now