Loading ...
Sorry, an error occurred while loading the content.

OwnerDraw CTabView

Expand Messages
  • ivan.ivanov510
    I want to display the tabs icon with different color font. I created my class, but there were problems.class CCustomTabView : public
    Message 1 of 2 , Aug 2, 2011
    View Source
    • 0 Attachment
      I want to display the tabs icon with different color font. I created my
      class, but there were problems.class CCustomTabView : public
      CTabView/*CWindowImpl<CCustomTabView,CTabView>*/, public
      COwnerDraw<CCustomTabView>{public: BEGIN_MSG_MAP(CCustomTabView)
      MESSAGE_HANDLER(WM_CREATE, OnCreate) //CHAIN_MSG_MAP(CTabView)
      CHAIN_MSG_MAP_ALT(COwnerDraw<CCustomTabView>, 1)
      REFLECT_NOTIFICATIONS() END_MSG_MAP()
      HBRUSH hBr; UINT bkColor;
      LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
      bHandled) { CreateTabControl(); return 0; }
      bool CreateTabControl() { m_tab.Create(m_hWnd, rcDefault, NULL,
      WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_TOOLTIPS, 0,
      m_nTabID); ATLASSERT(m_tab.m_hWnd != NULL); if(m_tab.m_hWnd == NULL)
      return false;
      m_tab.SetFont(AtlGetDefaultGuiFont());
      m_tab.SetItemExtra(sizeof(TABVIEWPAGE));
      m_cyTabHeight = this->CalcTabHeight();
      return true; }
      void DrawItem(LPDRAWITEMSTRUCT pDS) { LPDRAWITEMSTRUCT lpdis =
      pDS/*(LPDRAWITEMSTRUCT) lParam*/; // item drawing information
      if ( m_hWnd == lpdis->hwndItem) // is this the tab control? { hBr =
      CreateSolidBrush(RGB(255, 0, 0)); bkColor = RGB(0, 0, 255);
      int cchBuff = 100; LPTSTR szTabText = NULL; ATLTRY(szTabText = new
      TCHAR[cchBuff]); if(szTabText == NULL) return;
      SecureHelper::strcpy_x(szTabText, cchBuff, _T(""));
      TCITEMEXTRA tcix = { 0 }; tcix.tciheader.mask = TCIF_PARAM;
      tcix.tciheader.pszText = szTabText; tcix.tciheader.cchTextMax =
      sizeof(szTabText)-1;
      if(m_tab.GetItem(lpdis->itemID, tcix) == FALSE) return;
      FillRect(lpdis->hDC, &lpdis->rcItem, hBr); SetBkColor(lpdis->hDC,
      bkColor);
      TextOut(lpdis->hDC, lpdis->rcItem.left, lpdis->rcItem.top,
      tcix.tciheader.pszText, lstrlen(tcix.tciheader.pszText)); } }};The
      object not created. Calls: CCustomTabView::OnCreate ->
      CCustomTabView::CreateTabControl -> CWindowImplBaseT::Create Debug error
      Expression::IsWindow(m_hWnd) in atlwin.h CWindowImplBaseT< .. >::Create
      after HWND hWnd = ::CreateWindowEx(..)


      [Non-text portions of this message have been removed]
    • domehead100
      I might suggest a slightly different approach. I just uploaded a file to the group, TabView2.h. This is a slight tweak of the tab view to allow an additional
      Message 2 of 2 , Aug 10, 2011
      View Source
      • 0 Attachment
        I might suggest a slightly different approach. I just uploaded a file to the group, TabView2.h. This is a slight tweak of the tab view to allow an additional template parameter for the tab control class itself (defaults to CTabCtrl).

        This allows one to write customized self-contained tab control classes, such as ones that look different, and swap them into the tab view without having to wire anything else up.

        Hope this helps.

        ~Mike

        --- In wtl@yahoogroups.com, "ivan.ivanov510" <ivan.ivanov510@...> wrote:
        >
        > I want to display the tabs icon with different color font. I created my
        > class, but there were problems...
      Your message has been successfully submitted and would be delivered to recipients shortly.