Bitcoin ABC 0.33.3
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 =
50 (PSHUTDOWNBRCREATE)(void *)GetProcAddress(
51 GetModuleHandleA("User32.dll"), "ShutdownBlockReasonCreate");
52 if (shutdownBRCreate == nullptr) {
53 qWarning() << "registerShutdownBlockReason: GetProcAddress for "
54 "ShutdownBlockReasonCreate failed";
55 return;
56 }
57
58 if (shutdownBRCreate(mainWinId, strReason.toStdWString().c_str()))
59 qInfo() << "registerShutdownBlockReason: Successfully registered: " +
60 strReason;
61 else
62 qWarning() << "registerShutdownBlockReason: Failed to register: " +
63 strReason;
64}
65#endif
void StartShutdown()
Request shutdown of the application.
Definition: shutdown.cpp:16