-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcwndproc.h
75 lines (62 loc) · 2.3 KB
/
cwndproc.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef _CWNDPROC_H_
#define _CWNDPROC_H_
#include <Windows.h>
#include "debug.h"
#include <CommCtrl.h>
#include <ShlObj.h>
// CImpWndProc
//
// Use this class when you want to associate a window with
// an object using a virtual wndproc.
//
// NOTE: The window's lifetime must be encompassed by the object.
// I.E. NO REFCOUNT IS HELD ON THE OBJECT!
//
// Messages after WM_NCCREATE up to and including WM_DESTROY
// are forwarded to v_WndProc.
//
// _hwnd is non-NULL from WM_NCCREATE up to but not during WM_DESTROY.
// (Not during because the final release may be tied to WM_DESTROY
// so we cannot reference member variables after forwarding thie message.)
//
class CImpWndProc
{
public:
virtual ULONG STDMETHODCALLTYPE AddRef() = 0;
virtual ULONG STDMETHODCALLTYPE Release() = 0;
protected:
virtual LRESULT v_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) PURE;
static LRESULT CALLBACK s_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
HWND _hwnd;
};
// CNotifySubclassWndProc
//
// This class subclasses an HWND, registers for SHChangeNotify events,
// and forwards them to the inheritor's IShellChangeNotify implementation.
//
// You need one instance of this class per window you want to subclass
// and register for events against. (So if you need >1 window hooked up
// in this matter, you need to have member implementations that inherit
// from this class.)
//
class CNotifySubclassWndProc
{
public:
virtual STDMETHODIMP OnChange(LONG lEvent, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2) PURE;
protected:
BOOL _SubclassWindow(HWND hwnd);
void _UnsubclassWindow(HWND hwnd);
void _RegisterWindow(HWND hwnd, LPCITEMIDLIST pidl, long lEvents,
UINT uFlags = (SHCNRF_ShellLevel | SHCNRF_InterruptLevel));
void _UnregisterWindow(HWND hwnd);
virtual LRESULT _DefWindowProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam);
void _FlushNotifyMessages(HWND hwnd);
private:
static LRESULT CALLBACK _SubclassWndProc(
HWND hwnd, UINT uMessage,
WPARAM wParam, LPARAM lParam,
UINT_PTR uIdSubclass, DWORD_PTR dwRefData);
UINT _uRegister; // SHChangeNotify id
HWND _hwndSubclassed;
};
#endif _CWNDPROC_H_