From e6d4bdd43ca8f9e0a3ad51c5d59b70c20ce4b9d8 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Thu, 7 Oct 2021 00:25:11 +0800 Subject: [PATCH] - implement: handle windows logout message --- NEWS.md | 1 + RedPandaIDE/main.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/NEWS.md b/NEWS.md index efb1fe73..47138668 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,6 +24,7 @@ Version 0.6.0 - fix: makefile generated for static / dynamic library projects not right - fix: editors disappeared when close/close all - implement: config shortcuts + - implement: handle windows logout message Version 0.5.0 - enhancement: support C++ using type alias; diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index b59b48da..3ad4d600 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "common.h" #include "colorscheme.h" #include "iconsmanager.h" @@ -16,6 +17,27 @@ #include "platform.h" #include "parser/parserutils.h" #include "editorlist.h" +#include + +class WindowLogoutEventFilter : public QAbstractNativeEventFilter { + + // QAbstractNativeEventFilter interface +public: + bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override; +}; + +bool WindowLogoutEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result){ + MSG * pMsg = static_cast(message); + if (pMsg->message == WM_QUERYENDSESSION) { + if (!pMainWindow->close()) { + *result = 0; + } else { + *result = 1; + } + return true; + } + return false; +} QString getSettingFilename(const QString& filepath = QString()) { QString filename; @@ -110,6 +132,8 @@ int main(int argc, char *argv[]) } } mainWindow.show(); + WindowLogoutEventFilter filter; + app.installNativeEventFilter(&filter); int retCode = app.exec(); // save settings // settings->compilerSets().saveSets();