CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Font Issue on Button Controls

  1. #1
    Join Date
    Dec 2008

    Font Issue on Button Controls

    I am writing a C++ Win32 program. I have searched the web using google and found what I am looking for (normally I do pretty quickly). I am trying to figure out how to change the Font Size of the Text displayed in a simple Button. For instance a button of similar stype to the one created by the following code.

    HWND button = (HWND)CreateWindow("COMBOBOX", "",CBS_DROPDOWN | WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_TABSTOP, 0, 0, 40, 100, hwnd, (HMENU)0, hInst, NULL);

    Thank you in advance for anyone who trys to help.

  2. #2
    Join Date
    Jan 2008

    Re: Font Issue on Button Controls

    See Google Groups. It has been answered 3 580 times (hits)

  3. #3
    Join Date
    Nov 2003

    Re: Font Issue on Button Controls

    Had this laying around...
    HFONT CreateFont(HDC hdc, int pitch, const wchar_t *facename, bool bold = false)
        // calculate font height based on requested pitch
        int nHeight = -MulDiv(pitch, GetDeviceCaps(hdc, LOGPIXELSY), 72);
        LOGFONTW lf = {0};
        lstrcpyW(lf.lfFaceName, facename);
        lf.lfHeight = nHeight;
        lf.lfWeight = bold ? FW_BOLD : FW_NORMAL;
        lf.lfOutPrecision = OUT_TT_PRECIS;
        lf.lfQuality = PROOF_QUALITY;
        return CreateFontIndirectW(&lf);
    You may want to play around with lfOutPrecision and lfQuality. Once you have your HFONT, you set the font by sending WM_SETFONT to the control.



  4. #4
    Join Date
    Dec 2008

    Re: Font Issue on Button Controls

    Thanks CodePlug that helped a lot

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)