Archive

Posts Tagged ‘SendMessageToDescendants’

Changing font of all child controls at one go!

December 6, 2007 Leave a comment

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
%d bloggers like this: