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,
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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
myaraAuthor Commented:

  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 ...
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.
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

myaraAuthor Commented:
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 ...
It sounds like you are doing some non-standard and very complex things... It might be that after fixing this particular problem, you just end up with a "fixed" version of an unweildy and non-standard U/I interface method that will certainly present many additional problems along the line.

You can try zipping up the entire project and posting it somewhere on the web... but I won't promise that I'll look at it (maybe some other Expert here might).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
myaraAuthor Commented:

   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,
The normal way to do drag-and-drop in MFC is described here:

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.  
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.