Server Help

Non-Subspace Related Coding - Tree-View Dragging?

Cyan~Fire - Sat Oct 15, 2005 10:51 am
Post subject: Tree-View Dragging?
Wondering if anyone (Ekted) has used a treeview before, and wondering what the heck might be wrong with mine. When I do the click-and-drag thing, I get this:

Basically, it's inverting the color of anything under the dragged item. If it's highlighted, the area is white, and if it's not, the area is blue. And it only happens when the item the cursor is hovering over changes, not when I move back and forth over an item.

Here's my code:
Code: Show/Hide
void TrigTree_HandleDrag(HWND treeview, NMTREEVIEW *params)
{
   HIMAGELIST images;

   /* Do the UI stuff. */
   images = TreeView_CreateDragImage(treeview, params->itemNew.hItem);
   ImageList_BeginDrag(images, 0, 0, 0);
   ImageList_DragEnter(treeview, params->ptDrag.x, params->ptDrag.y);

   /* Do the behind-the-scenes stuff. */
   SetCapture(GetParent(treeview));
   dragging = true;
}
bool HandleMouseMove(HWND dialog, WORD x, WORD y)
{
   TVHITTESTINFO tvht;
   HWND treeview = GetDlgItem(dialog, IDC_T_TREE);

   if (dragging)
   {
      ImageList_DragMove(x, y);

      tvht.pt.x = x;
      tvht.pt.y = y;
      if (TreeView_HitTest(treeview, &tvht))
      {
         TreeView_SelectDropTarget(treeview, tvht.hItem);
      }
   }

   return dragging;
}


Any clues?
Cyan~Fire - Mon Feb 27, 2006 8:12 pm
Post subject:
Stupid, stupid, horrible Win32 API. I finally found the answer when I happened to find a giant book on the API. I looked up treeviews, and there it was: how to properly drag. But here's the modification:
Code: Show/Hide
bool HandleMouseMove(HWND dialog, WORD x, WORD y)
{
...
      if (TreeView_HitTest(treeview, &tvht) &&
         tvht.flags & (TVHT_ONITEM | TVHT_ONITEMRIGHT))
      {
         ImageList_DragShowNolock(FALSE);
         TreeView_SelectDropTarget(treeview, tvht.hItem);
         ImageList_DragShowNolock(TRUE);
      }
...
}

Turns out if you don't turn off the drag image (with ImageList_DragShowNolock()) while the treeview's painting the drop-target highlight, it image interferes. Of course, the MSDN documentation doesn't say a word about this.
Mr Ekted - Mon Feb 27, 2006 11:05 pm
Post subject:
Never used one before. Thanks for the info. icon_smile.gif
Solo Ace - Mon Mar 06, 2006 1:46 am
Post subject:
Heh, speaking of a horrible Win32 API. Yesterday I was trying to figure out how to add a check box control (to the first, left column) to an entry in a ListView.
I couldn't get it to work, eventually I gave up heh.
Adding an icon there works fine, though. icon_sad.gif

Any of you ever did this?

BTW, Cyan, I love your *cough* meaningless *cough* comments. sa_tongue.gif
Mr Ekted - Mon Mar 06, 2006 2:37 am
Post subject:
There's no standard way to do it. Windows doesn't have a "checkbox in list" type of standard control. However it is done all the time. I'm sure you could find examples if you google the right keywords. If you find something, I can probably help you undertand it.
Solo Ace - Mon Mar 06, 2006 12:04 pm
Post subject:
Thanks, but I think it's something for later.
It's for a project for my dad, he said "all entries would be checked anyway", but I refuse to let the idea go!
Cyan~Fire - Mon Mar 06, 2006 6:48 pm
Post subject:
LVS_EX_CHECKBOXES?
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group