Re: Drawing lines in a CListCtrl

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I would simply use a CWnd or CStatic as the container. You will run into the
same drawing problem with a CEdit.
As far as the items go, unless you need the functionality of a Button, I
would use a CWnd or CStatic, but a CButton should also be fine.
As far as drag and drop goes. That can be a little tricky. Typically drag
and drop is done using OLE (CDataSource, and CDropTarget), so what you will
have to do is detect the dragging in your item's class (CWnd or CButton...)
create the CDataSource and set its drag icon to be the same as the picture
of the item begin dragged. You will also have to implement a CDropTarget
somewhere, either in each item, or at the parent level (the container
class), to get the drops.

With all that said, I would probably not do any of that. I would use a CWnd
as the container window.

Then I would create a class for the items, the class would look something
like this
class CListItem
{
public:
void Draw(CDC *pDC);
BOOL HitTest(const CPoint &Pt);
private:
CRect m_Rect;
CBitmap m_Image;
.... any other info that is needed.
}

and use a CList or a link list to keep track of all the items that the
container owns, and draw them.
For drag and drop, handle the WM_LBUTTONDOWN, WM_LBUTTONUP, and
WM_MOUSEMOVE. And do the drag and drop by detecting which item they clicked
on and dragged, and when the let the mouse button up, which object (if any)
the dropped it on.

I hope this helps.

AliR.



"TPFGuru" <TPFGuru@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9E620E31-8F82-4DF3-B6B0-B6AEB5C0EB36@xxxxxxxxxxxxxxxx
Thanks. I figured as much. I can see the lines after the WM_PAINT, but
the
items aren't drawn.

What do you recommend I use? Maybe a big edit control, where I create and
place buttons with Icons to behave like the CListCtrl items? I am
shooting
for the kind of display that Maya 7 does for the HyperGraph, which seems
to
use buttons to represent the items, and you can drag a button onto another
to
set the relationship. Could I detect when one button is dragged over
another
easily?

Thanks!

"AliR" wrote:

.... Trying to draw to
the window with DC commands may not be possible. I could always
change it
to
a basic window and just draw it all manually.

That's probably your best option. I know that customizing CListCtrl and
CTreeCtrl is almost next to impossible. The problem is that Microsoft
has
not left any room for customization of these controls. Chances are
whatever
you draw on the DC during the paint message will get wiped out by some
interal drawing of the control (like scrolling...)

AliR.

"TPFGuru" <TPFGuru@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:CBBB98F6-0BE9-40B3-9FAB-326BA73B30D5@xxxxxxxxxxxxxxxx
Thanks. Everything I have seen so far involves changing the LVxxx
property
of a control item or doing a CListCtrl.Set.... command. Trying to
draw
to
the window with DC commands may not be possible. I could always
change it
to
a basic window and just draw it all manually.

Thanks.


"Tom Serface" wrote:

I've never tried to do this, but if I were to try, I'd try either
doing
in
it OnPaint() or making it an owner drawn control and do it in
DrawItem().

Tom Archer's recent article might be interesting to you as well:

http://www.microsoft.com/indonesia/msdn/customdraw.aspx

Tom

"TPFGuru" <TPFGuru@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A52FEB6F-4BBF-4576-AD28-337AF76C1580@xxxxxxxxxxxxxxxx
So, no one knows where I stick two drawing instructions:

MoveToEx(dc, Pos1.x, Pos1.y, NULL);
LineTo(dc, Pos2.x, Pos2.y);

for a CListCtrl so that it will correctly draw the items and the
lines?

"TPFGuru" wrote:

Hi, I am using a CListCtrl in LVS_ICON mode to create a tree
structure of
my
icons (which are the bones of a skinned mesh). I have the icons
all
drawing
OK, but would like to draw a red line to link a parent to a child
and
a
blue
line to link siblings.

I have tried various ways of getting the lines to draw, but
cannot
get
the
control to draw both the items and lines at the same time. If I
over-ride
the WM_PAINT message in my CListCtrl derived class and draw the
lines, I
cannot see the items.

If instead I write a separate routine to draw the lines that is
called by
the dialog class, it draws the items but not the lines.

How can I have the control draw both?

I have also tried using UpdateWindow() and Update(nItem) in the
control's
OnPaint function without success.

Thanks!









.



Relevant Pages

  • Re: Drawing lines in a CListCtrl
    ... would use a CWnd or CStatic, but a CButton should also be fine. ... As far as drag and drop goes. ... container owns, and draw them. ... place buttons with Icons to behave like the CListCtrl items? ...
    (microsoft.public.vc.mfc)
  • Re: Generate a List of Dialog Boxes in a View - Scroll
    ... And putting buttons in a generic CWnd is easy. ... way to reflect the messages from the child to the parent. ... dialogs is that the control IDs would be "locally scoped" to the child dialog, ... > Why i am taking CDialog as Container is that the container should has ...
    (microsoft.public.vc.mfc)
  • Re: Best Practices for Improving FM Performance
    ... tool in the status area to draw a box in some solid shade with no ... If I changed every occurrence of the boxes to a global container field ... your layouts flicker horribly during normal use (changing from record ... Graphics light layouts - use fm's built in drawing tools, ...
    (comp.databases.filemaker)
  • Re: custom component painting
    ... I create a canvas type object (as a container) and ... removes the Node reference by a_node from the GraphToy4 referenced by ... For the Graphic g value passed to the paintComponent method of a Node, ... your paintComponent method invokes draw ...
    (comp.lang.java.gui)
  • Re: derive from CWnd?
    ... about hundreds of objects on the drawing. ... The alternative is to have each object have a virtual "Draw" method. ... a pointer to a CView; you'd most likekly pass a CDC * or CDC & into it. ... should each object be derived from CWnd? ...
    (microsoft.public.vc.mfc)