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. Derived class OnPaint() question

Derived class OnPaint() question

Scheduled Pinned Locked Moved C / C++ / MFC
questiontestingbeta-testinglearning
7 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.
  • J Offline
    J Offline
    J B 0
    wrote on last edited by
    #1

    Hi guys, I am creating a CEdit derived class and I notice the overriden OnPaint() will not get called if I don't use Create() to create the control. If I draw a CEdit control on my dialog from Resource Editor and uses it by a pointer (assuming the CEdit derived class is CMyEdit:

    	pMyEdit = (CMyEdit *)GetDlgItem(IDC_MY_EDIT);
    	pMyEdit->SetFont(&editFont, TRUE);
    	pMyEdit->SetWindowText(_T("Testing"));
    

    the OnPaint() is never called. But the following will do:

    	pMyEdit->Create(dwStyle, Rect, this, IDC_MY_EDIT);
    

    Why is that? What does it mean when a control has been created from the resource editor, compared to created manually in the code? Also, is there a member function for CEdit that can be overriden to let redraw of only the content (text) and background colour? Pretty much the same as DrawItem() for CListCtrl. Thanks alot

    V 1 Reply Last reply
    0
    • J J B 0

      Hi guys, I am creating a CEdit derived class and I notice the overriden OnPaint() will not get called if I don't use Create() to create the control. If I draw a CEdit control on my dialog from Resource Editor and uses it by a pointer (assuming the CEdit derived class is CMyEdit:

      	pMyEdit = (CMyEdit *)GetDlgItem(IDC_MY_EDIT);
      	pMyEdit->SetFont(&editFont, TRUE);
      	pMyEdit->SetWindowText(_T("Testing"));
      

      the OnPaint() is never called. But the following will do:

      	pMyEdit->Create(dwStyle, Rect, this, IDC_MY_EDIT);
      

      Why is that? What does it mean when a control has been created from the resource editor, compared to created manually in the code? Also, is there a member function for CEdit that can be overriden to let redraw of only the content (text) and background colour? Pretty much the same as DrawItem() for CListCtrl. Thanks alot

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      The two member functions SetFont() and SetWindowText() send different messages to the edit window rather than WM_PAINT. For example, SetWindowText() sends WM_SETTEXT. You can override OnDraw() in the edit view. Kuphryn

      J 1 Reply Last reply
      0
      • V valikac

        The two member functions SetFont() and SetWindowText() send different messages to the edit window rather than WM_PAINT. For example, SetWindowText() sends WM_SETTEXT. You can override OnDraw() in the edit view. Kuphryn

        J Offline
        J Offline
        J B 0
        wrote on last edited by
        #3

        Thanks kuphryn, So it seems that for CEdit control not all display related operations will go through WM_PAINT (i.e. in MFC, OnPaint()) at the end. I found it a bit odd: using different ways when they all lead to the CEdit control's display needing to be refreshed eventually. I happened to find this post[^] which the guy asks exactly what I was looking. The control is the CEdit type, so I won't be able to overriding OnDraw(). I need something that has the appearance and functionalities of the CEdit and which then I can have/create a general function to customise its output(display) content (e.g. text, background colours), once for all. Thanks.

        V 1 Reply Last reply
        0
        • J J B 0

          Thanks kuphryn, So it seems that for CEdit control not all display related operations will go through WM_PAINT (i.e. in MFC, OnPaint()) at the end. I found it a bit odd: using different ways when they all lead to the CEdit control's display needing to be refreshed eventually. I happened to find this post[^] which the guy asks exactly what I was looking. The control is the CEdit type, so I won't be able to overriding OnDraw(). I need something that has the appearance and functionalities of the CEdit and which then I can have/create a general function to customise its output(display) content (e.g. text, background colours), once for all. Thanks.

          V Offline
          V Offline
          valikac
          wrote on last edited by
          #4

          It is possible to override OnDraw() in an edit view. What type of CEdit object is it? Kuphryn

          J 1 Reply Last reply
          0
          • V valikac

            It is possible to override OnDraw() in an edit view. What type of CEdit object is it? Kuphryn

            J Offline
            J Offline
            J B 0
            wrote on last edited by
            #5

            Hi Kuphryn, I creat and use the CEdit control from the resource view, it's Edit Control by the name. I'd use a CEdit derived class with it, like in my original post. And I'm hoping to handle the text content painting operation myself. I looked on MSDN and I couldn't find possible OnDraw() for CEdit, can you kindly give me an example? Thanks again.

            V 1 Reply Last reply
            0
            • J J B 0

              Hi Kuphryn, I creat and use the CEdit control from the resource view, it's Edit Control by the name. I'd use a CEdit derived class with it, like in my original post. And I'm hoping to handle the text content painting operation myself. I looked on MSDN and I couldn't find possible OnDraw() for CEdit, can you kindly give me an example? Thanks again.

              V Offline
              V Offline
              valikac
              wrote on last edited by
              #6

              Okay. In that case, add a message handler to WM_PAINT in the CEdit subclass. Kuphryn

              J 1 Reply Last reply
              0
              • V valikac

                Okay. In that case, add a message handler to WM_PAINT in the CEdit subclass. Kuphryn

                J Offline
                J Offline
                J B 0
                wrote on last edited by
                #7

                Hi Kuphryn, perhaps my original post wasn't not clear. That's exactly what I was doing in the first place, to add the WM_PAINT handler by overriding OnPaint() in the sub-class. The problem I am having is that OnPaint() is never called if I use the sub-class directly with the control I created from the resource view. But if I explicitly create the control in run-time using Create(), OnPant() gets called no problem. You can look my first post for the example. Thanks.

                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