Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Changing the font in a Combo Box?

Changing the font in a Combo Box?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chambers
    wrote on last edited by
    #1

    Hi All, just a quick one - How can I change the font type and size that is used to display text in a combo box? At the moment my MDI App has one located in the MainFrame toolbar, but because the Arial font looks so pants its made my app look as though its been designed for Windows 3.x. Please help make my app look better, Cheers Guys, Alan.:-D "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

    N 1 Reply Last reply
    0
    • C Chambers

      Hi All, just a quick one - How can I change the font type and size that is used to display text in a combo box? At the moment my MDI App has one located in the MainFrame toolbar, but because the Arial font looks so pants its made my app look as though its been designed for Windows 3.x. Please help make my app look better, Cheers Guys, Alan.:-D "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

      N Offline
      N Offline
      Nemanja Trifunovic
      wrote on last edited by
      #2

      Just as with any other window: void CWnd::SetFont( CFont* pFont, BOOL bRedraw = TRUE ); I vote pro drink :beer:

      C 1 Reply Last reply
      0
      • N Nemanja Trifunovic

        Just as with any other window: void CWnd::SetFont( CFont* pFont, BOOL bRedraw = TRUE ); I vote pro drink :beer:

        C Offline
        C Offline
        Chambers
        wrote on last edited by
        #3

        Thanks for the response, however, I have inevitably reached a problem and my efforts have gone to no avail, please help. This is the code that has resulted from my patheticness in an attempt to get it going :

        int CMainFrame::OnCreate(etc..)

        //Toolbar definition.

        stdFont.CreateFont(25,12,10,10,FW_THIN,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_OUTLINE_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,0,"Times New Roman");
        SetFont(&stdFont, TRUE);

        //ComboBox setup and displaying code.

        Can you see where I`m going wrong with this? I`ve tried different values for the third and forth arguments, but the combo box still uses the same crappy font to display the strings!!! Also I have checked the return value of the CreateFont function and its 1, so it must be doing something? Any advice on my failings would be hugely welcomed. Thanks again, Alan.:confused: "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

        D 1 Reply Last reply
        0
        • C Chambers

          Thanks for the response, however, I have inevitably reached a problem and my efforts have gone to no avail, please help. This is the code that has resulted from my patheticness in an attempt to get it going :

          int CMainFrame::OnCreate(etc..)

          //Toolbar definition.

          stdFont.CreateFont(25,12,10,10,FW_THIN,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_OUTLINE_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,0,"Times New Roman");
          SetFont(&stdFont, TRUE);

          //ComboBox setup and displaying code.

          Can you see where I`m going wrong with this? I`ve tried different values for the third and forth arguments, but the combo box still uses the same crappy font to display the strings!!! Also I have checked the return value of the CreateFont function and its 1, so it must be doing something? Any advice on my failings would be hugely welcomed. Thanks again, Alan.:confused: "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

          D Offline
          D Offline
          Derek Waters
          wrote on last edited by
          #4

          Is stdFont defined locally to the OnCreate function, or is a member variable? If it's defined locally, then when OnCreate finishes, the CFont object is destroyed, so you end up with the crappy default font. I don't know if this is the problem, but I know I've done this a lot of times! ------------------------ Derek Waters derek@lj-oz.com

          C 1 Reply Last reply
          0
          • D Derek Waters

            Is stdFont defined locally to the OnCreate function, or is a member variable? If it's defined locally, then when OnCreate finishes, the CFont object is destroyed, so you end up with the crappy default font. I don't know if this is the problem, but I know I've done this a lot of times! ------------------------ Derek Waters derek@lj-oz.com

            C Offline
            C Offline
            Chambers
            wrote on last edited by
            #5

            I found the answer, at last. I had been changing the MainFrame's standard font, and it was not being reflected in the combo box. As soon as I changed my code to m_ctlCombo.SetFont(&stdFont, TRUE), it worked! amazing! Many thanks to those of you who offered their advice on this, I very much appreciate it. Cheers, Alan. "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

            L 1 Reply Last reply
            0
            • C Chambers

              I found the answer, at last. I had been changing the MainFrame's standard font, and it was not being reflected in the combo box. As soon as I changed my code to m_ctlCombo.SetFont(&stdFont, TRUE), it worked! amazing! Many thanks to those of you who offered their advice on this, I very much appreciate it. Cheers, Alan. "When I left you I was but the learner, now I am the Master" - Darth Vader:mad:

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Here's some code for changing the font in a combobox... LOGFONT lf = { 0 }; (void)lstrcpy( lf.lfFaceName, _T("MS Sans Serif") ); lf.lfHeight = -MulDiv( 10, GetDeviceCaps( GetDC()->m_hDC, LOGPIXELSY ), 72 ); VERIFY( m_font.CreateFontIndirect( &lf ) ); m_ctlCombo.SetFont( &m_font ); Best regards, Mark www.mjsoft.co.uk

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups