summaryrefslogtreecommitdiff
path: root/w7ui/subclassmgr.h
diff options
context:
space:
mode:
authorwatcherhd <watcherhd@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-04-21 14:14:52 +0000
committerwatcherhd <watcherhd@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-04-21 14:14:52 +0000
commitcb4a46e7fbe62d788e66ed6121c717a2d22a4d7c (patch)
tree30df260fdc5a1b5a7049c2f8cac8b7ef17513d6d /w7ui/subclassmgr.h
parent19b6f534d2e784a1e120bf52c4aa07004798f473 (diff)
svn.miranda.im is moving to a new home!
git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@7 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb
Diffstat (limited to 'w7ui/subclassmgr.h')
-rw-r--r--w7ui/subclassmgr.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/w7ui/subclassmgr.h b/w7ui/subclassmgr.h
new file mode 100644
index 0000000..1cf2433
--- /dev/null
+++ b/w7ui/subclassmgr.h
@@ -0,0 +1,71 @@
+#ifndef subclassmgr_h__
+#define subclassmgr_h__
+
+struct TSubclassData
+{
+ WNDPROC oldWndProc;
+ LPARAM lParam;
+};
+
+typedef LRESULT (*TSubclassProc)(MSG *msg, TSubclassData *data);
+
+class CSubclassMgr
+{
+public:
+ static void Subclass(HWND hwnd, TSubclassProc newWndProc, LPARAM lParam)
+ {
+ TWindowInfo *wi = new TWindowInfo;
+ wi->hwnd = hwnd;
+ wi->newWndProc = newWndProc;
+ wi->lParam = lParam;
+ Instance().m_windows.insert(wi);
+ wi->oldWndProc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)GlobalSubclassProc);
+ }
+
+private:
+ CSubclassMgr(): m_windows(5, TWindowInfo::Compare) {}
+ CSubclassMgr(const CSubclassMgr &);
+ CSubclassMgr &operator=(const CSubclassMgr &);
+
+ static CSubclassMgr &Instance()
+ {
+ static CSubclassMgr theInstance;
+ return theInstance;
+ }
+
+ struct TWindowInfo
+ {
+ HWND hwnd;
+ WNDPROC oldWndProc;
+ TSubclassProc newWndProc;
+ LPARAM lParam;
+
+ static int Compare(const TWindowInfo *p1, const TWindowInfo *p2)
+ {
+ return (int)p1->hwnd - (int)p2->hwnd;
+ }
+ };
+
+ OBJLIST<TWindowInfo> m_windows;
+
+ static LRESULT CALLBACK GlobalSubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+ {
+ TWindowInfo search = { hwnd };
+ TWindowInfo *wnd = Instance().m_windows.find(&search);
+ if (!wnd) return DefWindowProc(hwnd, message, wParam, lParam);
+
+ MSG msg = { hwnd, message, wParam, lParam };
+ TSubclassData data = { wnd->oldWndProc, wnd->lParam };
+ LRESULT result = wnd->newWndProc(&msg, &data);
+
+ if (message == WM_DESTROY)
+ {
+ SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)wnd->oldWndProc);
+ Instance().m_windows.remove(wnd);
+ }
+
+ return result;
+ }
+};
+
+#endif // subclassmgr_h__