1 ////////////////////////////////////////////////////////////////
2 // Copyright 1998 Paul DiLascia
3 // If this code works, it was written by Paul DiLascia.
4 // If not, I don't know who wrote it.
10 // Generic class to hook messages on behalf of a CWnd.
11 // Once hooked, all messages go to CSubclassWnd::WindowProc before going
12 // to the window. Specific subclasses can trap messages and do something.
16 // * Derive a class from CSubclassWnd.
18 // * Override CSubclassWnd::WindowProc to handle messages. Make sure you call
19 // CSubclassWnd::WindowProc if you don't handle the message, or your
20 // window will never get messages. If you write seperate message handlers,
21 // you can call Default() to pass the message to the window.
23 // * Instantiate your derived class somewhere and call HookWindow(pWnd)
24 // to hook your window, AFTER it has been created.
25 // To unhook, call HookWindow(NULL).
27 // This is a very important class, crucial to many of the widgets Window
28 // widgets implemented in PixieLib. To see how it works, look at the HOOK
31 class CTRL_EXT_CLASS CSubclassWnd : public CObject {
33 DECLARE_DYNAMIC(CSubclassWnd);
37 // Subclass a window. Hook(NULL) to unhook (automatic on WM_NCDESTROY)
38 BOOL HookWindow(HWND hwnd);
39 BOOL HookWindow(CWnd* pWnd) { return HookWindow(pWnd->GetSafeHwnd()); }
40 BOOL IsHooked() { return m_hWnd!=NULL; }
42 friend LRESULT CALLBACK HookWndProc(HWND, UINT, WPARAM, LPARAM);
43 friend class CSubclassWndMap;
46 virtual void AssertValid() const;
47 virtual void Dump(CDumpContext& dc) const;
51 HWND m_hWnd; // the window hooked
52 WNDPROC m_pOldWndProc; // ..and original window proc
53 CSubclassWnd* m_pNext; // next in chain of hooks for this window
55 // Override this to handle messages in specific handlers
56 virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
57 LRESULT Default(); // call this at the end of handler fns
60 #endif // _SUBCLASSW_H