views:

274

answers:

2

We need to record how much time a user may spend in a set of forms. The main challenge is to detect if the user is interacting with the app. So far, I've found this link (http://blog.opennetcf.com/ctacke/2009/05/19/DetectingApplicationIdle.aspx) provided an idea solution but our company is very conservative on open source/3rd party libraries. (I knew installing message filter at form level is another option but it may make the existing app unnecessarily complex. Ideally, I want to install message filter at app level.)

Thanks in advance for any idea or solution.

+2  A: 

There really isn't a simple way using just the CF's built-in functions. You need to see all messages for your app, and an IMessageFilter implementation as outlined in that blog entry (enabled through the SDF since the CF doesn't support them) is the easiest way to get there.

You can always do the same the the SDF is doing by creating your own message pump (by P/Invoking GetMessage, TranslateMessage and DispatchMessage) and then not using Application.Run but your own call. That's all the SDF is doing anyway.

ctacke
A: 

Windows Mobile sets a named event when the user interacts with the system. The name of the event is stored in: HKLM\System\GWE\ActivityEvent. You can setup a thread to wait for this named event to be signaled and figure out if your form is active when the event was triggered. You can use GetForegroundWindow to determine if your window had focus while the event was set.

Another possibility is to subclass your forms using GetWindowLong and SetWindowLong. That would cause all of the messages received by your form to be passed to a new WndProc function. You can check for activity messages (WM_LBUTTONDOWN, WM_LBUTTONUP, WM_COMMAND, etc.) in the WndProc function and then pass the messages back to the original WndProc using the CallWndProc function.

Trevor Balcom
Problem is neither of these are very maintainable. If you add a new Form to your app, you then have to subclass it or add it to your search logic to know if it was your form getting the event.
ctacke
Named event sounds like a good way to go. I am starting with this link (Power to the Developers part 2 , http://blogs.msdn.com/windowsmobile/archive/2005/08/11/450591.aspx). subclass by itself is not complex, but apply it to a selected set of forms and still hide it from other developers may make the solution more complex than it needs to be.
Codism