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 make a derived CEdit more perfect?

How to make a derived CEdit more perfect?

Scheduled Pinned Locked Moved C / C++ / MFC
helphostingcloudtutorialquestion
9 Posts 2 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.
  • W Offline
    W Offline
    whiteclouds
    wrote on last edited by
    #1

    Hi all! I meet a problem when I derive a class from CEdit. I want to use a font specficed by myself in it. Now I use the font in the message function of WM_CTLCOLOR in parent window of CEdit. The new font can be shown in CEdit. But when I double click the left-button or drag the mouse to select more than one character, the position of caret is wrong. I don't know how to fix it. Plz help me! Thx! whiteclouds

    There is some white cloud floating on the blue sky. That's the landscape I like.

    E 1 Reply Last reply
    0
    • W whiteclouds

      Hi all! I meet a problem when I derive a class from CEdit. I want to use a font specficed by myself in it. Now I use the font in the message function of WM_CTLCOLOR in parent window of CEdit. The new font can be shown in CEdit. But when I double click the left-button or drag the mouse to select more than one character, the position of caret is wrong. I don't know how to fix it. Plz help me! Thx! whiteclouds

      There is some white cloud floating on the blue sky. That's the landscape I like.

      E Offline
      E Offline
      Eugen Podsypalnikov
      wrote on last edited by
      #2

      Have you already tried to set a font at the WM_CREATE reaction ? :)

      virtual void BeHappy() = 0;

      W 1 Reply Last reply
      0
      • E Eugen Podsypalnikov

        Have you already tried to set a font at the WM_CREATE reaction ? :)

        virtual void BeHappy() = 0;

        W Offline
        W Offline
        whiteclouds
        wrote on last edited by
        #3

        In WM_CREATE of CEdit? What difference between this and the action I take?

        There is some white cloud floating on the blue sky. That's the landscape I like.

        E 1 Reply Last reply
        0
        • W whiteclouds

          In WM_CREATE of CEdit? What difference between this and the action I take?

          There is some white cloud floating on the blue sky. That's the landscape I like.

          E Offline
          E Offline
          Eugen Podsypalnikov
          wrote on last edited by
          #4

          I think, the difference is the settings purpose: - your choice: the drawing (I guess, not in the edit mode) - my choice: system assignment (I guess, for drawing and editing as well) When you will want to use the class for a dialog item, you could place the setting in your OnInitDialog() function :) :

          ...
          m_cYourEdit.SetFont(..); // the font could be a static member in your class
          ...

          virtual void BeHappy() = 0;

          W 1 Reply Last reply
          0
          • E Eugen Podsypalnikov

            I think, the difference is the settings purpose: - your choice: the drawing (I guess, not in the edit mode) - my choice: system assignment (I guess, for drawing and editing as well) When you will want to use the class for a dialog item, you could place the setting in your OnInitDialog() function :) :

            ...
            m_cYourEdit.SetFont(..); // the font could be a static member in your class
            ...

            virtual void BeHappy() = 0;

            W Offline
            W Offline
            whiteclouds
            wrote on last edited by
            #5

            I had test your method. I add some codes into OnInitDialog() of parent window as below:

            CColorEdit \*pEdit = (CColorEdit\*)GetDlgItem(IDC\_ED\_COLOR);
            if(pEdit)
            {
            	CDC \*pDC = pEdit->GetDC();
            	if(pDC)
            	{
            		pDC->SelectObject(m\_fnt);
            	}
            }
            

            Then m_fnt can't be shown. And when I select some characters, the caret isn't in correct position. :(

            There is some white cloud floating on the blue sky. That's the landscape I like.

            E 1 Reply Last reply
            0
            • W whiteclouds

              I had test your method. I add some codes into OnInitDialog() of parent window as below:

              CColorEdit \*pEdit = (CColorEdit\*)GetDlgItem(IDC\_ED\_COLOR);
              if(pEdit)
              {
              	CDC \*pDC = pEdit->GetDC();
              	if(pDC)
              	{
              		pDC->SelectObject(m\_fnt);
              	}
              }
              

              Then m_fnt can't be shown. And when I select some characters, the caret isn't in correct position. :(

              There is some white cloud floating on the blue sky. That's the landscape I like.

              E Offline
              E Offline
              Eugen Podsypalnikov
              wrote on last edited by
              #6

              Try it :) :

              CWnd* pcWnd = GetDlgItem(IDC_ED_COLOR);
              if (pcWnd->GetSafeHwnd()) {
              pcWnd->SetFont(&m_cFont); // Please note:
              // the member CFont m_cFont
              // has been already created !
              }

              virtual void BeHappy() = 0;

              W 1 Reply Last reply
              0
              • E Eugen Podsypalnikov

                Try it :) :

                CWnd* pcWnd = GetDlgItem(IDC_ED_COLOR);
                if (pcWnd->GetSafeHwnd()) {
                pcWnd->SetFont(&m_cFont); // Please note:
                // the member CFont m_cFont
                // has been already created !
                }

                virtual void BeHappy() = 0;

                W Offline
                W Offline
                whiteclouds
                wrote on last edited by
                #7

                Thx for your reply! :) The position of caret is right now. But the font isn't be used in general. Only when I select the characters, the font can work. That means, when not select any character, the OnPaint() respond function in the derived class hadn't work. Because I draw the characters using specific font in it. Maybe I make a mistake, isn't it? Pls help me more! Thx!

                There is some white cloud floating on the blue sky. That's the landscape I like.

                E 1 Reply Last reply
                0
                • W whiteclouds

                  Thx for your reply! :) The position of caret is right now. But the font isn't be used in general. Only when I select the characters, the font can work. That means, when not select any character, the OnPaint() respond function in the derived class hadn't work. Because I draw the characters using specific font in it. Maybe I make a mistake, isn't it? Pls help me more! Thx!

                  There is some white cloud floating on the blue sky. That's the landscape I like.

                  E Offline
                  E Offline
                  Eugen Podsypalnikov
                  wrote on last edited by
                  #8

                  It works in my OnInitDialog() (I have not performed any font manipulations for WM_CTLCOLOR) :) :

                  static CFont cFont; // test only
                  cFont.CreatePointFont(120, _T("Arial"));

                  CWnd* pcWnd = GetDlgItem(IDC_EDIT1);
                  if (pcWnd->GetSafeHwnd()) {
                  pcWnd->SetFont(&cFont);
                  }

                  virtual void BeHappy() = 0;

                  W 1 Reply Last reply
                  0
                  • E Eugen Podsypalnikov

                    It works in my OnInitDialog() (I have not performed any font manipulations for WM_CTLCOLOR) :) :

                    static CFont cFont; // test only
                    cFont.CreatePointFont(120, _T("Arial"));

                    CWnd* pcWnd = GetDlgItem(IDC_EDIT1);
                    if (pcWnd->GetSafeHwnd()) {
                    pcWnd->SetFont(&cFont);
                    }

                    virtual void BeHappy() = 0;

                    W Offline
                    W Offline
                    whiteclouds
                    wrote on last edited by
                    #9

                    I had test the code you provided. That can work correct. And I know that the problem was generated by my own class derived from CEdit. Thank you, Eugen Podsypalnikov!

                    There is some white cloud floating on the blue sky. That's the landscape I like.

                    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