[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

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

Posted on 2000-01-05
10
Medium Priority
?
658 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:Brian_HP
  • 6
  • 4
10 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 2325620
>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
 

Author Comment

by:Brian_HP
ID: 2359008
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
 
LVL 32

Expert Comment

by:jhance
ID: 2359332
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 

Author Comment

by:Brian_HP
ID: 2359393
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
 
LVL 32

Expert Comment

by:jhance
ID: 2360088
>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
 

Author Comment

by:Brian_HP
ID: 2362052
>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
 

Author Comment

by:Brian_HP
ID: 2362062
Hmm. The ">"s looked better in the edit box than above :(
0
 

Author Comment

by:Brian_HP
ID: 2477827
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
 
LVL 32

Expert Comment

by:jhance
ID: 2478150
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
 

Author Comment

by:Brian_HP
ID: 2478332
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question