Inserting a 'list' of items into a CListCtrl, CListBox & CTreeCtrl

Hi,

1) Does anyone know how to insert a list of itmes into a CListCtrl, a CListBox and a CTreeCtrl?
2) Does anyone know how to select a list of items in a CListCtrl, a CListBox and a CTreeCtrl?

Right now I am inserting / selecting each item one at a time which causes some messages to be sent (eg. LVN_ITEMCHANGED and LVN_SELCHANGED), therefore the update is very slowly - eventhough I use LockWindowUpdate & UnlockWindowUpdate.
  I am capturing the above messages and do a lot of stuff each time the selections change - this slows down the process of adding items into the three mentioned controls.

/Brian
Brian_HPAsked:
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.

jhanceCommented:
>I am capturing the above messages and
>do a lot of stuff each time the
>selections change

You've almost answered your own question here. Why not set an "update" flag in your application when you are updating these controls and inhibit your "lot of stuff" until after the items are all inserted?
0

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
Brian_HPAuthor Commented:
I know it is possible to put in "update" flags, but it is not a 'nice' solution.
  Furthermore, each time an item is added or selected a message must be sent, when the number of items to be added or selected is large, it is very time consuming (4-5 seconds on a P-III 500 MHz). Instead, if it is possible to pass a list of items to be added/selected only one (or perhaps two) messages would be sent, this would(most likely) reduce the total time used to add/select the items.
  Is this possible in Visual C++ 6.0?
0
jhanceCommented:
Well then the answer is no.  These MFC controls are designed to accept items one at a time and require a message for each one.  I think the best solution it to set an update flag and don't see why you say it's not "nice".  

If this is unacceptable, you might consider writing your own versions of these controls.  You could do one that takes an array of items instead of just a single one.  It probably wouldn't be that much work especially since you have the source code to the MFC classes available for inspection.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Brian_HPAuthor Commented:
If you cannot see using global or semi-global variables for flags is a hack and that it is not enforcing the loose cobbling between two components, then fine, I will not discuss it further - you'll get the points, anyway!

But, you said I could write my own verions of the controls. Do you know where I can get the source code for the MFC controls? or is it not available?
0
jhanceCommented:
>If you cannot see using global or semi-
>global variables for flags is a hack
>and that it is not enforcing the loose
>cobbling between two components, then
>fine, I will not discuss it further -
>you'll get the points, anyway!

Sorry to offend you but you asked how to get the job done, not how to do it beautifully!  Aesthetics are fine for the academic/purist crowd but for those of us that do real work, sometimes a hack is what is needed.

Anyway, that philosophical viewpoint aside, I still don't see how doing what I've suggested is a hack.  In fact, I'd suggest you could do this in a really nice clean way.  Too bad you won't discuss it further....



If you're using Microsoft VC++, the source code for MFC is included with the compiler but you may not have installed it.  With another compiler, I don't know.
0
Brian_HPAuthor Commented:
>Sorry to offend you but you asked how >to get the job done, not how to do it >beautifully!  Aesthetics are fine for >the academic/purist crowd but for >those of us that do real work, >sometimes a hack is what is needed.

You're right, when VC++ MFC does not provide the functionality needed, a 'hack' is often the best way to solve it. Therefore, I am going to so. I was just frustrated that VC++ MFC should be only VC++ MFC--  :~)

>Anyway, that philosophical viewpoint >aside, I still don't see how doing >what I've suggested is a hack.

I think I define a hack slightly different from you, eg. in a situation like this.

>Too bad you won't discuss it >further....

I would like to, but right now I don't have the time ;-(

/Brian
0
Brian_HPAuthor Commented:
Hmm. The ">"s looked better in the edit box than above :(
0
Brian_HPAuthor Commented:
Hi jhance,

>It probably wouldn't be that much work
>especially since you have the source
>code to the MFC classes available for
>inspection.

I cannot find the source code for eg. CListCtrl - the source I can find only covers a few of the methods of the class, these methods only sends messages - it doesn't give me any clues wrt. eg. drawing in the CListCtrl. I would eg. like to write my own methods for drawing.

/Brian
0
jhanceCommented:
The source code to CListCtrl is in:

<VC INSTALL DIRECTORY>\VC98\MFC\SRC\WINCTRL2.CPP


That's all there _IS_ to it!  A CListCtrl is just a window with a certain style.  In this case, it's a Windows list control with an MFC "wrapper" around it.  You can certainly modify the InsertItem to do you bidding....

Otherwise, write a new list control of your own from scratch.
0
Brian_HPAuthor Commented:
Hi jhance

>The source code to CListCtrl is in:
>
><VC INSTALL DIRECTORY>\VC98\MFC\SRC\WINCTRL2.CPP
>
>That's all there _IS_ to it!  A
>CListCtrl is just a window with a
>certain style.  In this case, it's a
>Windows list control with an MFC
>"wrapper" around it.  You can
>certainly modify the InsertItem to do
>you bidding....

Thanks, but that was also what I could find. But the wrapper code does not help me drawing the control correctly.

Do you know where I can find a good implementation of the following methods of CListCtrl:
  OnPaint()
  OnCustomDraw()
  DrawItem()
such that I can improve my own implementation which has some misprints once and awhile.

>Otherwise, write a new list control of
>your own from scratch.

It is not that imporatant!

/Brian
0
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.