Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a CListCtrl in which im continously adding items to the list using a while loop. Now i want to stop adding items to the list when the user clicks on a button.now i want a if statement to check if a button is clicked.what statement should i use in the while loop to check if a the button is clicked?
Posted

Create a member variable bool value to check whether it is clicked.

When it is clicked then make it as true.

Now add the message ON_BN_CLICKED and inside that mapped function, change the status of hte bool value as true.
 
Share this answer
 
Adding continously - but how?

Are you using a loop in the same thread? If yes, you cannot handle the Stop event that easily. The event would not be raised, since message-pump will not get time to process the user's action. You either need to call PeekMessage within the loop, or make your program multithreaded.


Read this article:
The Practical Guide to Multithreading - Part 1[^]
 
Share this answer
 
put a call procedure into the loop that looks to the button, and if pressed breaks.
 
Share this answer
 
First add one Button in your Dialog/View. Then set a name of that Button ( e.g. I set a name BTN_STOP_NOW). Now double click on that button it will add one Method autometically

OnBTN_STOP_NOW()
{

//Add your code to stop adding Item into the list
//NOTE: You need not to check for any If condition.
//Anything you put ib this method, that will take care
//by windows autometically when this button will b pressed
}

When we add any controls, that will gets added inside windows DDX/PDX Map. Which will used by windows at run time, to get validated of that controls & for messages passing purpose. So, window will take care of that autometically, to check if the button pressed or not
 
Share this answer
 
I've offer a simple way: create a boolean variables and then check state of variable when a button is clicked.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900