Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2005

Tip: Looking for answers? Try searching our database.

Closing a window

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
csshelton70@gmail.com - 29 Dec 2005 14:45 GMT
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.
Rob Schieber - 29 Dec 2005 14:58 GMT
> Hopefully, someone can help out:
>
[quoted text clipped - 10 lines]
>
> Thanks.

Have you tried FindWindowEx?

Signature

Rob Schieber

csshelton70@gmail.com - 29 Dec 2005 16:01 GMT
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
Rob Schieber - 29 Dec 2005 17:51 GMT
> Yes.
>
[quoted text clipped - 24 lines]
>   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?

Signature

Rob Schieber

AlexS - 29 Dec 2005 23:17 GMT
Did you check GetParent / GetAncestor APIs?

HTH
Alex

> Hopefully, someone can help out:
>
[quoted text clipped - 10 lines]
>
> Thanks.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.