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. Font text on command button

Font text on command button

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
3 Posts 3 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.
  • D Offline
    D Offline
    durban2
    wrote on last edited by
    #1

    MFC, STUDIO 2008, MDI CButton m_button1; CString font(L"Courier New"); m_button1.SetFont(font,20); // error C2664: 'CWnd::SetFont' : cannot convert parameter 1 from 'const wchar_t [12]' to 'CFont *' m_button1.SetFont(L"Courier New",20); // error C2664: 'CWnd::SetFont' : cannot convert parameter 1 from 'const wchar_t [12]' to 'CFont *' 2. // How do to set BOLD FONT on button? m_button1.SetFont(L"Courier New",20,600); // error C2660: 'CWnd::SetFont' : function does not take 3 arguments Add #include "afxctl.h" class CFontHolder; // add into header file my class where is command button that I want write caption.

    S H 2 Replies Last reply
    0
    • D durban2

      MFC, STUDIO 2008, MDI CButton m_button1; CString font(L"Courier New"); m_button1.SetFont(font,20); // error C2664: 'CWnd::SetFont' : cannot convert parameter 1 from 'const wchar_t [12]' to 'CFont *' m_button1.SetFont(L"Courier New",20); // error C2664: 'CWnd::SetFont' : cannot convert parameter 1 from 'const wchar_t [12]' to 'CFont *' 2. // How do to set BOLD FONT on button? m_button1.SetFont(L"Courier New",20,600); // error C2660: 'CWnd::SetFont' : function does not take 3 arguments Add #include "afxctl.h" class CFontHolder; // add into header file my class where is command button that I want write caption.

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      Have you looked at the documentation at all? Stupid question really, 'cause you obviously haven't. Does help, though. Anyway - that has the definition for CWnd::SetFont, which is this:

      void SetFont(
      CFont* pFont,
      BOOL bRedraw = TRUE
      );

      No strings mentioned there? So, to change the font, you need to create a CFont. To do that, add a CFont data member to the class this code is in (the view?). Initialise the font with CFont::CreateFont and call m_button1.SetFont passing the address of the CFont data member.

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      1 Reply Last reply
      0
      • D durban2

        MFC, STUDIO 2008, MDI CButton m_button1; CString font(L"Courier New"); m_button1.SetFont(font,20); // error C2664: 'CWnd::SetFont' : cannot convert parameter 1 from 'const wchar_t [12]' to 'CFont *' m_button1.SetFont(L"Courier New",20); // error C2664: 'CWnd::SetFont' : cannot convert parameter 1 from 'const wchar_t [12]' to 'CFont *' 2. // How do to set BOLD FONT on button? m_button1.SetFont(L"Courier New",20,600); // error C2660: 'CWnd::SetFont' : function does not take 3 arguments Add #include "afxctl.h" class CFontHolder; // add into header file my class where is command button that I want write caption.

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

        First of all you can see parameters of functions on your code you need to make this font(Courier New) for it you can use of CreateFont/CFont class and then you can use of it of the SetFont much as you are new to VC++ you can read error message(Can not convert to CFont*) so you can think its parameter is CFont not CString.

        Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )

        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