Link to home
Create AccountLog in
Avatar of myara
myara

asked on

Custom List View

Dear Experts Exchange,
  I try to build my own list view. I'd like each row to be the following :
  |----|   |----|
  | B1 |  | B2 |      Text
  |----|  |----|
B1 and B2 being (for now) CButtons.
My actual code is organised this way :
  - a "CRow : public CView" Object describing a line (contains 2 buttons instances, one for B1 and one for B2 + a custom drawing fuction drawing the text)
  - a "CMyList" : public CView" Object describing the list itself. This object makes for now only 2 instances of CRow (that's a preliminary test class).

  CMyList is registered as a Custom MFC Object, declared in the resource file as a child view for a CDialogBar.

  My main problem is a Focus Problem I think : only the first row instance tracks both buttons clicks. Trying things such as SetFocus() for the second line does not seem to work, as the only messages tracking view is still the first row.

  A subsidiary question : Is it possible to call only the drawing function of a CButton in the OnPaint function of a custom object ?

  Best Regards,
   Mike
Avatar of DanRollins
DanRollins
Flag of United States of America image

Is your goal to have buttons in the first two columns of a multiple-colum list view?  And (for instance) when the list is scrolled, the buttons scroll with the row?

If so, you have some significant work ahead of you.  I'd recommend using an existing control, derived from CListCtrl that has that sort of functionality built into it.  For instance, see
   Adding Controls to listcontrol
   http://www.codeguru.com/cpp/controls/listbox/article.php/c4761/

Even if you do not want to use that specific control, the sources code is provided so that you can learn the needed techniques for incorporation into yur own controls.

-- Dan
Avatar of myara
myara

ASKER

Hello,

  thanks for your advice, I already had a look to this article but that's not exactly what I wanted to do.

I found a "not so bad" solution : the Line View is derived from CDialog, and my custom List View is derived from CScrollView. This way I've no problem of "focus". My only problem for now is that one button per line has the "black frame" around itself. I think there's a message-problem but I don't know how to solve it ...

  Thanks once more ...
    Mike
P.S. : possible to send a screen copy here ?
EE doesn't have that ability ... if you post the image somewhere (say on a free picture-sharing site), then you can put a link to it in your comment... but that's about the best that can be done.

As to the "black frame" -- I think you are talking about the so-called "focus rectangle"  That is supposed to be there -- it indicates which controls has the keyboard focus.

It this point, I don't really know what techniques you are using, but if you are doing almost any form of OwnerDraw on a CListCtrl, then that will relate to the "item state" -- one of its values is LVIS_FOCUSED (the relevant message is LVM_GETITEMSTATE and/or LVM_SETITEMSTATE).

You might also be talking about the larger darker rectangle that indicates the "Default Button" in a dialog.  It indicates which action the program should take when the user presses the Enter key. That is a property of the dialog item and you can change it by sending a BM_SETSTYLE to turn off the BS_DEFPUSHBUTTON style bit.  The DM_SETDEFID message is also related.
Avatar of myara

ASKER

Yes the black frame is the "focus rectangle", not the "default button" (I removed its state in the resource).
I think the problem is that, in MFC, the "focus" does not go through a CScrollView : the "main dialog" (the floating tool) cannot (I think) forward it messages to through the ScrollView (perhaps I mistake), and thus it can be more than one "focused" button at one time in a single dialog box. Is it possible to send to you my code ? Perhaps can I put it in a mini web site and give you the link ?

  Thanks once more for your interest ...
     Mike
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of myara

ASKER

Hello,

   Thanks to your help, I finally found a solution : As you said, using a CScrollView to scroll a dialog is not standard, so I implemented a kind of CScrollDialog (derived from CDialog) and this time it works.  So thanks a lot for your advice.

  I have two questions more :
   - Is OLE the "good way" to handle Drag 'n' Drop in MFC ?
   - Drawing during mouse events (OnMouseMove) does not seem to work. Is there a way to do this, or may I change my OnPaint Override and invalidate the Wnd ?

   Thanks once more,
      Mike
The normal way to do drag-and-drop in MFC is described here:
   http://msdn2.microsoft.com/en-us/library/96826a87(vs.80).aspx

You probably should not be drawing things in your OnMouseMove handler during a drag-and-drop operation.   If you want to change the image of what is being dragged, you make calls to affect the CImageList that gets set up during the OnBegindrag() call.  For instance, CImageList::SetDragCursorImage() and so forth.  Also, look at the CImageList::DragShowNolock() function which relates to locking window updates during drag operations.