Guest User

Untitled

a guest
May 6th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. How to make an infinite loop in c ? (Windows)
  2. for (;;) {}
  3.  
  4. while(true){}
  5.  
  6. #define WINDOWS_LEAN_AND_MEAN
  7. #define _WIN32_WINNT 0x0500
  8. #include <windows.h>
  9. #include <iostream>
  10.  
  11. // do something after 10 minutes of user inactivity
  12. static const unsigned int idle_milliseconds = 60*10*1000;
  13. // wait at least an hour between two runs
  14. static const unsigned int interval = 60*60*1000;
  15.  
  16. int main() {
  17.  
  18. LASTINPUTINFO last_input;
  19. BOOL screensaver_active;
  20.  
  21. // main loop to check if user has been idle long enough
  22. for (;;) {
  23. if ( !GetLastInputInfo(&last_input)
  24. || !SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0,
  25. &screensaver_active, 0))
  26. {
  27. std::cerr << "WinAPI failed!" << std::endl;
  28. return EXIT_FAILURE;
  29. }
  30.  
  31. if (last_input.dwTime < idle_milliseconds && !screensaver_active) {
  32. // user hasn't been idle for long enough
  33. // AND no screensaver is running
  34. Sleep(1000);
  35. continue;
  36. }
  37.  
  38. // user has been idle at least 10 minutes
  39. HWND hWnd = GetConsoleWindow();
  40. ShowWindow( hWnd, SW_HIDE );
  41. system("C:\Windows\software.exe");
  42. // done. Wait before doing the next loop.
  43. Sleep(interval);
  44. }
  45. }
  46.  
  47. while(true){
  48. //Do something
  49. }
  50.  
  51. bool isRunning = true;
  52. while( isRunning ){
  53. //Do something
  54. }
  55.  
  56. for (;;) // or while(1), doesn't matter
  57. {
  58. function();
  59. sleep(1000);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment