Home > Windows API > Changing font of all child controls at one go!

Changing font of all child controls at one go!

Ever felt the need to change the font of all child controls of a dialog, or a window, and you had to use GetWindow, GetNextWindow and stuff like that to set a font for a window. Well here is an easy way!

// Idea taken from MSDN...
BOOL CSomeDialog::OnInitDialog()
{
    // I am using a static font for demo purpose only, make sure
    // you have this as a member
    static CFont fnt;
    CDC dc;
    dc.Attach( GetDC()->GetSafeHdc() );
    fnt.CreatePointFont( 100, _T( "Courier new" ), &dc );

    // Set change font message to all child windows
    SendMessageToDescendants( GetSafeHwnd(),
                              WM_SETFONT,
                              (WPARAM)fnt.GetSafeHandle(),
                              MAKELONG(WORD( TRUE ), 0 ),
                              true,
                              false );
}// End OnInitDialog
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: