I'm working on a dialog based MFC application on Visual Studio 2017 in C++.
In my app I have a window which shows text. I'm using an infinite while loop to write numbers to it when I press "Start" button, and I want to stop this process when I press "Stop" button. The window looks like this:
For this purpose, In the Start
button handler I use a while loop for the counting and printing the counter in the window of the application. I'm checking every time I enter the while loop, if ICD_BUTTON2
(which is the stop button ID) was pressed like this:
void CEditableListControlDlg::OnBnClickedButton1()
{
int counter = 0;
while ((WM_COMMAND != IDC_BUTTON2)) {
counter++;
m_editCtrl.SetWindowTextA(std::to_string(counter).c_str());
}
}
I didn't enter any code in the Stop
button handler.
But my application stopes responding and I need to close it using the task manager. What could be the problem? Perhaps it's not the right way to check if a button clicked message was received?
Thank you.