Solved

Application Idle time

Posted on 2002-06-22
14
237 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MFC Dialog 9 47
configuration management 2 100
lucky13 challenge 11 112
Modbus - whats the maximum I can store in one register? 4 75
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.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

16 Experts available now in Live!

Get 1:1 Help Now