Quit application when QWindowsSystemTrayIcon receives WM_CLOSE

When an application only has a trayicon and is killed by `taskkill /IM
binary.exe` the trayicon's HWND will receive a WM_CLOSE message. If we
don't handle this, the tray icon will close anyway, but the app still
runs in the task manager.

Fixes: QTBUG-43855
Change-Id: I5f82a068df9c40360bd565a2681e1b37ff114e44
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Jan Niklas Hasse 2019-12-04 10:40:20 +01:00
parent 7cf8c993c7
commit 92cf38018a

View File

@ -62,6 +62,7 @@
#include <QtCore/qrect.h>
#include <QtCore/qvector.h>
#include <QtCore/qsettings.h>
#include <qpa/qwindowsysteminterface.h>
#include <qt_windows.h>
#include <commctrl.h>
@ -136,7 +137,7 @@ extern "C" LRESULT QT_WIN_CALLBACK qWindowsTrayIconWndProc(HWND hwnd, UINT messa
{
if (message == MYWM_TASKBARCREATED || message == MYWM_NOTIFYICON
|| message == WM_INITMENU || message == WM_INITMENUPOPUP
|| message == WM_COMMAND) {
|| message == WM_CLOSE || message == WM_COMMAND) {
const int index = indexOfHwnd(hwnd);
if (index >= 0) {
MSG msg;
@ -439,6 +440,9 @@ bool QWindowsSystemTrayIcon::winEvent(const MSG &message, long *result)
case WM_INITMENUPOPUP:
QWindowsPopupMenu::notifyAboutToShow(reinterpret_cast<HMENU>(message.wParam));
break;
case WM_CLOSE:
QWindowSystemInterface::handleApplicationTermination<QWindowSystemInterface::SynchronousDelivery>();
break;
case WM_COMMAND:
QWindowsPopupMenu::notifyTriggered(LOWORD(message.wParam));
break;