Solved

Wizard -> Change Font

Posted on 1998-10-20
3
541 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Expert Comment

by:Answers2000
ID: 1323553
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
ID: 1323554
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
ID: 1323555
>> 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 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