Hi Bala,
Thanks for your post.
I think this is an interesting question. The implementation is based on
your program logic definition for "idle". For example, the "idle" maybe
mean a period of time without any mouse/keyboard input. However, I think it
is reasonable to ignore the WM_MOUSEMOVE messages, because even when your
form is in background, when the mouse cursor moves move your form window,
the WM_MOUSEMOVE message will be prompt to your application, this should
not be recognized as "active" state.
So, our design can use a timer component to calculate the idle time, and
any "active" mouse/keyboard messages can reset this timer to start again
from 0. Once the timer calculated without any active input for your setting
time(for example 20 minutes), we can ask the user for re-login.
In .Net winform, to get all the input messages, we can add a Message filter
on the main GUI thread(with IMessageFilter interface), then we can get
notification in IMessageFilter.PreFilterMessage method. In this method, we
can reset timer for any "active" input messages, such as WM_LBUTTONDOWN,
WM_RBUTTONDOWN, WM_KEYDOWN etc... Below is the sample code snippet:
static void Main()
{
Application.AddMessageFilter(new TestMessageFilter());
Application.Run(new Form1());
}
public class TestMessageFilter : IMessageFilter
{
private int WM_LBUTTONDOWN=0x0201;
private int WM_KEYDOWN=0x0100;
public bool PreFilterMessage(ref Message m)
{
// Blocks all the messages relating to the left mouse button.
if (m.Msg==WM_LBUTTONDOWN||m.Msg==WM_KEYDOWN||other active messages)
{
Console.WriteLine("Processing the messages : " + m.Msg);
//reset the timer.
}
return false;
}
}
Hope this helps
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.