src/gui/util/qsystemtrayicon_win.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/src/gui/util/qsystemtrayicon_win.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/gui/util/qsystemtrayicon_win.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -83,7 +83,11 @@
     GUID guidItem;
 };
 
+#define Q_MSGFLT_ALLOW 1
+
 typedef HRESULT (WINAPI *PtrShell_NotifyIconGetRect)(const Q_NOTIFYICONIDENTIFIER* identifier, RECT* iconLocation);
+typedef BOOL (WINAPI *PtrChangeWindowMessageFilter)(UINT message, DWORD dwFlag);
+typedef BOOL (WINAPI *PtrChangeWindowMessageFilterEx)(HWND hWnd, UINT message, DWORD action, void* pChangeFilterStruct);
 
 class QSystemTrayIconSys : QWidget
 {
@@ -143,6 +147,23 @@
     if (!MYWM_TASKBARCREATED) {
         MYWM_TASKBARCREATED = RegisterWindowMessage(L"TaskbarCreated");
     }
+
+    // Allow the WM_TASKBARCREATED message through the UIPI filter on Windows Vista and higher
+    static PtrChangeWindowMessageFilterEx pChangeWindowMessageFilterEx =
+        (PtrChangeWindowMessageFilterEx)QLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilterEx");
+
+    if (pChangeWindowMessageFilterEx) {
+        // Call the safer ChangeWindowMessageFilterEx API if available
+        pChangeWindowMessageFilterEx(winId(), MYWM_TASKBARCREATED, Q_MSGFLT_ALLOW, 0);
+    } else {
+        static PtrChangeWindowMessageFilter pChangeWindowMessageFilter =
+            (PtrChangeWindowMessageFilter)QLibrary::resolve(QLatin1String("user32"), "ChangeWindowMessageFilter");
+
+        if (pChangeWindowMessageFilter) {
+            // Call the deprecated ChangeWindowMessageFilter API otherwise
+            pChangeWindowMessageFilter(MYWM_TASKBARCREATED, Q_MSGFLT_ALLOW);
+        }
+    }
 }
 
 QSystemTrayIconSys::~QSystemTrayIconSys()