Results 1 to 6 of 6

Thread: Fonts

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    Fonts

    How would I add different fonts to my buttons and statics?

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You need to send it a WM_SETFONT message with the handle to a newly created HFONT:
    Code:
    SendMessage(hWnd_Edit, WM_SETFONT, hTheFont, TRUE); // TRUE = redraw after setting
    To create the font, use the CreateFont function:
    Code:
    HFONT hTheFont;
    HDC hEditDC = GetDC(hWnd_Edit);
    int nHeight = -MulDiv(26 /* Point size required */, GetDeviceCaps(hEditDC, 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, "Times New Roman");
    
    ReleaseDC(hEditDC);
    See the PSDK for more info on the parameters...there's lots of them I would post it here but it's too long
    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    should I put this right under WinMain?

    so It would look like this?

    Code:
    HFONT hTheFont;
    HDC hEditDC = GetDC(ghWnd_PlayFile);
    int nHeight = -MulDiv(26 /* Point size required */, GetDeviceCaps(hEditDC, 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, "Wingdings 3");
    
    ReleaseDC(ghWnd_PlayFile, hEditDC);
    
    SendMessage(ghWnd_PlayFile, WM_SETFONT, hTheFont, TRUE); // TRUE = redraw after setting

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You could do, or you could separate it out into a separate function that you call from WinMain:
    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, hTheFont, TRUE);
    }
    
    int WinMain(...) {
        // ...
        SetFont(ghWnd_Edit, 26, "Wingdings 3");
        // ...
    }
    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

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Nothing Changes...not even sizes

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Hmmm...it worked for me when I just tested that function

    (I used the (WPARAM) cast as decided in our MSN conversation...)
    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

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