Bitcoin ABC 0.32.4
P2P Digital Currency
winshutdownmonitor.cpp
Go to the documentation of this file.
1// Copyright (c) 2014-2016 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6
7#if defined(Q_OS_WIN)
8#include <shutdown.h>
9
10#include <QDebug>
11
12#include <windows.h>
13
14// If we don't want a message to be processed by Qt, return true and set result
15// to the value that the window procedure should return. Otherwise return false.
16#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
17bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType,
18 void *pMessage, qintptr *pnResult) {
19#else
20bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType,
21 void *pMessage, long *pnResult) {
22#endif
23 Q_UNUSED(eventType);
24
25 MSG *pMsg = static_cast<MSG *>(pMessage);
26
27 switch (pMsg->message) {
28 case WM_QUERYENDSESSION: {
29 // Initiate a client shutdown after receiving a WM_QUERYENDSESSION
30 // and block
31 // Windows session end until we have finished client shutdown.
33 *pnResult = FALSE;
34 return true;
35 }
36
37 case WM_ENDSESSION: {
38 *pnResult = FALSE;
39 return true;
40 }
41 }
42
43 return false;
44}
45
46void WinShutdownMonitor::registerShutdownBlockReason(const QString &strReason,
47 const HWND &mainWinId) {
48 typedef BOOL(WINAPI * PSHUTDOWNBRCREATE)(HWND, LPCWSTR);
49 PSHUTDOWNBRCREATE shutdownBRCreate = (PSHUTDOWNBRCREATE)GetProcAddress(
50 GetModuleHandleA("User32.dll"), "ShutdownBlockReasonCreate");
51 if (shutdownBRCreate == nullptr) {
52 qWarning() << "registerShutdownBlockReason: GetProcAddress for "
53 "ShutdownBlockReasonCreate failed";
54 return;
55 }
56
57 if (shutdownBRCreate(mainWinId, strReason.toStdWString().c_str()))
58 qInfo() << "registerShutdownBlockReason: Successfully registered: " +
59 strReason;
60 else
61 qWarning() << "registerShutdownBlockReason: Failed to register: " +
62 strReason;
63}
64#endif
void StartShutdown()
Request shutdown of the application.
Definition: shutdown.cpp:16