Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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.
16bool WinShutdownMonitor::nativeEventFilter(const QByteArray &eventType,
17 void *pMessage, long *pnResult) {
19
20 MSG *pMsg = static_cast<MSG *>(pMessage);
21
22 switch (pMsg->message) {
23 case WM_QUERYENDSESSION: {
24 // Initiate a client shutdown after receiving a WM_QUERYENDSESSION
25 // and block
26 // Windows session end until we have finished client shutdown.
28 *pnResult = FALSE;
29 return true;
30 }
31
32 case WM_ENDSESSION: {
33 *pnResult = FALSE;
34 return true;
35 }
36 }
37
38 return false;
39}
40
41void WinShutdownMonitor::registerShutdownBlockReason(const QString &strReason,
42 const HWND &mainWinId) {
43 typedef BOOL(WINAPI * PSHUTDOWNBRCREATE)(HWND, LPCWSTR);
45 GetModuleHandleA("User32.dll"), "ShutdownBlockReasonCreate");
46 if (shutdownBRCreate == nullptr) {
47 qWarning() << "registerShutdownBlockReason: GetProcAddress for "
48 "ShutdownBlockReasonCreate failed";
49 return;
50 }
51
52 if (shutdownBRCreate(mainWinId, strReason.toStdWString().c_str()))
53 qInfo() << "registerShutdownBlockReason: Successfully registered: " +
55 else
56 qWarning() << "registerShutdownBlockReason: Failed to register: " +
58}
59#endif
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
void StartShutdown()
Request shutdown of the application.
Definition shutdown.cpp:55