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