[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to cancel the population of a CListView?

Posted on 2000-05-01
15
Medium Priority
?
249 Views
Last Modified: 2013-11-20
I have an SDI application and the view class is derived from CListView.  I populate the list view with potentially a large number of records which could take a minute or so.  I want the user to be able to cancel the operation while the list view is populating.  

How can I do this?  Is there some sort of call back function?
0
Comment
Question by:wzhxxj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
  • 2
15 Comments
 
LVL 3

Expert Comment

by:Shay050799
ID: 2766172
did u try to have a progress dialog, with a cancel button on it ?
0
 

Author Comment

by:wzhxxj
ID: 2766500
No, what I really want to do is to have a button on the toolbar that is enabled when the list box is populating.  Then the user has the option of pressing this cancel button and terminating the population of the list view.  Problem is that when the list view is populating, the application has not transferred control back to the application.

Would a progress bar help me with this?  If so, how?
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 2766511
try multythreaded
make the feeling of the listview another thread
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:wzhxxj
ID: 2766743
Any suggestions on how I would do this?
0
 
LVL 3

Expert Comment

by:GlennDean
ID: 2766834
Spin off a worker thread via AfxBeginThread("Function to populate list",&paramsNeededByThread);

Then, in the paramsNeededByThread structure store the "this" pointer of the View class.  

You do have to be careful about some stuff like
1.  Make sure that the worker thread function, if defined as a member function in a class is defined as static so it doesn't receive the hidden this pointer.
   Glenn
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 2766841
i still think the easiest way is just to create a progress dialog, and check for cancel...
you do not have to hassle with thread sync at all !!!
0
 
LVL 3

Expert Comment

by:GlennDean
ID: 2766868
You make a good point.  It does get messy, because one would have to also create an event or a variable so that the worker thread would have to check periodically to see if it should stop populating and exit.  

wzhxxi: What function are you populating the list?  It sounded like in a message handler, which is why pressing a button to cancel wouldn't work?
   Glenn

0
 

Author Comment

by:wzhxxj
ID: 2769073
Yes, I am populating the list in a message handler - i'm using the OnUpdate() event handler.  How would I do it with a progress dialog?? Are you guys referring to the progress bar??
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 2769082
in onUpdate you are running through the list in a do while loop or a like ?
if so, create the CProgressCtrl and check the cancel button every time u get to the While loop again

while
{
   check for cancel
   ...
}
0
 

Author Comment

by:wzhxxj
ID: 2769121
In this case, I would have to create a modeless dialog box with a CProgressCtrl and a cancel button on it?  Is this what you are suggesting?

0
 
LVL 3

Accepted Solution

by:
Shay050799 earned 400 total points
ID: 2769152
well progressctrl does that for you
go to Project->Add To Project->Components and controls
and chose the visual studio controls

add the progress dialog into the project
it already has the functionality to check cancel and everything

make sure that u do the following

CProgressDlg progDlg(FF_IDS_PROGRESS_CAPTION); //the dialog
progDlg.Create(this);                  
progDlg.SetStatus("Processing...");      

while(...)
{
   if(progDlg.CheckCancelButton())
   {                              break;
   }            
   ... do ur stuff here ...
}

any question ? ask !
0
 

Author Comment

by:wzhxxj
ID: 2769178
Shay, thanks for all your help !!  
There are obviously lots of ways to do a particular thing - I try to find the simplest solution to the problem.

Thanks again.
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 2769191
did u try it ?
does it work ?
if not feel free to ask more questions
it won't cost u a dime :-)

Shay
0
 

Author Comment

by:wzhxxj
ID: 2771161
Yeah, I tried it.  Works like a charm!
0
 
LVL 3

Expert Comment

by:Shay050799
ID: 2773926
well wzhxxj there is another way to do it without the progressbar.
i m sorry i didn't mentioned it earlier, i just went a cross the same problem, and since just like u i do not want the progress bar to show up  
i did the following:

while(1)
{
    m_MyList.AddString(somestring);
    somestring = readstringfromfile();
   
    MSG msg;
    while ( ::PeekMessage( &msg, NULL,  0, 0, PM_NOREMOVE ) )                if ( !AfxGetApp()->PumpMessage());      
}


this message loop will let u (the application) to proccess new message while it process ur function

try it out , it works for me

take care

Shay
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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. …
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

656 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