update for HEAD-2003091401
[reactos.git] / subsys / system / explorer / Seashell / SeaShellExt / Include / UISubclass.h
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.
5 //
6 #ifndef _SUBCLASSW_H
7 #define _SUBCLASSW_H
8
9 //////////////////
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.
13 //
14 // To use:
15 //
16 // * Derive a class from CSubclassWnd.
17 //
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.
22 //
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).
26 //
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
29 // sample program.
30 //
31 class CTRL_EXT_CLASS CSubclassWnd : public CObject {
32 public:
33         DECLARE_DYNAMIC(CSubclassWnd);
34         CSubclassWnd();
35         ~CSubclassWnd();
36
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; }
41
42         friend LRESULT CALLBACK HookWndProc(HWND, UINT, WPARAM, LPARAM);
43         friend class CSubclassWndMap;
44
45 #ifdef _DEBUG
46         virtual void AssertValid() const;
47         virtual void Dump(CDumpContext& dc) const;
48 #endif
49
50 protected:
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
54
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
58 };
59
60 #endif // _SUBCLASSW_H
61