Hello. I use Visual C ++ 2010. I encountered such a problem - I cannot create a delay to call a function (I need to call it, say, once a minute).

I have a button, I click on it, the cycle starts:

while(true) { ScreenShot (HWND); } 

I have to perform this function, of course, not every second, but, for example, once a minute. Sleep (); Before the function causes the program to hang (well, there is a lot of information about this in Google) Please tell me how you can cause a delay in execution. With SetTimer something I did not understand.

  • And what is your program? Command line? Windows application without UI? UI on pure WinAPI? MFC? Qt? - VladD
  • If the framework you are using has timers, then use them. If not, then, as an option, by clicking on the button, create a separate stream and do a ScreenShot call with a delay between calls - Donil

2 answers 2

If the program is with a window, then create a timer via SetTimer , and in the window function call ScreenShot (HWND) by the message WM_TIMER ;
The second option is to pass the code you specify to a separate stream. Then kill him if necessary.

    To implement your ideas, you will need threads or libraries of asynchronous execution. I recommend to look towards Boost.Thread and / or Boost.ASIO .