Click here to Skip to main content
15,908,115 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: GetFile( ) function in vc++/MFC Pin
David Crow20-May-08 3:24
David Crow20-May-08 3:24 
GeneralRe: GetFile( ) function in vc++/MFC Pin
lahom20-May-08 8:50
lahom20-May-08 8:50 
GeneralRe: GetFile( ) function in vc++/MFC Pin
David Crow20-May-08 8:54
David Crow20-May-08 8:54 
GeneralRe: GetFile( ) function in vc++/MFC Pin
lahom20-May-08 9:07
lahom20-May-08 9:07 
GeneralRe: GetFile( ) function in vc++/MFC Pin
David Crow20-May-08 10:18
David Crow20-May-08 10:18 
AnswerRe: GetFile( ) function in vc++/MFC Pin
Hamid_RT15-May-08 20:31
Hamid_RT15-May-08 20:31 
QuestionHow to verify if a password matches the local password policies? Pin
Alex Vargas15-May-08 11:08
Alex Vargas15-May-08 11:08 
QuestionDrag&Drop Sorting in Icon View of CListCtrl Pin
Brett Fowle15-May-08 9:45
Brett Fowle15-May-08 9:45 
Hello,

I know it's possible, with a bit of work and a custom sorting algorithm, to add the ability to drag&drop-order items in a CListCtrl (in ICON view mode) to reorder them manually. I found this article: http://support.microsoft.com/kb/822483/en-us pertaining to such a thing, but it's all in VB/C# and was wondering if there was a way to do it in C++...?

Currently, I have set up the correct OnBeginDrag, OnMouseMove and OnLButtonUp functions working just fine -- I get a dragIndex and dragPoint&dropPoint ,... but the problems are:

1.) dropIndex is not calculated correctly, because it can be ordered in both different X and Y coordinates to drop it into
2.) deleting the currently dragged item at it's position, and adding it to the correctly dropped position
3.) then shifting all the other items into their correct (new) positions

Here is the code, the sorting algo is currently quite(!) incomplete and just for left&right sorting tests...

<br />
    POINT startPT;<br />
    GetItemPosition(m_nDragIndex, &startPT);<br />
<br />
    POINT endPT;<br />
    for (int i = 0; i < GetItemCount(); i++)<br />
    {<br />
        if (i == m_nDragIndex) continue;<br />
<br />
        GetItemPosition(i, &endPT);<br />
<br />
        // do sorting algo (currently incomplete)<br />
        if (endPT.x > m_ptDropPoint.x)<br />
        {<br />
            m_nDropIndex = i;<br />
            if (startPT.x < m_ptDropPoint.x) m_nDropIndex--;<br />
<br />
            break;<br />
        }<br />
    }<br />
<br />
    // Get information on the dragged item by setting an LV_ITEM structure and then calling GetItem to fill it in<br />
    char szLabel[256];<br />
    LVITEM lvi;<br />
    ZeroMemory(&lvi, sizeof(LV_ITEM));<br />
    lvi.mask       = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE | LVIF_PARAM;<br />
    lvi.stateMask  = LVIS_DROPHILITED | LVIS_FOCUSED | LVIS_SELECTED;<br />
    lvi.pszText    = (LPWSTR)szLabel;<br />
    lvi.iItem      = m_nDragIndex;<br />
    lvi.cchTextMax = 255;<br />
    GetItem(&lvi);<br />
<br />
    // Insert the dropped item<br />
    if (m_nDropIndex < 0)<br />
        m_nDropIndex = GetItemCount();<br />
<br />
    lvi.iItem = m_nDropIndex;<br />
    InsertItem(&lvi);<br />
<br />
    // Index of dragged item will change if item is dropped above itself<br />
    if (m_nDragIndex > m_nDropIndex)<br />
        m_nDragIndex++;<br />
<br />
    // Copy item data pointer<br />
    SetItemData(m_nDropIndex, GetItemData(m_nDragIndex));<br />
<br />
    // Delete the item that was dragged from its original location<br />
    DeleteItem(m_nDragIndex);<br />


I have auto-arrange currently turned off for certain purposes and feel this is necessary for this sort of custom-sort. If anyone has any ideas, or can convert that article's code into the correct C++/MFC ones, that'd be an immense help!

Thanks!
QuestionRe: Drag&Drop Sorting in Icon View of CListCtrl Pin
Brett Fowle16-May-08 3:16
Brett Fowle16-May-08 3:16 
QuestionConsole application junk arguments Pin
kasi1415-May-08 6:29
kasi1415-May-08 6:29 
QuestionRe: Console application junk arguments Pin
David Crow15-May-08 6:48
David Crow15-May-08 6:48 
AnswerRe: Console application junk arguments Pin
kasi1415-May-08 7:55
kasi1415-May-08 7:55 
QuestionRe: Console application junk arguments Pin
David Crow15-May-08 8:04
David Crow15-May-08 8:04 
QuestionMFC Grid control 2.26 Pin
capint15-May-08 5:46
capint15-May-08 5:46 
AnswerRe: MFC Grid control 2.26 Pin
toxcct15-May-08 5:56
toxcct15-May-08 5:56 
AnswerRe: MFC Grid control 2.26 Pin
led mike15-May-08 5:58
led mike15-May-08 5:58 
QuestionRe: MFC Grid control 2.26 Pin
David Crow15-May-08 6:49
David Crow15-May-08 6:49 
AnswerRe: MFC Grid control 2.26 Pin
Cedric Moonen15-May-08 7:11
Cedric Moonen15-May-08 7:11 
AnswerRe: MFC Grid control 2.26 Pin
Hamid_RT15-May-08 9:10
Hamid_RT15-May-08 9:10 
GeneralRe: MFC Grid control 2.26 Pin
capint15-May-08 16:10
capint15-May-08 16:10 
GeneralRe: MFC Grid control 2.26 Pin
Hamid_RT15-May-08 20:42
Hamid_RT15-May-08 20:42 
GeneralRe: MFC Grid control 2.26 Pin
capint15-May-08 22:21
capint15-May-08 22:21 
GeneralRe: MFC Grid control 2.26 Pin
Hamid_RT15-May-08 23:23
Hamid_RT15-May-08 23:23 
GeneralRe: MFC Grid control 2.26 Pin
capint16-May-08 0:14
capint16-May-08 0:14 
GeneralRe: MFC Grid control 2.26 Pin
Hamid_RT16-May-08 0:28
Hamid_RT16-May-08 0:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.