Solved

Application Idle time

Posted on 2002-06-22
14
242 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 96
How do you programatically show and hide the Windows 10 On-Screen-Keyboard? 3 803
unix example issues 18 99
Increment column based of a FK 8 31
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 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