Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

(Windows)Can I get the program to be changed or be stopped while it is running?

I am now writing a win32 program in C++.
I want to show my running process on the window, just like time is flowing.

For example, this code

int a=0;
for(int i=0;i<10;i++)
{
  a++;//The change in "a" can be seen on the window.
  Sleep(1*1000);
}

But I’ve found that if I want to show this process, like clicking a button and a changing number appears on the screen, then the program needs to be running all the time. At this point, I don’t have a way to do anything else, like clicking on another button.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So I realized I needed an operation that could interrupt the current process. But I went through a lot of information and found that only the fork() function of the Linux system can meet my needs. But I’m using Windows now, so what other ways can I achieve this?
Sincerely look forward to your reply.

>Solution :

You want to create a timer with SetTimer. Then watch for the WM_TIMER messages and update the screen then. This is the standard way of achieving what you described.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading