
changing the font for text items in a dialog box
Hi Lieven,
//** FIRST GET THE CURRENT FONT - COPY It's INFO INTO A LOGFONT
STRUCT
CFont* TheOldFont = GetFont();
LOGFONT logFont;
TheOldFont->GetObject( sizeof( LOGFONT ), &logFont );
//** SECOND CHANGE THE WEIGHT AND THE NAME IN THE LOGFONT INFO SET
ASIDE
// Set attributes for new font
logFont.lfWeight = FW_MEDIUM;
strcpy(logFont.lfFaceName, "A Font Name");
//** THIRD CREATE A NEW FONT BASED ON THIS ALTERED LOGFONT
NewFont = new CFont();
// Create Font
NewFont->CreateFontIndirect( &logFont );
ASSERT_VALID( NewViewFont );
//** USE THIS TO SET ALL THE DIALOG'S CONTROLS TO THE FONT
SendMessageToDescendants( WM_SETFONT,
(WPARAM)NewFont->GetSafeHandle(), 0L, TRUE );
//** OR USE THIS JUST FOR YOUR STATIC CONTROLS or whatever
GetDlgItem(IDC_YOURSTATICTEXT)SendMessage( WM_SETFONT,
(WPARAM)NewFont->GetSafeHandle(), 0L, TRUE );
In yur case, choose a new font name
IMPORTANT: Don't forget to keep the declaration of these fonts in the
class header - they must be around at a class scope - not
function scope. Also, don't forget to "delete" the NewViewFont pointer
in your dtor.
<<<<<<<<<<<<<<<<<<<<<<<Here are the various values you can try from
windows.h.>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//**
/* weight values */
#define FW_DONTCARE 0
#define FW_THIN 100
#define FW_EXTRALIGHT 200
#define FW_LIGHT 300
#define FW_NORMAL 400
#define FW_MEDIUM 500
#define FW_SEMIBOLD 600
#define FW_BOLD 700
#define FW_EXTRABOLD 800
#define FW_HEAVY 900
#define FW_ULTRALIGHT FW_EXTRALIGHT
#define FW_REGULAR FW_NORMAL
#define FW_DEMIBOLD FW_SEMIBOLD
#define FW_ULTRABOLD FW_EXTRABOLD
#define FW_BLACK FW_HEAVY
<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Be as specific as you want in the LogFont structure
Let me know if that helps,
Charles Steinhardt[MVP]