Link to home
Start Free TrialLog in
Avatar of madhusr
madhusr

asked on

Application Idle time

Hi There,

I would like to write a dll which will monitor the application idle time. When the application becomes idle for certain amount of time without any activity performed in the application (running application includes multiple exes, notepads, winwords, crystal reports, etc.), only all those windows include forms, word documents, notepads, crytal reports and other resources opened through that application should get closed properly.

Any sample code is highly appreciated.

Thanks a lot in advance

Madhu
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of madhusr
madhusr

ASKER

Hi jkr,

Its absolutely working fine throughtout the system but it would be great if we could restrict the system scope to some applications only. An application may have multiple exes invoked in it, whenever there is an activity performed within the defined application scope, the timer needs to updated, otherwise idle time should be increased.

I can increase the points if you could give the expected solution.

Thanks a lot for your efforts.

Madhu
Hi!
based on this article I can say that you need to modify code for these 2 hooks:
//MyKbdHook(...);
 LRESULT CALLBACK MyMouseHook(int code,
                              WPARAM wp,
                              LPARAM lp)
 {
   if (code==HC_ACTION) {
/// here you must get curent process exe name and compare with monitored APP list
    // this line must be executed only when process in the list.
     g_dwLastInputTick = GetTickCount();
   }
   return ::CallNextHookEx(g_hHookMouse,
                           code, wp, lp);
 }
Good Luck
Migel is correct, that's what I meant.
Avatar of madhusr

ASKER

Hi,

Fine but then I would I get a list of processes which have been running from a given application to hook the messages only for those processes.

Thanks a lot for your continuous support.

Madhu
Avatar of madhusr

ASKER

Hi,

Fine but then how would I get a list of processes which have been running from a given application to hook the messages only for those processes.

Thanks a lot for your continuous support.

Madhu
Hi!
Since you have to install global hook, that is hook procedures will be mapped (injected) into the each system process than You need enumerate processes in the procedures.
To enemerate process you can use ToolHelp functions or PSAPI functions(EnumProcess)
see MSDN there are good articles about this
i.e Q175030.
Avatar of madhusr

ASKER

Hi Miqel and Jkr,

Thanks a lot. I combined both of yours suggestions. It is partially working fine. I am opening ms word document from my application. Prior to this document I have an ms word document opened from out side of the application.

when I run my application and check the parent process id of document using CreateToolhelp32Snapshot API, both of the ms word documents have only one winword.exe process running having the parent process id of the previously opened ms word document parent process id(not the parent process id of the application process id). Hence, I am unable to distinguish which word document window belongs my application(I can not hard code any window title because it could be plugged into any application).

In other words, I want to get all the top level window handle which have been opened from my running application.

Please help out in resolving this problem.

I can reward you the 100s of points if it is solved.

Hope you could resolve this problem.

Thank you for support.

Madhu
You can use 'EnumWindows()' to achieve that. All you need to do is storing the PIDs of the instances you launched and compare them in the 'EnumWindowsCallback()' proc using 'GetWindowThreadProcessId()' withe the window handle.
Avatar of madhusr

ASKER

Hi jkr,

Thanks a lot for your suggestion but how would I get only those particular top level window handles or processids which have been opened by my application.

Once again thanks a lot for your halp.

Madhu
Are you tragetting NT-only sytems?
Avatar of madhusr

ASKER

Hi jkr,

All Microsoft platforms like Windows 9x, Windowd 2K.

Thanks a lot.

--Madhu
Why don't you keep a list of all the PIDs of the processes you launched?
Avatar of madhusr

ASKER

Hi jkr,

I can not keep a list of all the processes because i am injecting my hooking dll to the main form which has numerous menu items. Our main intension is that as menu items anytime may increase or decrease, we don't want to change the dll code. My dll should automatically take care of.

Thanks a lot.

--Madhu