visual c++ - Having time waiting in C++ programs -


I read the book for my compiler, graphics installed on MS Visual Studio 2012. The machine I am using is MS Windows 7.
I have read up to the 17th chapter and I have not studied any method to wait. By waiting, I mean executing a statement, waiting for a while for the system and executing the second statement.

The following describes a simple example that draws two sizes on the window. There are graphics libraries used for the book.

For example, in this code, I have two codes with two different posts and different radios.
I want to attach the code first> circle ( c1 ), by waiting one second, separate c1 and at this time the C2 Attached Please wait for a second (or more) of what is the easiest way?

  #include & lt; Windows.h & gt; # Include & lt; GUI.h & gt; Graph_lib using the namespace; // --------------------------------- Class test: public window {public: test (point p, int w , Ath, const string and title): Window (P, W, H, Titles), Examination buttons (point (x_max () - 90,20), 60, 20, "Quit", cb_quit), C1 (Point (100,100), 50), c2 (point (300,200), 100) {enclosed (left_button); Attached (C1); Attached (C2); Private: Circle C1, C2; Button release_button; Out of zero () (hide ()); } Fixed zero cb_quit (address, address PW) {reference_so < Test & gt; (PW) .quit ();}}; // ------------------ int main () {test ts (point (300,250), 800, 600, "test"); Return gui_main (); }  

If you are using c ++ 11:

  std :: this_thread :: sleep_for (std :: chrono :: seconds (1));  

Otherwise use the Windows Function Sleep.

And if you want to wait without blocking the main thread, you can use std :: async:

 Add  #. Future & gt; // Add your own test std :: async ([& amp;] () {attach (quit_button); enclosed (c1); std :: this_thread :: sleep_for (std :: chrono :: seconds (1)) (Attach) c2);});  

This is probably not working, because I do not know much about the library you are using.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -