Index: src/plugin/PluginClass.cpp |
=================================================================== |
--- a/src/plugin/PluginClass.cpp |
+++ b/src/plugin/PluginClass.cpp |
@@ -40,6 +40,9 @@ |
extern CComModule _Module; |
+// Status bar pane number |
+#define STATUSBAR_PANE_NUMBER 2 |
+ |
typedef HANDLE (WINAPI *OPENTHEMEDATA)(HWND, LPCWSTR); |
typedef HRESULT (WINAPI *DRAWTHEMEBACKGROUND)(HANDLE, HDC, INT, INT, LPRECT, LPRECT); |
typedef HRESULT (WINAPI *CLOSETHEMEDATA)(HANDLE); |
@@ -55,7 +58,6 @@ |
DRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL; |
OPENTHEMEDATA pfnOpenThemeData = NULL; |
-ATOM CPluginClass::s_atomPaneClass = NULL; |
HINSTANCE CPluginClass::s_hUxtheme = NULL; |
std::set<CPluginClass*> CPluginClass::s_instances; |
@@ -700,37 +702,6 @@ |
} |
s_criticalSectionLocal.Unlock(); |
- // Register pane class |
- if (!GetAtomPaneClass()) |
- { |
- WNDCLASSEX wcex; |
- |
- wcex.cbSize = sizeof(wcex); |
- wcex.style = 0; |
- wcex.lpfnWndProc = (WNDPROC)PaneWindowProc; |
- wcex.cbClsExtra = 0; |
- wcex.cbWndExtra = 0; |
- wcex.hInstance = _Module.m_hInst; |
- wcex.hIcon = NULL; |
- wcex.hCursor = NULL; |
- wcex.hbrBackground = NULL; |
- wcex.lpszMenuName = NULL; |
- wcex.lpszClassName = STATUSBAR_PANE_NAME; |
- wcex.hIconSm = NULL; |
- |
- s_criticalSectionLocal.Lock(); |
- { |
- s_atomPaneClass = ::RegisterClassEx(&wcex); |
- } |
- s_criticalSectionLocal.Unlock(); |
- |
- if (!GetAtomPaneClass()) |
- { |
- DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_REGISTER_PANE_CLASS, "Class::InitObject - RegisterClassEx"); |
- return false; |
- } |
- } |
- |
int ieVersion = AdblockPlus::IE::InstalledMajorVersion(); |
// Create status pane |
if (ieVersion > 6 && !CreateStatusBarPane()) |
@@ -776,6 +747,25 @@ |
return true; |
} |
+namespace |
+{ |
+ /** |
+ * Wrapper for Windows API 'SetWindowLongPtr()' to set a new window procedure |
+ * |
+ * Adds type safety and proper error handling over calling the API function directly. |
+ */ |
+ DWORD SetWindowProc(HWND window, WNDPROC procedure) |
+ { |
+ /* |
+ * Error handling for 'SetWindowLongPtr()' is not standard. |
+ * The method below is as specified by its documentation. |
+ */ |
+ SetLastError(0); |
+ ::SetWindowLongPtr(window, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(procedure)); |
+ return ::GetLastError(); |
+ } |
+} |
+ |
bool CPluginClass::CreateStatusBarPane() |
{ |
CriticalSection::Lock lock(m_csStatusBar); |
@@ -902,8 +892,8 @@ |
// Create pane window |
HWND hWndNewPane = ::CreateWindowEx( |
NULL, |
- MAKEINTATOM(GetAtomPaneClass()), |
- L"", |
+ L"Edit", // predefined system class |
+ L"ABPStatusBarPane", |
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, |
rcStatusBar.Width() - 500, 0, m_nPaneWidth, rcStatusBar.Height(), |
hWndStatusBar, |
@@ -917,6 +907,15 @@ |
return false; |
} |
+ // Set window procedure to the one for status bars |
+ auto error = SetWindowProc(hWndNewPane, CPluginClass::PaneWindowProc); |
+ if (error) |
+ { |
+ DEBUG_ERROR_LOG(error, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_STATUSBAR_PANE, "Class::SetStatusBarPaneWindowProc - SetWindowProc"); |
+ ::DestroyWindow(hWndNewPane); |
+ return false; |
+ } |
+ |
DEBUG_GENERAL("ABP window created"); |
m_hTabWnd = hTabWnd; |
m_hStatusBarWnd = hWndStatusBar; |
@@ -1069,8 +1068,8 @@ |
// Create menu parent window |
HWND hMenuWnd = ::CreateWindowEx( |
NULL, |
- MAKEINTATOM(GetAtomPaneClass()), |
- L"", |
+ L"Edit", // predefined system class |
+ L"ABPStatusBarPopupMenu", |
0, |
0,0,0,0, |
NULL, |
@@ -1084,6 +1083,15 @@ |
return; |
} |
+ // Set window procedure to the one for status bars. |
+ auto error = SetWindowProc(hMenuWnd, CPluginClass::PaneWindowProc); |
+ if (error) |
+ { |
+ DEBUG_ERROR_LOG(error, PLUGIN_ERROR_UI, PLUGIN_ERROR_UI_CREATE_STATUSBAR_PANE, "Class::DisplayPluginMenu - SetWindowProc"); |
+ ::DestroyWindow(hMenuWnd); |
+ return; |
+ } |
+ |
// Display menu |
nMenuFlags |= TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTBUTTON; |
@@ -1729,9 +1737,3 @@ |
return icon; |
} |
- |
-ATOM CPluginClass::GetAtomPaneClass() |
-{ |
- return s_atomPaneClass; |
-} |
- |