changing the font for text items in a dialog box 
Author Message
 changing the font for text items in a dialog box

Dear all,

I need to display my data on a dialog box in a non proportional font.
Can anybody tell me how to do this in the most elegant way.

thanks

Lieven



Sun, 25 Jul 1999 03:00:00 GMT  
 changing the font for text items in a dialog box

You can change the font in the resource editor - Hit properties - General -
Font... to change it for the entire dialog box.

If you need to change it for just certain fields then do this:

// Declare a CFont in you dialogs class:  CFont m_fontOther;

BOOL YourDialog::OnInitDialog()
{
...
        LOGFONT logfont;
        VERIFY (GetDlgItem (IDC_YOURCONTROL)->GetFont()->GetLogFont (&logfont));

        // Change the logfont to what you want.
        logfont.lfWeight += FW_BOLD - FW_NORMAL;        // Make font bold

        VERIFY (m_fontOther.CreateFontIndirect (&logfont));

        GetDlgItem (IDC_YOURCONTROL)->SetFont (&m_fontOther, FALSE);
...

Quote:
}



Quote:
> Dear all,

> I need to display my data on a dialog box in a non proportional font.
> Can anybody tell me how to do this in the most elegant way.

> thanks

> Lieven



Sun, 25 Jul 1999 03:00:00 GMT  
 changing the font for text items in a dialog box

Lieven,

Set the data-displaying control(s) in your dialog to use a fixed-pitch
font.  Here's how:

Add a CFont member variable in your CDialog-derived class:

        CFont   m_fontFixed;

Then, in your OnInitDialog member function, do something like the
following...

        int CMyDialog::OnInitDialog()
        {
                LOGFONT lf;

                CDialog::OnInitDialog();

                // Get a description of the (standard) font used by some control
                // in the dialog -- this way you can just change the attributes
                // you need to, and leave the others as they are...
                GetDlgItem(IDC_SOMECTRL)->GetFont()->GetObject(sizeof(LOGFONT), &lf);

                // Modify to make a fixed-pitch font
                lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
                strncpy(lf.lfFaceName, "Courier New", LF_FACESIZE-1);

                // Create a font based on the new attributes
                VERIFY( m_fontFixed.CreateFontIndirect(&lf) );

                // Set the data-containing controls to use the new font
                GetDlgItem(IDC_LISTBOX)->SetFont(&m_fontFixed, FALSE);
                GetDlgItem(IDC_STATIC1)->SetFont(&m_fontFixed, FALSE);
                GetDlgItem(IDC_EDIT1)->SetFont(&m_fontFixed, FALSE);
        }

Hope that helps.

---
Scott Smith



Quote:
> Dear all,

> I need to display my data on a dialog box in a non proportional font.
> Can anybody tell me how to do this in the most elegant way.

> thanks

> Lieven



Sun, 25 Jul 1999 03:00:00 GMT  
 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]



Sun, 25 Jul 1999 03:00:00 GMT  
 changing the font for text items in a dialog box

Quote:
>I need to display my data on a dialog box in a non proportional font.
>Can anybody tell me how to do this in the most elegant way.

Lieven,

You'll need a CFont* member variable in your derived dialog class to
hold the font for the lifetime of the dialog.

In OnInitDialog, create the font you want to use and store it in your
class member variable.

For each control that you want to change the font for, call that
control's window SetFont routine with the font you have created.

Dave
----
Address is altered to discourage junk mail.
Remove ".---" for the real address.



Mon, 26 Jul 1999 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. How to change the color,size,font of text in a dialog box

2. How to change the color,size,font of text in a dialog box

3. Changing the Font in a text box

4. Changing font color in static text box

5. Text with different font in dialog box

6. Text with different font in dialog box

7. How do I change font of a text in dialog

8. changing fonts in a dialog box

9. How to change the font in dialog box

10. How to change font for controls in dialog box

11. How to change statit text in dialog box

12. Changing text in dialog box

 

 
Powered by phpBB® Forum Software