Applications that must block shutdown should use the new shutdown reason
API
In Windows XP, Microsoft recommended that if an application needed to block shutdown, it should display its own UI explaining why it needed to do so, so users would be less frustrated when shutdown failed. As discussed earlier, Windows Vista will reduce user frustration when shutdown fails even more, by displaying new UI that lists all the reasons applications have provided for blocking shutdown.
In Windows Vista, if your application must block shutdown, in addition to returning FALSE or not responding to WM_QUERYENDSESSION, it should leverage this new UI by using a simple
API to provide Windows with a reason string explaining why it is blocking shutdown. This
API is straightforward:
BOOL ShutdownBlockReasonCreate(HWND hWnd, LPCWSTR pwszReason);
BOOL ShutdownBlockReasonDestroy(HWND hWnd);
BOOL ShutdownBlockReasonQuery(HWND hWnd, LPWSTR pwszBuff, DWORD *pcchBuff);
Use of this
API is detailed more fully later in this topic, as well as in the
MSDN documentation for the individual ShutdownBlockReason() functions.
Again, note that this
API does not replace the need to return FALSE (or delay responding) to WM_QUERYENDSESSION to block shutdown. Applications need to do this in addition to using the
API. Applications that return TRUE to WM_QUERYENDSESSION will be closed at shutdown, regardless of whether they have used the
API.
Also note that if your application has no visible top-level windows, it must use this
API if it needs to successfully block shutdown. Such applications will automatically be terminated if they block shutdown without using the
API.