Code C++ progrom in Visual Studio to run another program.

I am needing to code a program that will run a additional program after 3 minutes of inactivity on my laptop. I know some basic coding in C++ and am not skilled enough to perform this. IF someone could help me that would be most helpful.
Add this function in the CWinApp derived class. It calculates the amount of time the application was idle and then creates the process specified.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
BOOL OnIdle(LONG count)
{
static CTime starttime;
		CTimeSpan span;
		if(count==0)
		{
			starttime=CTime::GetCurrentTime();
			span=0;
		}
		else
		{
			span=CTime::GetCurrentTime()-starttime;
		}
		if(span.GetTotalSeconds()==180)
		{
			ShellExecute( NULL, NULL, YourProgramName , NULL, NULL, SW_SHOW );
		}
		CWinApp::OnIdle(count);
		return true;
	}
If I read you right, you want to work out when the whole PC is idle, rather than when your app is idle. If so, I think you might need to check what the CPU is up to. In that case this article might help:

Get CPU Usage with GetSystemTimes
http://www.codeproject.com/Articles/9113/Get-CPU-Usage-with-GetSystemTimes

Andy

GetSystemTimes function
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724400%28v=vs.85%29.aspx

Last edited on
Topic archived. No new replies allowed.