Solved

Application Idle time

Posted on 2002-06-22
14
243 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:madhusr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 2
14 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 7100744
Check http://www.microsoft.com/msj/0200/c++/c++0200.asp - it shows how to use hooks to determinse the system idle time, but this can easily be converted to suite your needs (multiple exes).
0
 

Author Comment

by:madhusr
ID: 7103177
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
0
 
LVL 12

Expert Comment

by:migel
ID: 7103322
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:jkr
ID: 7103409
Migel is correct, that's what I meant.
0
 

Author Comment

by:madhusr
ID: 7106441
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
0
 

Author Comment

by:madhusr
ID: 7106443
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
0
 
LVL 12

Expert Comment

by:migel
ID: 7106625
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.
0
 

Author Comment

by:madhusr
ID: 7149060
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 7149157
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.
0
 

Author Comment

by:madhusr
ID: 7153331
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
0
 
LVL 86

Expert Comment

by:jkr
ID: 7168465
Are you tragetting NT-only sytems?
0
 

Author Comment

by:madhusr
ID: 7168581
Hi jkr,

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

Thanks a lot.

--Madhu
0
 
LVL 86

Expert Comment

by:jkr
ID: 7170400
Why don't you keep a list of all the PIDs of the processes you launched?
0
 

Author Comment

by:madhusr
ID: 7170941
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
modThree challenge 4 103
FizzBuzz challenge 9 84
noX challenge 17 134
Windows shortcut location resolution on double click open 4 50
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question