Solved

Application Idle time

Posted on 2002-06-22
14
239 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WinWaitActive parameters 12 31
conditional code and condition difference 9 82
Is there a simple front-end menu system. 9 88
x-bar in Google Sheets 2 50
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

815 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now