Results 1 to 6 of 6

Thread: Font

  1. #1

    Thread Starter
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Post Font

    The Fonts are always ugly... How do you change them? In Win32 that is...

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    may I offer parksies famous funcion

    Code:
    void SetFont(HWND hWnd, int iPointSize, const char *pcFontName) {
        
        HFONT hTheFont;
        HDC hDC = GetDC(hWnd);
        int nHeight = -MulDiv(iPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
    
        hTheFont = CreateFont(nHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, pcFontName);
    
        ReleaseDC(hWnd, hDC);
    
        SendMessage(hWnd, WM_SETFONT, (WPARAM)hTheFont, TRUE);
    }

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    No, you may not

    Kidding, use it all you want! It's free!

    (like Simon's mum on thursday nights )
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    If you don't want to set the font of controls, you'll need a device context too. Just replace the line with SendMessage by:
    Code:
    HFONT hOldFont = SelectObject(hdc, hfont);
    Then return the old font (you will have to select it back into the dc once your done drawing text). Unlike parksies function, you must call this every time you got a new dc. (BeginPaint, GetDC etc.)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Addicted Member Bazza81's Avatar
    Join Date
    Apr 2001
    Location
    Nottingham, UK
    Posts
    203
    One VERY important rule to remember is not to destroy the font after sending WM_SETFONT message. Windows will not make a copy of the font and starangethings can happen if an HFONT is destroyed while it is being refferenced.
    Who needs rhetorical questions anyway?


    Bazza NET - The place you want to be!

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Someone's been browsing posts... (look at the date)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width