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. How to change the font of a button's caption in MFC

How to change the font of a button's caption in MFC

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tutorialquestion
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.
  • E Offline
    E Offline
    Eikthrynir
    wrote on last edited by
    #1

    Hi! Could anyone help me change the font of a button's caption/text in MFC? The button is created with the modal frame style. The problem is that when I try to modify the caption's font, the application crashes. The code which creates the button is:m_wndButton.CreateEx( WS_EX_DLGMODALFRAME, _T( "Button" ), _T( "Test button" ), WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON, CRect( 100, 100, 190, 140 ), &m_wndView, 1, NULL );
    m_wndButton is the CButton object I'm trying to modify. Can anybody give me a hint? Thanks in advance!

    D L H 3 Replies Last reply
    0
    • E Eikthrynir

      Hi! Could anyone help me change the font of a button's caption/text in MFC? The button is created with the modal frame style. The problem is that when I try to modify the caption's font, the application crashes. The code which creates the button is:m_wndButton.CreateEx( WS_EX_DLGMODALFRAME, _T( "Button" ), _T( "Test button" ), WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON, CRect( 100, 100, 190, 140 ), &m_wndView, 1, NULL );
      m_wndButton is the CButton object I'm trying to modify. Can anybody give me a hint? Thanks in advance!

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Do you really need to create the button dynamically?


      "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

      "Judge not by the eye but by the heart." - Native American Proverb

      E 1 Reply Last reply
      0
      • D David Crow

        Do you really need to create the button dynamically?


        "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

        "Judge not by the eye but by the heart." - Native American Proverb

        E Offline
        E Offline
        Eikthrynir
        wrote on last edited by
        #3

        The application I am developing is Single Document (SDI). I do not have a dialog which can be modified at design time. The only dialog of this kind is the AboutBox. The button which I am trying to modify is contained on the main frame. It's on the child view exactly. I have no other choice (in my opinion), than to dynamically create the button.

        1 Reply Last reply
        0
        • E Eikthrynir

          Hi! Could anyone help me change the font of a button's caption/text in MFC? The button is created with the modal frame style. The problem is that when I try to modify the caption's font, the application crashes. The code which creates the button is:m_wndButton.CreateEx( WS_EX_DLGMODALFRAME, _T( "Button" ), _T( "Test button" ), WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON, CRect( 100, 100, 190, 140 ), &m_wndView, 1, NULL );
          m_wndButton is the CButton object I'm trying to modify. Can anybody give me a hint? Thanks in advance!

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          m_wndButton.SetFont( &m_buttonFont); where m_buttonFont is a CFont object declared in the View object and intialized to whatever font you desire or whatever.

          led mike

          E 1 Reply Last reply
          0
          • L led mike

            m_wndButton.SetFont( &m_buttonFont); where m_buttonFont is a CFont object declared in the View object and intialized to whatever font you desire or whatever.

            led mike

            E Offline
            E Offline
            Eikthrynir
            wrote on last edited by
            #5

            Thanks a lot!!! It finally works! The only thing that was wrong was the declaration of the CFont object: instead of declaring it in the CMainFrame class, it was declared in the same method the button was created in.

            1 Reply Last reply
            0
            • E Eikthrynir

              Hi! Could anyone help me change the font of a button's caption/text in MFC? The button is created with the modal frame style. The problem is that when I try to modify the caption's font, the application crashes. The code which creates the button is:m_wndButton.CreateEx( WS_EX_DLGMODALFRAME, _T( "Button" ), _T( "Test button" ), WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON, CRect( 100, 100, 190, 140 ), &m_wndView, 1, NULL );
              m_wndButton is the CButton object I'm trying to modify. Can anybody give me a hint? Thanks in advance!

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              Whats error?

              _**


              **_

              WhiteSky


              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