tags:

views:

196

answers:

2

This should be simple it seems but I can't quite get it to work. I want a control (I guess CListBox or CListCtrl) which displays text strings in a nice tabulated way.

As items are added, they should be added along a row until that row is full, and then start a new row. Like typing in your wordprocessor - when the line is full, items start being added to the next line, and the control can scroll vertically.

What I get when trying with a list-mode CListCtrl is a single row which just keeps growing, with a horizontal scroll bar. I can't see a way to change that, there must be one?

+2  A: 

You probably need a list control wth LVS_REPORT. If you expect the user to add items interactively using a keyboard, you probably need a data grid, not a list. Adding editing to list control subitems is not easy, and it would be easier to start from CWnd. Search "MFC Data Grid" to find some open source class libraries that implemented the feature.

If you can afford adding /clr to your program, you can try the data grid classes in Windows Forms using MFC's Windows Form hosting support. You will find a lot more programming resources on data grid classes in Windows Forms than any other third-party MFC data grid class library.

Sheng Jiang 蒋晟
A: 

If you use CRichEditCtrl you can set it to word-wrap, take a look at this snippet extracted from:

http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.ui/2004-03/0111.html

    (I've derived my own QRichEditCtrl from the MFC CRichEditCtrl,
and here's the relevant code:)

void QRichEditCtrl::SetWordWrap(bool bWrap)
{
   RECT r;
   GetWindowRect(&r);
   CDC * pDC = GetDC();
   long lLineWidth = 9999999; // This is the non-wrap width
   if (bWrap)
   {
      lLineWidth = ::MulDiv(pDC->GetDeviceCaps(PHYSICALWIDTH),
               1440, pDC->GetDeviceCaps(LOGPIXELSX));
   }

   SetTargetDevice(*GetDC(), lLineWidth);
}
rec