I have a different requirement in one of my projects, when I run my exe and make it idle (i.e. without click, min, max), after a period of time (timer) it should be automatically closed. If anyone clicked before the particular time, the timer must reset for the same period. How can I find out whether the exe is idle or not?
+1
A:
You might want to take a look at the Application.Idle
event (Note: Only applicable to a WinForms application, as far as I'm aware).
If you combine it with a timer that you stop/reset whenever your application receives input, that should give you pretty much what you're looking for.
Rob
2010-08-02 09:44:49
Hi rob thanks for your reply,actually i used some unmanaged code and achieved it.i will post it here.Thanks
karthik
2010-08-02 10:15:51
A:
public class GlobalMouseHandler : IMessageFilter
{
public delegate void EventHandlerForActiveState();
public event EventHandlerForActiveState onActive;
public event EventHandlerForActiveState onStateChanged;
private const int WM_KEYDOWN = 0x100;
//private const int WM_HSCROLL = 0x114;
//private const int WM_VSCROLL = 0x115;
private const int WM_LBUTTONDOWN = 0x201;
private const int WM_LBUTTONUP = 0x202;
private const int WM_RBUTTONDOWN = 0x204;
private const int WM_RBUTTONUP = 0x205;
//private const int WM_MBUTTONDBLCLK = 0x209;
private const int WM_MOUSEWHEEL = 0x20A;
private const int WM_GETMINMAXINFO = 0x024;
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == 275)
{
return false;
}
switch (m.Msg)
{
case WM_LBUTTONDOWN:
if (onActive != null)
onActive();
break;
case WM_LBUTTONUP:
if (onActive != null)
onActive();
break;
case WM_RBUTTONDOWN:
if (onActive != null)
onActive();
break;
case WM_RBUTTONUP:
if (onActive != null)
onActive();
break;
case WM_MOUSEWHEEL:
if (onActive != null)
onActive();
break;
//case WM_ACTIVATE:
// if (onActive != null)
// onActive();
// break;
case WM_KEYDOWN:
if (onActive != null)
onActive();
break;
case WM_GETMINMAXINFO:
if (onStateChanged != null)
onStateChanged();
break;
//case WM_HSCROLL:
// if (onActive != null)
// onActive();
// break;
//case WM_VSCROLL:
// if (onActive != null)
// onActive();
// break;
}
return false;
}
}
GlobalMouseHandler handle = new GlobalMouseHandler(); handle.onActive += new GlobalMouseHandler.EventHandlerForActiveState(handle_onActive); Application.AddMessageFilter(handle); I used this class and done this.
karthik
2010-08-02 10:16:55
Missed some. Check http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/815cfbf9-2303-4637-a7c2-d25ef5c1eeb3
Hans Passant
2010-08-02 15:26:50