我用浏览器风格创建了一个单文档程序,右边是CListView;用SetImageList()设置了图表列表,启动程序可以正确显示图标,然后增加一个按钮,单击此按钮,右边将删除CLiewView,创建一个新的View;但是当我又返回到CListView时,却不能显示图标,为什么?

解决方案 »

  1.   

    1.如何切换视口而不破坏它们?
    我创建了一个带有静态分隔区的sdi应用程序,左边显示工作区,右过显示左边选取
    的东西.我想达到的是如果在分隔区之间进行切换,而不覆盖或破坏原来的CView对象.
    A:以下代码是你所想要的:
    class CExSplitterWnd : public CSplitterWnd
    {
    // Construction
    public:
        CExSplitterWnd();
    // Overrides
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CExSplitterWnd)
        //}}AFX_VIRTUAL
    // Implementation
        virtual ~CExSplitterWnd();
        BOOL AttachView(CWnd* pView, int row, int col);
        BOOL DetachView(int row, int col);
        // Generated message map functions
        //{{AFX_MSG(CExSplitterWnd)
            // NOTE - the ClassWizard will add and remove member functions here.
        //}}AFX_MSG
        DECLARE_MESSAGE_MAP()
    };CExSplitterWnd::CExSplitterWnd()
    {
    }CExSplitterWnd::~CExSplitterWnd()
    {
    }BOOL CExSplitterWnd::AttachView(CWnd* pView, int row, int col)
    {
        //Make sure the splitter window was created
        if (!IsWindow(m_hWnd))
        {
            ASSERT(0);
            TRACE(_T("Create the splitter window before attaching windows to panes"));
            return (FALSE);
        }    //Make sure the row and col indices are within bounds
        if (row >= GetRowCount() || col >= GetColumnCount())
        {
            ASSERT(0);
            return FALSE;
        }    //Is the window to be attached a valid one
        if (pView == NULL || (!IsWindow(pView->m_hWnd)))
        {
            ASSERT(0);
            return FALSE;
        }    pView->SetDlgCtrlID(IdFromRowCol(row, col));
        pView->SetParent(this);
        pView->ShowWindow(SW_SHOW);
        pView->UpdateWindow();
        return (TRUE);
    }BOOL CExSplitterWnd::DetachView(int row, int col)
    {
        //Make sure the splitter window was created
        if (!IsWindow(m_hWnd))
        {
            ASSERT(0);
            TRACE(_T("Create the splitter window before attaching windows to panes"));
            return (FALSE);
        }    //Make sure the row and col indices are
        //within bounds
        if (row >= GetRowCount() || col >= GetColumnCount())
        {
            ASSERT(0);
            return FALSE;
        }    CWnd* pWnd = GetPane(row, col);
        if (pWnd == NULL || (!IsWindow(pWnd->m_hWnd)))
        {
            ASSERT(0);
            return FALSE;
        }
        pWnd->ShowWindow(SW_HIDE);
        pWnd->UpdateWindow();    //Set the parent window handle to NULL so that this child window is not
        //destroyed when the parent (splitter) is destroyed
        pWnd->SetParent(NULL);
        return (TRUE);
    }
      

  2.   

    创建的新的VIEW不是CListView的子类,而是一个普通的CView的子类。
    在新的CView的子类显示图像。
    切换回CListView的子类的时候,无法显示图标。