<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problem bei Drag &amp;amp; Drop im TreeView]]></title><description><![CDATA[<p>Hi,<br />
Ich versuche mich gerade an Drag &amp; drop. Soweit funktioniert es auch schon aber zum schluss wenn ich die Maus loslasse, dann bleibt das TreeViewItem ausgewählt wo ich es losgelassen habe. Also ich kann dann mit der Maus kein anderes auswählen. Ich halte mich bei den Quellcode direkt an dem von der MSDN.</p>
<pre><code>bool g_fDragging;
void Main_OnBeginDrag(HWND hwndTV, LPNMTREEVIEW lpnmtv) 
{ 
    HIMAGELIST himl;    // handle to image list 
    RECT rcItem;        // bounding rectangle of item 
    DWORD dwLevel;      // heading level of item 
    DWORD dwIndent;     // amount that child items are indented 

    // Tell the tree view control to create an image to use 
    // for dragging. 
    himl = TreeView_CreateDragImage(hwndTV, lpnmtv-&gt;itemNew.hItem); 

    // Get the bounding rectangle of the item being dragged. 
    TreeView_GetItemRect(hwndTV, lpnmtv-&gt;itemNew.hItem, &amp;rcItem, TRUE); 

    // Get the heading level and the amount that the child items are 
    // indented. 
    dwLevel = lpnmtv-&gt;itemNew.lParam; 
    dwIndent = (DWORD) SendMessage(hwndTV, TVM_GETINDENT, 0, 0); 

    // Start the drag operation. 
    ImageList_BeginDrag(himl, 0, -5, -5); 

    // Hide the mouse cursor, and direct mouse input to the 
    // parent window. 
    ShowCursor(FALSE); 
    SetCapture(GetParent(hwndTV)); 
    g_fDragging = true; 
    return; 
} 

void Main_OnMouseMove(HWND hwndParent, HWND hwndTV, LONG xCur, LONG yCur) 
{ 
    HTREEITEM htiTarget;  // handle to target item 
    TVHITTESTINFO tvht;  // hit test information 

    if( g_fDragging ) { 

        // Drag the item to the current position of the mouse cursor. 
        ImageList_DragMove(xCur, yCur); 

        // Find out if the cursor is on the item. If it is, highlight 
        // the item as a drop target. 
        tvht.pt.x = xCur; 
        tvht.pt.y = yCur; 
        if( (htiTarget = TreeView_HitTest(hwndTV, &amp;tvht)) != NULL ) { 
			TreeView_SelectDropTarget(hwndTV, htiTarget);
        } 
    } 
    return; 
}
</code></pre>
<p>Und dann das noch in meiner Nachrichtenschleife.</p>
<pre><code>case TVN_BEGINDRAG:
				Main_OnBeginDrag(TreeView.GetHwnd(), (LPNMTREEVIEW) lP); 
				break; 
			}
		}
		break;
			case WM_MOUSEMOVE:
				if( g_fDragging == true )
					Main_OnMouseMove(hdlg, TreeView.GetHwnd(), LOWORD(lP), HIWORD(lP));
				break;
			case WM_LBUTTONUP:
				if( g_fDragging )
				{ 
					ImageList_EndDrag();
					ReleaseCapture();
					ShowCursor(TRUE); 
					g_fDragging = false;
				}
</code></pre>
<p>Also wenn ich diese Zeile auskommentiere</p>
<pre><code>TreeView_SelectDropTarget(hwndTV, htiTarget);
</code></pre>
<p>Dann funktioniert es danach auch wieder aber dann wird beim Ziehen ja nix markiert???<br />
Hoffe jemand kann mir helfen. Evtl ist es noch wichtig zu wissen das das TreeView in einem Dialogbox ist das untergeordnet arbeitet, also das ist in einem TabCtrl vielleicht hängt es ja damit zusammen??</p>
<p>MfG schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/148776/problem-bei-drag-amp-drop-im-treeview</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Jul 2026 17:29:15 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/148776.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 30 May 2006 11:29:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem bei Drag &amp;amp; Drop im TreeView on Tue, 30 May 2006 11:29:47 GMT]]></title><description><![CDATA[<p>Hi,<br />
Ich versuche mich gerade an Drag &amp; drop. Soweit funktioniert es auch schon aber zum schluss wenn ich die Maus loslasse, dann bleibt das TreeViewItem ausgewählt wo ich es losgelassen habe. Also ich kann dann mit der Maus kein anderes auswählen. Ich halte mich bei den Quellcode direkt an dem von der MSDN.</p>
<pre><code>bool g_fDragging;
void Main_OnBeginDrag(HWND hwndTV, LPNMTREEVIEW lpnmtv) 
{ 
    HIMAGELIST himl;    // handle to image list 
    RECT rcItem;        // bounding rectangle of item 
    DWORD dwLevel;      // heading level of item 
    DWORD dwIndent;     // amount that child items are indented 

    // Tell the tree view control to create an image to use 
    // for dragging. 
    himl = TreeView_CreateDragImage(hwndTV, lpnmtv-&gt;itemNew.hItem); 

    // Get the bounding rectangle of the item being dragged. 
    TreeView_GetItemRect(hwndTV, lpnmtv-&gt;itemNew.hItem, &amp;rcItem, TRUE); 

    // Get the heading level and the amount that the child items are 
    // indented. 
    dwLevel = lpnmtv-&gt;itemNew.lParam; 
    dwIndent = (DWORD) SendMessage(hwndTV, TVM_GETINDENT, 0, 0); 

    // Start the drag operation. 
    ImageList_BeginDrag(himl, 0, -5, -5); 

    // Hide the mouse cursor, and direct mouse input to the 
    // parent window. 
    ShowCursor(FALSE); 
    SetCapture(GetParent(hwndTV)); 
    g_fDragging = true; 
    return; 
} 

void Main_OnMouseMove(HWND hwndParent, HWND hwndTV, LONG xCur, LONG yCur) 
{ 
    HTREEITEM htiTarget;  // handle to target item 
    TVHITTESTINFO tvht;  // hit test information 

    if( g_fDragging ) { 

        // Drag the item to the current position of the mouse cursor. 
        ImageList_DragMove(xCur, yCur); 

        // Find out if the cursor is on the item. If it is, highlight 
        // the item as a drop target. 
        tvht.pt.x = xCur; 
        tvht.pt.y = yCur; 
        if( (htiTarget = TreeView_HitTest(hwndTV, &amp;tvht)) != NULL ) { 
			TreeView_SelectDropTarget(hwndTV, htiTarget);
        } 
    } 
    return; 
}
</code></pre>
<p>Und dann das noch in meiner Nachrichtenschleife.</p>
<pre><code>case TVN_BEGINDRAG:
				Main_OnBeginDrag(TreeView.GetHwnd(), (LPNMTREEVIEW) lP); 
				break; 
			}
		}
		break;
			case WM_MOUSEMOVE:
				if( g_fDragging == true )
					Main_OnMouseMove(hdlg, TreeView.GetHwnd(), LOWORD(lP), HIWORD(lP));
				break;
			case WM_LBUTTONUP:
				if( g_fDragging )
				{ 
					ImageList_EndDrag();
					ReleaseCapture();
					ShowCursor(TRUE); 
					g_fDragging = false;
				}
</code></pre>
<p>Also wenn ich diese Zeile auskommentiere</p>
<pre><code>TreeView_SelectDropTarget(hwndTV, htiTarget);
</code></pre>
<p>Dann funktioniert es danach auch wieder aber dann wird beim Ziehen ja nix markiert???<br />
Hoffe jemand kann mir helfen. Evtl ist es noch wichtig zu wissen das das TreeView in einem Dialogbox ist das untergeordnet arbeitet, also das ist in einem TabCtrl vielleicht hängt es ja damit zusammen??</p>
<p>MfG schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1067983</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1067983</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Tue, 30 May 2006 11:29:47 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Drag &amp;amp; Drop im TreeView on Fri, 09 Jun 2006 15:32:17 GMT]]></title><description><![CDATA[<p>Ich hab das mit: pTree-&gt;SelectDropTarget( 0 ); in WM_LBUTTONUP gelöst</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1074694</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1074694</guid><dc:creator><![CDATA[StephanS]]></dc:creator><pubDate>Fri, 09 Jun 2006 15:32:17 GMT</pubDate></item><item><title><![CDATA[Reply to Problem bei Drag &amp;amp; Drop im TreeView on Sun, 11 Jun 2006 12:49:28 GMT]]></title><description><![CDATA[<p>Wow cool danke das hat gefunzt. Hatte wegen Zeit mich nicht weiter mit beschäftigt aber nun kann es ja flot weiter gehen. Danke nochmal.</p>
<p>MfG schirrmie</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1075590</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1075590</guid><dc:creator><![CDATA[schirrmie]]></dc:creator><pubDate>Sun, 11 Jun 2006 12:49:28 GMT</pubDate></item></channel></rss>