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. WM_DRAWITEM does not process for tab control

WM_DRAWITEM does not process for tab control

Scheduled Pinned Locked Moved C / C++ / MFC
18 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.
  • M Mark Salsbery

    Where are you handling WM_DRAWITEM? What about overriding CTabCtrl::DrawItem() in your tab control class? Mark

    Mark Salsbery Microsoft MVP - Visual C++ :java:

    Y Offline
    Y Offline
    yaminisridaran
    wrote on last edited by
    #5

    The execution does not come to drawitem method. Why

    M 1 Reply Last reply
    0
    • Y yaminisridaran

      The execution does not come to drawitem method. Why

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #6

      The following code works for me... Note you have to have a tab control subclassed by an object of your CTabCtrl-derived class, otherwise DrawItem() will never get called...

      class CMyTabCtrl : public CTabCtrl
      {
      public:
      CMyTabCtrl() : CTabCtrl() {}

      virtual void DrawItem(LPDRAWITEMSTRUCT /\*lpDrawItemStruct\*/);
      

      };

      void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
      {
      CDC dc;
      dc.Attach(lpDrawItemStruct->hDC);

      // Note:  My test tab control has two tabs inserted :)
      
      if (0 == lpDrawItemStruct->itemID)
          dc.DrawText(\_T("Tab 1"), &lpDrawItemStruct->rcItem, DT\_CENTER);
      else
          dc.DrawText(\_T("Tab 2"), &lpDrawItemStruct->rcItem, DT\_CENTER);
      
      dc.Detach();
      

      }

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      Y 2 Replies Last reply
      0
      • M Mark Salsbery

        The following code works for me... Note you have to have a tab control subclassed by an object of your CTabCtrl-derived class, otherwise DrawItem() will never get called...

        class CMyTabCtrl : public CTabCtrl
        {
        public:
        CMyTabCtrl() : CTabCtrl() {}

        virtual void DrawItem(LPDRAWITEMSTRUCT /\*lpDrawItemStruct\*/);
        

        };

        void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
        {
        CDC dc;
        dc.Attach(lpDrawItemStruct->hDC);

        // Note:  My test tab control has two tabs inserted :)
        
        if (0 == lpDrawItemStruct->itemID)
            dc.DrawText(\_T("Tab 1"), &lpDrawItemStruct->rcItem, DT\_CENTER);
        else
            dc.DrawText(\_T("Tab 2"), &lpDrawItemStruct->rcItem, DT\_CENTER);
        
        dc.Detach();
        

        }

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        Y Offline
        Y Offline
        yaminisridaran
        wrote on last edited by
        #7

        Thanks for ur help I created a dialog based application. I selected a tab control and moved to my dialog . I have created an MFC class named CMyTabCtrl derived from CTabCtrl. I added ur code to it. I created a member variable in the dialog class for the tab control using class wizard which is CMyTabCtrl m_Tab I have selected the owner draw fixed properties But still the drawitem of CMyTabCtrl does not called. Please implement this and if u r getting let me know what u did.

        M 1 Reply Last reply
        0
        • Y yaminisridaran

          Thanks for ur help I created a dialog based application. I selected a tab control and moved to my dialog . I have created an MFC class named CMyTabCtrl derived from CTabCtrl. I added ur code to it. I created a member variable in the dialog class for the tab control using class wizard which is CMyTabCtrl m_Tab I have selected the owner draw fixed properties But still the drawitem of CMyTabCtrl does not called. Please implement this and if u r getting let me know what u did.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #8

          I did the same - I used a DDX_Control() call in DoDataExchange() to subclass the control...

          void CMyDialog::DoDataExchange(CDataExchange* pDX)
          {
          CDialog::DoDataExchange(pDX);
          DDX_Control(pDX, IDC_TAB1, m_Tab); <-- make sure you use the right ID!!!
          }

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          Y 1 Reply Last reply
          0
          • M Mark Salsbery

            I did the same - I used a DDX_Control() call in DoDataExchange() to subclass the control...

            void CMyDialog::DoDataExchange(CDataExchange* pDX)
            {
            CDialog::DoDataExchange(pDX);
            DDX_Control(pDX, IDC_TAB1, m_Tab); <-- make sure you use the right ID!!!
            }

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            Y Offline
            Y Offline
            yaminisridaran
            wrote on last edited by
            #9

            I have done that. But still does not work Can u send me ur sample project.

            M 1 Reply Last reply
            0
            • Y yaminisridaran

              I have done that. But still does not work Can u send me ur sample project.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #10

              It's a VS2008 project - is that OK?

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              Y 1 Reply Last reply
              0
              • M Mark Salsbery

                It's a VS2008 project - is that OK?

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                Y Offline
                Y Offline
                yaminisridaran
                wrote on last edited by
                #11

                ok

                1 Reply Last reply
                0
                • M Mark Salsbery

                  The following code works for me... Note you have to have a tab control subclassed by an object of your CTabCtrl-derived class, otherwise DrawItem() will never get called...

                  class CMyTabCtrl : public CTabCtrl
                  {
                  public:
                  CMyTabCtrl() : CTabCtrl() {}

                  virtual void DrawItem(LPDRAWITEMSTRUCT /\*lpDrawItemStruct\*/);
                  

                  };

                  void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
                  {
                  CDC dc;
                  dc.Attach(lpDrawItemStruct->hDC);

                  // Note:  My test tab control has two tabs inserted :)
                  
                  if (0 == lpDrawItemStruct->itemID)
                      dc.DrawText(\_T("Tab 1"), &lpDrawItemStruct->rcItem, DT\_CENTER);
                  else
                      dc.DrawText(\_T("Tab 2"), &lpDrawItemStruct->rcItem, DT\_CENTER);
                  
                  dc.Detach();
                  

                  }

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  Y Offline
                  Y Offline
                  yaminisridaran
                  wrote on last edited by
                  #12

                  Am I doing anything wrong in setting the properties of the tab control. Shall I send the sample code.

                  M 1 Reply Last reply
                  0
                  • Y yaminisridaran

                    Am I doing anything wrong in setting the properties of the tab control. Shall I send the sample code.

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #13

                    It seems like you're doing everything.... Send me an email from here and I'll reply with the project. Mark

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    Y 2 Replies Last reply
                    0
                    • M Mark Salsbery

                      It seems like you're doing everything.... Send me an email from here and I'll reply with the project. Mark

                      Mark Salsbery Microsoft MVP - Visual C++ :java:

                      Y Offline
                      Y Offline
                      yaminisridaran
                      wrote on last edited by
                      #14

                      I am waiting for ur reply

                      1 Reply Last reply
                      0
                      • M Mark Salsbery

                        It seems like you're doing everything.... Send me an email from here and I'll reply with the project. Mark

                        Mark Salsbery Microsoft MVP - Visual C++ :java:

                        Y Offline
                        Y Offline
                        yaminisridaran
                        wrote on last edited by
                        #15

                        It works now when i call insert item Thanks

                        M 1 Reply Last reply
                        0
                        • Y yaminisridaran

                          It works now when i call insert item Thanks

                          M Offline
                          M Offline
                          Mark Salsbery
                          wrote on last edited by
                          #16

                          Ohhh you had no tabs :) I guess the email through CodeProject isn't working yet....I sent one so I could get your address to send the project. Glad you got it working! Mark

                          Mark Salsbery Microsoft MVP - Visual C++ :java:

                          Y 1 Reply Last reply
                          0
                          • M Mark Salsbery

                            Ohhh you had no tabs :) I guess the email through CodeProject isn't working yet....I sent one so I could get your address to send the project. Glad you got it working! Mark

                            Mark Salsbery Microsoft MVP - Visual C++ :java:

                            Y Offline
                            Y Offline
                            yaminisridaran
                            wrote on last edited by
                            #17

                            Thanks for ur support

                            M 1 Reply Last reply
                            0
                            • Y yaminisridaran

                              Thanks for ur support

                              M Offline
                              M Offline
                              Mark Salsbery
                              wrote on last edited by
                              #18

                              You're welcome!

                              Mark Salsbery Microsoft MVP - Visual C++ :java:

                              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