Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 15th, 2006, 9:15 PM   #1
AntiNinja
Hobbyist Programmer
 
AntiNinja's Avatar
 
Join Date: Jun 2006
Location: The States
Posts: 101
Rep Power: 3 AntiNinja is on a distinguished road
Send a message via AIM to AntiNinja Send a message via Yahoo to AntiNinja
PC shutdown event...?

So I was writing a small app and was wondering what to do if the user presses the power button on their pc whilst the app is still running? I read an article that prevents Standby/Hibernate, but not shutdown...Is it possible to do anything like this in Java?

(Like if I needed to write to a file to save settings and whatnot.)
__________________
Pain is just weakness leaving the body.
AntiNinja is offline   Reply With Quote
Old Nov 15th, 2006, 10:45 PM   #2
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 4 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
The java.util.prefs were introduced in Java 1.4. This package is used to write/read files about your application. Such as saving the window's previous location or the size of the window.

I would recommend, every time a user triggers an event, I would record the information.

Here a link to help you get started: http://javaalmanac.com/egs/java.util.prefs/pkg.html
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Nov 16th, 2006, 6:23 PM   #3
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Off the top of my head, all of your forms/frames/windows will get the WM_CLOSE message on any logout or shutdown event. The actual shutdown does not occur until all windows close, gracefully or otherwise.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Nov 16th, 2006, 7:32 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Actually, I'm not so sure about that. When I was experimenting with drastic shutdowns at the Win API level, the documentation indicated that I had about 20 ms (a relatively long time if one's process doesn't get swapped out) to wrap it all up. You're probably correct, however, if the adjective "otherwise" indicates that one may be dumped in the landfill before finishing the cleanup.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 30th, 2006, 5:56 AM   #5
Harakim
Hobbyist Programmer
 
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3 Harakim is on a distinguished road
Windows will stay open until all of the programs close. I have had it hang and run my battery out on a few occasions because a GDK+ or GDI+ or some kind of window won't close for 6 hours.
Harakim is offline   Reply With Quote
Old Nov 30th, 2006, 6:57 AM   #6
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,261
Rep Power: 5 grumpy will become famous soon enough
Not sure about the java aspects, but the following normally happens after a windows shutdown of logoff is initiated.

1) All windows applications will receive a WM_QUERYENDSESSION message asking for permission to shutdown. An application can indicate, by setting an appropriate flag, that it does want to allow the shutdown/logoff.

2) All windows applications will receive a WM_ENDSESSION message, with a value indicating whether the shutdown is proceeding or not. If shutdown or logoff is occurring, that flag is TRUE.

3) There are a set of similar signals sent to each console process (eg the DOS prompt), to make them shut down as well. I've never developed a console application that needed to respond to a windows shutdown event, so can't give more details.

4) If shutdown is happening, each program is terminated (the sequence of events such as WM_CLOSE for windows applications). This allows the applications to clean up as they terminate (including doing things like prompting a user to save files, which is why a shutdown will not occur while a program waits for user input).


The above is what happens in response to a user manually initiates a shutdown or logs off. It can also be initiated programatically with a call to the win32 API functions ExitWindows() or ExitWindowsEx(). ExitWindowsEx() accepts a flag that allows bypassing of the protocol of asking programs for permission to shutdown in emergency situations (it basically shuts down applications with prejudice, and does not allow data to be saved) --- that can't be done manually. Such a technique is one that should be used with extreme caution, as it can make your program unpopular with users.
grumpy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MAC remote shutdown tool Baphomet Coder's Corner Lounge 9 Nov 28th, 2006 9:14 PM
School's Out Bash - LAN Event in Ash Flat, Arkansas bigguy Coder's Corner Lounge 21 Apr 24th, 2006 5:12 PM
console event handling jayme C++ 3 Jan 1st, 2006 3:40 PM
question: usage of delagates and custom events melbolt C# 1 Oct 3rd, 2005 8:17 PM
Help! I have a problem thomas55 C++ 1 Apr 24th, 2005 2:16 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:12 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC