WTL: OwnerDraw CTabView
От: insolent  
Дата: 02.08.11 11:18
Оценка:
Создаю OwnerDraw CTabView:

    class CCustomTabView : public CTabView/*CWindowImpl<CCustomTabView,CTabView>*/,
                           public COwnerDraw<CCustomTabView>
    {
    public:
        CCustomTabView() : CTabView()
        {}
        DECLARE_WND_SUPERCLASS(NULL, CTabView::GetWndClassName())
     
        BEGIN_MSG_MAP(CCustomTabView)
            MESSAGE_HANDLER(WM_CREATE, OnCreate)
            //CHAIN_MSG_MAP(CTabView)
            // Направляем сообщения в карту №1 класса COwnerDraw!
            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));
            }
        }
    };

Вот так создаю контрол:

    LRESULT CMainFrame::OnCreate(...)
    //..
        m_hWndClient = m_wndTabView.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);
    //..

Но HWND остается нулевым и вылетает ошибка по такому вызову:
CCustomTabView::OnCreate -> CCustomTabView::CreateTabControl -> CContainedWindowT::Create на

    HWND hWnd = ::CreateWindowEx(dwExStyle, MAKEINTATOM(atom), szWindowName,
                                    dwStyle,
                                    rect.m_lpRect->left, rect.m_lpRect->top,
                                    rect.m_lpRect->right - rect.m_lpRect->left,
                                    rect.m_lpRect->bottom - rect.m_lpRect->top,
                                    hWndParent, MenuOrID.m_hMenu,
                                    _AtlBaseModule.GetModuleInstance(), lpCreateParam);
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.