Closing a window

  • Thread starter Thread starter csshelton70
  • Start date Start date
C

csshelton70

Hopefully, someone can help out:

I'm working on a program to close a specific application after X
minutes of inactivity. I have all of the code working to identify the
main window and close it, but I'm having an issue identifying when any
other secondary window other than the main window of the program is
open. These secondary windows do not have a standard naming convention
( so I cannot search by name) , nor do they show up as having the main
window as their owner or parent (so I can't just check to see if it's a
child window). I'm hoping someone that knows more of the windows API
can make a suggestion how to identify these secondary windows as
belonging to that app.


Thanks.
 
Hopefully, someone can help out:

I'm working on a program to close a specific application after X
minutes of inactivity. I have all of the code working to identify the
main window and close it, but I'm having an issue identifying when any
other secondary window other than the main window of the program is
open. These secondary windows do not have a standard naming convention
( so I cannot search by name) , nor do they show up as having the main
window as their owner or parent (so I can't just check to see if it's a
child window). I'm hoping someone that knows more of the windows API
can make a suggestion how to identify these secondary windows as
belonging to that app.


Thanks.

Have you tried FindWindowEx?
 
Yes.

The logic is basically thus:

I get the MainWindowID by looping through all the windows ( using
findwindowex ) and then comparing the caption to what I know it should
be using GetWindowText.

On a timer set to fire every 5 seconds
As long as the program is running ( MainWindowID !=0 )
I get the activeWidowID ( using GetForegroundWindow )
If MainWindowID = ActiveWindowID, then I know they are using the
program and set failurecount = 0

<here is the part I can't figure out>
If the ActiveWindowID != MainWindowID then I know that they MIGHT
be using the program
In testing, I made sure the active window was one of the secondary
windows created by the main program. I tried checking the parent or
owner of the activewindow to see if either matches the MainWindowID,
but the parent is 0 and the owner is itself. I know that the program
in question created the secondary windows, but I cannot figure out how
to determine if the active window is one of these secondary windows
using the WindowsAPI.
</here is the part I can't figure out>

if failurecount > 20, then I assume they havent used the software in
the last minute and PostMessage to the MainWindowID to WM_CLOSE it
 
Yes.

The logic is basically thus:

I get the MainWindowID by looping through all the windows ( using
findwindowex ) and then comparing the caption to what I know it should
be using GetWindowText.

On a timer set to fire every 5 seconds
As long as the program is running ( MainWindowID !=0 )
I get the activeWidowID ( using GetForegroundWindow )
If MainWindowID = ActiveWindowID, then I know they are using the
program and set failurecount = 0

<here is the part I can't figure out>
If the ActiveWindowID != MainWindowID then I know that they MIGHT
be using the program
In testing, I made sure the active window was one of the secondary
windows created by the main program. I tried checking the parent or
owner of the activewindow to see if either matches the MainWindowID,
but the parent is 0 and the owner is itself. I know that the program
in question created the secondary windows, but I cannot figure out how
to determine if the active window is one of these secondary windows
using the WindowsAPI.
</here is the part I can't figure out>

if failurecount > 20, then I assume they havent used the software in
the last minute and PostMessage to the MainWindowID to WM_CLOSE it

It sounds like you are a little unsure of exactly what window you are
trying to access. Have you tried using Spy++ to isolate the window you
need?
 
Back
Top