Set Button / Edit box font

This is a discussion on Set Button / Edit box font within the Windows Programming forums, part of the Platform Specific Boards category; hey...is there any "easy way" to set the fonts in my program? i want Microsoft Sans Serif, 10pt font for ...

  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    Set Button / Edit box font

    hey...is there any "easy way" to set the fonts in my program? i want Microsoft Sans Serif, 10pt font for the controls. i found this in another post on here:
    Code:
    // Default font for button
    void SetDefaultFont( HWND hWnd, int identifier ){
        SendDlgItemMessage(hWnd, identifier, WM_SETFONT,
    		(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE, 0));
    but i dont want the default font and i know you can create a font but thats quite a bit of code (at least it was when i did it) so yea - is the only way to create a font and then set it using that font? thanks
    Registered Linux User #380033. Be counted: http://counter.li.org

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    The CreateFont function can be daunting, given the number of arguments, fortunately, most of them accept the default value.
    Code:
    HFONT CreateFontEasy(HDC hdc, LPCTSTR szFontName, UINT nFontPointSize, BOOL fBold)
    {
    	return CreateFont(-MulDiv(nFontPointSize, GetDeviceCaps(hdc, LOGPIXELSY), 72),
    	                  0, 0, 0, fBold ? FW_BOLD : FW_NORMAL,
    	                  FALSE, FALSE, FALSE,
    	                  DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
    	                  DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE,
    	                  szFontName);
    }
    
    void SetControlFont(HWND hwnd, int identifier)
    {
    	HDC   hdc   = GetDC(hwnd);
    	HFONT hFont = CreateFontEasy(hdc, TEXT("Microsoft Sans Serif"), 10, FALSE);
    
    	SendDlgItemMessage(hwnd, identifier, WM_SETFONT, (WPARAM) hFont, MAKELPARAM(TRUE, 0));
    
    	ReleaseDC(hwnd, hdc);
    }

  3. #3
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    awesome :-D
    thanks.
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiline Edit Box Parser
    By The Brain in forum Windows Programming
    Replies: 6
    Last Post: 11-01-2005, 07:15 PM
  2. Replies: 2
    Last Post: 05-31-2005, 04:02 PM
  3. display a file in dropdown edit box
    By sunburnbyRA in forum Windows Programming
    Replies: 2
    Last Post: 03-10-2004, 01:58 PM
  4. Edit and Combo Box
    By MPSoutine in forum Windows Programming
    Replies: 2
    Last Post: 11-21-2003, 12:54 PM
  5. Edit Box Questions PT. II
    By Quantrizi in forum Windows Programming
    Replies: 16
    Last Post: 08-12-2003, 11:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21