|
-
Jun 18th, 2013, 02:28 PM
#23
Re: Prevent windows shutdown
 Originally Posted by Korku
But it's not what I want. What I want is that ...
You should've made that clear right from the start. 
 Originally Posted by Korku
... when you try to shut down the computer with the application open, display a message something like "You must close the application before turning off the computer."
ShutdownBlockReasonCreate already does that. Isn't that what you want? The SHUTDOWN_BLOCK_REASON constant in the example code in post #25 above can be modified as desired.
 Originally Posted by Korku
Also this sample code closes the programs that are in the background.
Well, it could be because of the reason mentioned in posts #3 & #4. It might also be because those programs have no visible top-level window. As discussed in the Application Shutdown Changes in Windows Vista:
 Originally Posted by MSDN
Windows Vista will also not allow console applications or applications that have no visible top-level windows to block shutdown. In most cases, such applications are less important to users at shutdown than applications that do have visible top-level windows. If an application without a visible top-level window blocks shutdown by vetoing WM_QUERYENDSESSION, or takes over 5 seconds to respond to WM_QUERYENDSESSION or WM_ENDSESSION, Windows will automatically terminate it.
 Originally Posted by Korku
I'm trying to make a remote connection application for a tablet with Windows 8, I wanted to avoid placing in sleep mode or turned off when the application is open.
As pointed out several times already, you shouldn't prevent the user from shutting down the computer. Even Microsoft agrees:
 Originally Posted by Application Shutdown Changes in Windows Vista
Applications should not block shutdown
If you take only one thing away from reading this topic, it should be this one. You will be presenting the best experience to your users if your application does not block shutdown. When users initiate shutdown, in the vast majority of cases, they have a strong desire to see shutdown succeed; they may be in a hurry to leave the office for the weekend, for example. Applications should respect this desire by not blocking shutdown if at all possible.
In many cases, applications that block shutdown can be redesigned so that they no longer need to do so. For example, applications with unsaved data at shutdown can be designed to automatically save their data and restore it when the user next starts the application, instead of blocking shutdown to ask the user what to do. Microsoft Office 2007 will do this in certain scenarios.
In other cases, there is usually a sensible default action that applications should automatically perform, instead of blocking shutdown to ask the user what to do. In many cases, this is true even if the default action could be slightly destructive. Read more...
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|