Windows QPA: Move the code installing the filter for WM_TASKBARCREATED

Previously, the code was in the constructor, where hwnd was 0 and
ChangeWindowMessageFilterEx() failed. Move it into
QWindowsSystemTrayIcon::ensureInstalled() after the creation of the message
window.

Change-Id: Iff4c6d6d6b11bdcace7514ad421c96c94e52bbba
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Friedemann Kleint 2019-01-23 08:38:08 +01:00
parent 4aa0bcf5f5
commit c154766630

View File

@ -183,12 +183,6 @@ static inline HWND createTrayIconMessageWindow()
QWindowsSystemTrayIcon::QWindowsSystemTrayIcon()
{
// For restoring the tray icon after explorer crashes
if (!MYWM_TASKBARCREATED)
MYWM_TASKBARCREATED = RegisterWindowMessage(L"TaskbarCreated");
// Allow the WM_TASKBARCREATED message through the UIPI filter
ChangeWindowMessageFilterEx(m_hwnd, MYWM_TASKBARCREATED, MSGFLT_ALLOW, 0);
qCDebug(lcQpaTrayIcon) << __FUNCTION__ << this << "MYWM_TASKBARCREATED=" << MYWM_TASKBARCREATED;
}
QWindowsSystemTrayIcon::~QWindowsSystemTrayIcon()
@ -320,6 +314,13 @@ bool QWindowsSystemTrayIcon::ensureInstalled()
m_hwnd = createTrayIconMessageWindow();
if (Q_UNLIKELY(m_hwnd == nullptr))
return false;
// For restoring the tray icon after explorer crashes
if (!MYWM_TASKBARCREATED)
MYWM_TASKBARCREATED = RegisterWindowMessage(L"TaskbarCreated");
// Allow the WM_TASKBARCREATED message through the UIPI filter
ChangeWindowMessageFilterEx(m_hwnd, MYWM_TASKBARCREATED, MSGFLT_ALLOW, nullptr);
qCDebug(lcQpaTrayIcon) << __FUNCTION__ << this << "MYWM_TASKBARCREATED=" << MYWM_TASKBARCREATED;
QWindowsHwndSystemTrayIconEntry entry{m_hwnd, this};
hwndTrayIconEntries()->append(entry);
sendTrayMessage(NIM_ADD);