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. Set font Courier for Edit box (VC++6.0) ???

Set font Courier for Edit box (VC++6.0) ???

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
4 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.
  • A Offline
    A Offline
    aa_zz
    wrote on last edited by
    #1

    hi everybody. I need data in edit box : 5 line, 1 line max = 50 characters. then I must set font Courier for Edit box. i using code: ... ::OnInitDialog() { CFont m_Font; VERIFY(m_Font.CreateFont( 12, // nHeight 0, // nWidth 0, // nEscapement 0, // nOrientation FW_NORMAL, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily "Courier")); // lpszFacename CWnd *pWnd = GetDlgItem(IDC_MESSAGE_TEXT); pWnd->SetFont(&m_Font); m_Font.DeleteObject(); ... } =>Data in Edit text is Bold. When I using mouse to choice this Edit text , it show text wrong. seem, it need control of mouse. for example: show text wrong when type : "y" or "g", it have lost under. i wish you help me. thanks very much. **) when using all character UPPER ==> 1 line don't show 50 character. hope your help. thanks very much regards

    nothing

    H 1 Reply Last reply
    0
    • A aa_zz

      hi everybody. I need data in edit box : 5 line, 1 line max = 50 characters. then I must set font Courier for Edit box. i using code: ... ::OnInitDialog() { CFont m_Font; VERIFY(m_Font.CreateFont( 12, // nHeight 0, // nWidth 0, // nEscapement 0, // nOrientation FW_NORMAL, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily "Courier")); // lpszFacename CWnd *pWnd = GetDlgItem(IDC_MESSAGE_TEXT); pWnd->SetFont(&m_Font); m_Font.DeleteObject(); ... } =>Data in Edit text is Bold. When I using mouse to choice this Edit text , it show text wrong. seem, it need control of mouse. for example: show text wrong when type : "y" or "g", it have lost under. i wish you help me. thanks very much. **) when using all character UPPER ==> 1 line don't show 50 character. hope your help. thanks very much regards

      nothing

      H Offline
      H Offline
      Hans Dietrich
      wrote on last edited by
      #2

      First, m_Font needs to persist - you have declared it on stack, therefore it will be destroyed when OnInitDialog() exits. Make it a class variable. Second, if all you're trying to do is limit the text to 50 characters, you can use pWnd->SetLimitText(50) on the edit box. No need to change the font.

      Best wishes, Hans


      [Hans Dietrich Software]

      M 1 Reply Last reply
      0
      • H Hans Dietrich

        First, m_Font needs to persist - you have declared it on stack, therefore it will be destroyed when OnInitDialog() exits. Make it a class variable. Second, if all you're trying to do is limit the text to 50 characters, you can use pWnd->SetLimitText(50) on the edit box. No need to change the font.

        Best wishes, Hans


        [Hans Dietrich Software]

        M Offline
        M Offline
        Michael Schubert
        wrote on last edited by
        #3

        Hans Dietrich wrote:

        First, m_Font needs to persist

        Not necessarily, I have been using this for years (usually in OnInitDialog):

        CFont f1;
        LOGFONT lf1;
        ::ZeroMemory(&lf1, sizeof(lf1));
        lf1.lfHeight = 14;
        lf1.lfCharSet = ANSI_CHARSET;
        lf1.lfWeight = FW_BOLD;
        ::lstrcpy(lf1.lfFaceName, "Verdana");
        f1.CreateFontIndirect(&lf1);
        GetDlgItem(IDC_STATUS)->SetFont(&f1);
        f1.Detach();

        modified on Monday, October 5, 2009 1:06 PM

        A 1 Reply Last reply
        0
        • M Michael Schubert

          Hans Dietrich wrote:

          First, m_Font needs to persist

          Not necessarily, I have been using this for years (usually in OnInitDialog):

          CFont f1;
          LOGFONT lf1;
          ::ZeroMemory(&lf1, sizeof(lf1));
          lf1.lfHeight = 14;
          lf1.lfCharSet = ANSI_CHARSET;
          lf1.lfWeight = FW_BOLD;
          ::lstrcpy(lf1.lfFaceName, "Verdana");
          f1.CreateFontIndirect(&lf1);
          GetDlgItem(IDC_STATUS)->SetFont(&f1);
          f1.Detach();

          modified on Monday, October 5, 2009 1:06 PM

          A Offline
          A Offline
          aa_zz
          wrote on last edited by
          #4

          thanks everybody very much. thanks Hans Dietrich and Michael Schubert Michael Schubert answer very good :thumbsup:.

          nothing

          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