我把图标依次加入到CListCtrl上,我现在想把图标调整顺序,我应如何做啊?请各位多多指教,谢谢了.

解决方案 »

  1.   

    什么意思,行图标还是列图标
    行设置LVITEM的subImage就行吧
      

  2.   

    TVITEM::iImage   iSelectedImage
      

  3.   

    你原来怎么调整的,重新调整就不会了?
    不知道你要怎么调整了...... /************ 添加列表控件项 **************/
    /*
    LVITEM lvItem;
    lvItem.mask = LVIF_TEXT | LVIF_IMAGE;
    lvItem.iItem = 0;
    lvItem.iSubItem = 0;
    //lvItem.state = ;
    //lvItem.stateMask = ;
    lvItem.pszText = "1";
    //lvItem.cchTextmax = ;
    lvItem.iImage = 0;
    //lvItem.lParam = ;
    #if (_WIN32_IE >= 0x0300)
    lvItem.iIndent = 1;
    #endif int i = m_wndList.InsertItem(&lvItem); lvItem.iItem = 0;
    lvItem.pszText = "2007-05-22 10:00:00";
    lvItem.iSubItem = 1;
    lvItem.iImage = 1;    //这里就是图片索引
    m_wndList.SetItem(&lvItem); lvItem.iItem = 0;
    lvItem.pszText = "001";
    lvItem.iSubItem = 2;
    lvItem.iImage = 0;
    m_wndList.SetItem(&lvItem);
      

  4.   

    没有直接的方法,只能通过改写代码实现了,我知道这很麻烦,但实在没有办法,你可以搜索下有没有第3方的CListCtrl支持该功能,这样你才能仅复制原代码,再通过属性的调整来整体调整CListCtrl
      

  5.   

    我已初步做了一些,就是用drag和drop这个思路去做的.但是在drop的时候,不知道如何处理.请问大家有没有做过类似问题呢?
      

  6.   

    /*********************************这是我处理的主要代码**************************/
    // TaskArrangeDlg.cpp : 实现文件
    //#include "stdafx.h"
    #include "TaskArrange.h"
    #include "TaskArrangeDlg.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #endif
    // 用于应用程序“关于”菜单项的 CAboutDlg 对话框class CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();// 对话框数据
    enum { IDD = IDD_ABOUTBOX }; protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持// 实现
    protected:
    DECLARE_MESSAGE_MAP()
    };CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
    {
    }void CAboutDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    }BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    END_MESSAGE_MAP()
    // CTaskArrangeDlg 对话框
    CTaskArrangeDlg::CTaskArrangeDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CTaskArrangeDlg::IDD, pParent)
    {
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    m_nDragIndex = -1;
    m_nDropIndex = -1;
    m_pDragImage = NULL;
    }void CTaskArrangeDlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_LIST1, m_listL);
    }BEGIN_MESSAGE_MAP(CTaskArrangeDlg, CDialog)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_NOTIFY(LVN_BEGINDRAG, IDC_LIST1, &CTaskArrangeDlg::OnLvnBegindragList1)
    ON_WM_MOUSEMOVE()
    ON_WM_LBUTTONUP()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    // CTaskArrangeDlg 消息处理程序BOOL CTaskArrangeDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    } // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
    //  执行此操作
    SetIcon(m_hIcon, TRUE); // 设置大图标
    SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码
    m_Imagelist.Create(16,16,ILC_MASK,1,0);
    HICON hIcon=::LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1));
    m_Imagelist.Add(hIcon);
    hIcon=::LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON2));
    m_Imagelist.Add(hIcon);
    hIcon=::LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON4));
    m_Imagelist.Add(hIcon);
    hIcon=::LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON5));
    m_Imagelist.Add(hIcon);
    m_listL.SetImageList(&m_Imagelist,LVSIL_SMALL);
    for(int i=0;i<4;i++)
    {
    LVITEM lvItem;
    memset(&lvItem, 0, sizeof(lvItem));
    lvItem.mask = LVIF_IMAGE;
    lvItem.state = 0;
    lvItem.iItem = i;
    lvItem.iImage = i;
    m_listL.InsertItem(&lvItem);
    }
    return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
    }void CTaskArrangeDlg::OnSysCommand(UINT nID, LPARAM lParam)
    {
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
    else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
    }// 如果向对话框添加最小化按钮,则需要下面的代码
    //  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
    //  这将由框架自动完成。void CTaskArrangeDlg::OnPaint()
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); // 使图标在工作矩形中居中
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // 绘制图标
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CDialog::OnPaint();
    }
    }//当用户拖动最小化窗口时系统调用此函数取得光标显示。
    //
    HCURSOR CTaskArrangeDlg::OnQueryDragIcon()
    {
    return static_cast<HCURSOR>(m_hIcon);
    }
      

  7.   

    void CTaskArrangeDlg::OnLvnBegindragList1(NMHDR *pNMHDR, LRESULT *pResult)
    {
    LPNMLISTVIEW pNMListView = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
    // TODO: 在此添加控件通知处理程序代码 m_nDragIndex = pNMListView->iItem; POINT pt;
    //offset in pixels for drag image (positive is up and to the left; neg is down and to the right)
    int nOffset = -10; //Create a drag image
    m_pDragImage = m_listL.CreateDragImage(m_nDragIndex, &pt);
    //make sure it was created,We will call delete later (in LButtonUp) to clean this up
    ASSERT(m_pDragImage); 
    CBitmap bitmap;
    bitmap.LoadBitmap(IDB_BITMAP_SINGLE); m_pDragImage->Replace(0, &bitmap, &bitmap); //Change the cursor to the drag image
    m_pDragImage->BeginDrag(0, CPoint(nOffset, nOffset - 4));
    m_pDragImage->DragEnter(GetDesktopWindow(), pNMListView->ptAction);

    //Set dragging flag and others
    m_bDragging = TRUE;
    m_nDropIndex = -1;
    m_pDropWnd = &m_listL; //Capture all mouse messages
    SetCapture(); *pResult = 0;
    }void CTaskArrangeDlg::OnMouseMove(UINT nFlags, CPoint point)
    {
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    if(m_bDragging)
    {
    //Move the drag image
    CPoint pt(point);
    ClientToScreen(&pt);
    //move the drag image to those coordinates
    m_pDragImage->DragMove(pt); 
    // Unlock window updates (this allows the dragging image to be shown smoothly)
    m_pDragImage->DragShowNolock(false); //Get the CWnd pointer of the window that is under the mouse cursor
    CWnd* pDropWnd = WindowFromPoint(pt);
    ASSERT(pDropWnd); //make sure we have a window //Save current window pointer as the CListCtrl we are dropping onto
    m_pDropWnd = pDropWnd; //Convert from screen coordinates to drop target client coordinates
    pDropWnd->ScreenToClient(&pt); //If we are hovering over a CListCtrl we need to adjust the highlights
    UINT uFlags;
    CListCtrl* pList = (CListCtrl*)pDropWnd; //Turn off hilight for previous drop target
    pList->SetItemState (m_nDropIndex, 0, LVIS_DROPHILITED);
    // Redraw previous item
    pList->RedrawItems (m_nDropIndex, m_nDropIndex);

    //Get the item that is below cursor
    m_nDropIndex = ((CListCtrl*)pDropWnd)->HitTest(pt, &uFlags);
    //Highlight it
    pList->SetItemState(m_nDropIndex, LVIS_DROPHILITED, LVIS_DROPHILITED);
    //Redraw item
    pList->RedrawItems(m_nDropIndex, m_nDropIndex);
    pList->UpdateWindow();
    //Lock window updates
    m_pDragImage->DragShowNolock(true);
    }
    CDialog::OnMouseMove(nFlags, point);
    }
    void CTaskArrangeDlg::OnLButtonUp(UINT nFlags, CPoint point)
    {
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    if (m_bDragging)
    {
    // Release mouse capture, so that other controls can get control/messages
    ReleaseCapture (); // Note that we are NOT in a drag operation
    m_bDragging = FALSE; //End dragging image
    m_pDragImage->DragLeave(GetDesktopWindow());
    m_pDragImage->EndDrag();
    //must delete it because it was created at the beginning of the drag
    delete m_pDragImage;  //Get current mouse coordinates
    CPoint pt(point); 
    //Convert to screen coordinates
    ClientToScreen (&pt); 
    //Get the CWnd pointer of the window that is under the mouse cursor
    CWnd* pDropWnd = WindowFromPoint(pt);
    //make sure we have a window pointer
    ASSERT(pDropWnd); 
    // If window is CListCtrl, we perform the drop
    if(pDropWnd->IsKindOf(RUNTIME_CLASS(CListCtrl)))
    {
    //Set pointer to the list we are dropping on
    m_pDragList = (CListCtrl*)pDropWnd; 
    //Call routine to perform the actual drop
    DropItemOnList(m_pDragList); 
    }
    }
    CDialog::OnLButtonUp(nFlags, point);
    }void CTaskArrangeDlg::DropItemOnList(CListCtrl* pDragList)
    {
    // Unhilight the drop target
    m_pDragList->SetItemState(m_nDropIndex, 0, LVIS_DROPHILITED); //Set up the LV_ITEM for retrieving item from pDragList and adding the new item to the pDropList
    LVITEM lviT;
    //allocate and clear memory space for LV_ITEM
    ZeroMemory(&lviT, sizeof (LVITEM)); 
    lviT.mask = LVIF_IMAGE;
    lviT.iItem = m_nDragIndex;
    lviT.iImage     = m_nDragIndex; LVITEM *lvi;
    lvi = &lviT;
    lvi->mask = LVIF_IMAGE;
    lvi->iItem = m_nDragIndex;
    lvi->iImage = m_nDragIndex;
    // Get item that was dragged
    pDragList->GetItem(lvi); pDragList->DeleteItem(m_nDragIndex);
    //decrement drop index to account for item,being deleted above it
    if(m_nDragIndex < m_nDropIndex) m_nDropIndex--;  // Insert item into pDropList
    // if m_nDropIndex == -1, iItem = GetItemCount() (inserts at end of list), else iItem = m_nDropIndex
    lvi->iItem = (m_nDropIndex == -1) ? m_pDragList->GetItemCount() : m_nDropIndex;
    m_pDragList->InsertItem (lvi); // Select the new item we just inserted
    m_pDragList->SetItemState (lvi->iItem, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
    }