← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2447: init the taskbar interface immediately rather than waiting for TaskbarButtonCreated

 

------------------------------------------------------------
revno: 2447
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Wed 2011-03-02 17:06:03 +0100
message:
  init the taskbar interface immediately rather than waiting for TaskbarButtonCreated
modified:
  changelog.txt
  dwt/src/Taskbar.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt	2011-02-25 17:46:24 +0000
+++ changelog.txt	2011-03-02 16:06:03 +0000
@@ -16,6 +16,7 @@
 * Repurpose Ctrl+F to in-place searches in chat windows & file lists (poy)
 * Prevent endless redirection loops with some Coral servers (poy)
 * [L#590651] Plug a resource leak with regard to tab icons (poy)
+* [L#726254] Avoid a crash related to the Win 7 taskbar integration (poy)
 
 -- 0.781 2011-01-12 --
 * Add a dummy serial number to TLS certs to satisfy some parsers (poy)

=== modified file 'dwt/src/Taskbar.cpp'
--- dwt/src/Taskbar.cpp	2011-03-02 15:52:05 +0000
+++ dwt/src/Taskbar.cpp	2011-03-02 16:06:03 +0000
@@ -40,8 +40,6 @@
 
 namespace dwt {
 
-static const UINT taskbarButtonMsg = ::RegisterWindowMessage(_T("TaskbarButtonCreated"));
-
 typedef HRESULT (WINAPI *t_DwmInvalidateIconicBitmaps)(HWND);
 static t_DwmInvalidateIconicBitmaps DwmInvalidateIconicBitmaps = 0;
 
@@ -82,39 +80,36 @@
 		window = window_;
 		dwtassert(window, _T("Taskbar: no widget set"));
 
-		// init the COM pointer on reception of the "TaskbarButtonCreated" message.
-		window->onRaw([this](WPARAM, LPARAM) -> LRESULT {
-			if(!taskbar) {
+		/* init the ITaskbarList3 COM pointer. MSDN recommends waiting for the
+		"TaskbarButtonCreated" message, but neither MFC nor Win SDK samples do that, so we don't
+		either. greatly simplifies the logic of this interface. */
 #ifdef __GNUC__
-				/// @todo remove when GCC knows about ITaskbarList
-				CLSID CLSID_TaskbarList;
-				OLECHAR tbl[] = L"{56FDF344-FD6D-11d0-958A-006097C9A090}";
-				CLSIDFromString(tbl, &CLSID_TaskbarList);
-				IID IID_ITaskbarList;
-				OLECHAR itbl[] = L"{56FDF342-FD6D-11d0-958A-006097C9A090}";
-				CLSIDFromString(itbl, &IID_ITaskbarList);
+		/// @todo remove when GCC knows about ITaskbarList
+		CLSID CLSID_TaskbarList;
+		OLECHAR tbl[] = L"{56FDF344-FD6D-11d0-958A-006097C9A090}";
+		CLSIDFromString(tbl, &CLSID_TaskbarList);
+		IID IID_ITaskbarList;
+		OLECHAR itbl[] = L"{56FDF342-FD6D-11d0-958A-006097C9A090}";
+		CLSIDFromString(itbl, &IID_ITaskbarList);
 #endif
-				if(::CoCreateInstance(CLSID_TaskbarList, 0, CLSCTX_INPROC_SERVER, IID_ITaskbarList,
-					reinterpret_cast<LPVOID*>(&taskbar)) != S_OK) { taskbar = 0; }
-				if(taskbar) {
-					if(taskbar->HrInit() == S_OK) {
-						LibraryLoader lib_user32(_T("user32"));
-						typedef BOOL (WINAPI *t_ChangeWindowMessageFilterEx)(HWND, UINT, DWORD, void*);
-						t_ChangeWindowMessageFilterEx ChangeWindowMessageFilterEx;
-						if(ChangeWindowMessageFilterEx = reinterpret_cast<t_ChangeWindowMessageFilterEx>(
-							lib_user32.getProcAddress(_T("ChangeWindowMessageFilterEx"))))
-						{
-							ChangeWindowMessageFilterEx(window->handle(), WM_DWMSENDICONICTHUMBNAIL, 1/*MSGFLT_ALLOW*/, 0);
-							ChangeWindowMessageFilterEx(window->handle(), WM_DWMSENDICONICLIVEPREVIEWBITMAP, 1/*MSGFLT_ALLOW*/, 0);
-						}
-					} else {
-						taskbar->Release();
-						taskbar = 0;
-					}
+		if(::CoCreateInstance(CLSID_TaskbarList, 0, CLSCTX_INPROC_SERVER, IID_ITaskbarList,
+			reinterpret_cast<LPVOID*>(&taskbar)) != S_OK) { taskbar = 0; }
+		if(taskbar) {
+			if(taskbar->HrInit() == S_OK) {
+				/* call ChangeWindowMessageFilterEx on the 2 messages we use to dispatch bitmaps to
+				the destktop manager to prevent blockings because of different privilege levels. */
+				LibraryLoader lib_user32(_T("user32"));
+				if(auto ChangeWindowMessageFilterEx = reinterpret_cast<BOOL (WINAPI *)(HWND, UINT, DWORD, void*)>(
+					lib_user32.getProcAddress(_T("ChangeWindowMessageFilterEx"))))
+				{
+					ChangeWindowMessageFilterEx(window->handle(), WM_DWMSENDICONICTHUMBNAIL, 1/*MSGFLT_ALLOW*/, 0);
+					ChangeWindowMessageFilterEx(window->handle(), WM_DWMSENDICONICLIVEPREVIEWBITMAP, 1/*MSGFLT_ALLOW*/, 0);
 				}
+			} else {
+				taskbar->Release();
+				taskbar = 0;
 			}
-			return 0;
-		}, Message(taskbarButtonMsg));
+		}
 	}
 }