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 / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Checking for logout when closing a form?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy Pickering - 14 Apr 2005 18:01 GMT
I've written an app that minimises to the system tray when the 'close'
button is clicked (I'm setting the Cancel flag in my formname_Closing event
handler).  This works fine until you try to logout of Windows - the logout
is unable to stop my app!  Is there any way to check whether the user is
logging out/Windows is shutting down - or am I barking up the wrong tree?

Any pointers gratefully received.

Andy
Diggers - 14 Apr 2005 18:11 GMT
Odd!!!,

Can I just check, are you saying that if you shutdown windows it works
but not when you log off, or neither works.

Simon
Andy Pickering - 14 Apr 2005 18:23 GMT
Both logout and shutdown don't complete until I exit my app!  All I'm doing
in my form's Closing event handler is setting the Cancel flag to True and
then calling the Hide() method.  I would have thought that Windows closing
down or logging out would have automatically 'overruled' this....

> Odd!!!,
>
> Can I just check, are you saying that if you shutdown windows it works
> but not when you log off, or neither works.
>
> Simon
Diggers - 14 Apr 2005 18:39 GMT
Ah ok,

Setting the CancelEventArgs.Cancel to true will cancel closing the
form. Maybe its got to do with the fact that windows tries to close it,
you don't let Windows do that and then Hide the form (which of course
means its still running). Is there any reason to set the Cancel flag to
true and if so (for example you need to do some cleaning up first), do
your cleanup and then Close the form instead of hiding it.

Make sense?

Simon Rigby
Andy Pickering - 14 Apr 2005 18:56 GMT
Simon - thanks for the response.

The idea was that when the user clicks the form's close button, the app
minimises to the system tray - a bit like MSN Messenger.  To implement this
I added the 'Closing' event handler (I was hoping this would work similar to
the old 'QueryUnload' event from my VB6 days....).  In operation, it works
fine - it just has this unfortunate side effect!

> Ah ok,
>
[quoted text clipped - 8 lines]
>
> Simon Rigby
Diggers - 14 Apr 2005 19:00 GMT
ah of course, yes sorry you did mention that.

Hmm, I'll have a play and get back to you.

Simon
José Manuel Agüero - 14 Apr 2005 19:22 GMT
Hello, Andy:

Maybe you can handle the Microsoft.Win32.SystemEvents.SessionEnding event to know wheter the system is shutting down.
In the documentation for this event there is a sample of how to override the WndProc to achieve the same functionality.

Regards.

| I've written an app that minimises to the system tray when the 'close'
| button is clicked (I'm setting the Cancel flag in my formname_Closing event
[quoted text clipped - 5 lines]
|
| Andy

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.