-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdropsource.cpp
149 lines (128 loc) · 2.6 KB
/
dropsource.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// DROPSOURCE.CPP
//
// Implementation of the IDropSource COM interface
//
// By J Brown 2004
//
// www.catch22.net
//
//#define STRICT
#include <windows.h>
class CDropSource : public IDropSource
{
public:
//
// IUnknown members
//
HRESULT __stdcall QueryInterface (REFIID iid, void ** ppvObject);
ULONG __stdcall AddRef (void);
ULONG __stdcall Release (void);
//
// IDropSource members
//
HRESULT __stdcall QueryContinueDrag (BOOL fEscapePressed, DWORD grfKeyState);
HRESULT __stdcall GiveFeedback (DWORD dwEffect);
//
// Constructor / Destructor
//
CDropSource();
~CDropSource();
private:
//
// private members and functions
//
LONG m_lRefCount;
};
//
// Constructor
//
CDropSource::CDropSource()
{
m_lRefCount = 1;
}
//
// Destructor
//
CDropSource::~CDropSource()
{
}
//
// IUnknown::AddRef
//
ULONG __stdcall CDropSource::AddRef(void)
{
// increment object reference count
return InterlockedIncrement(&m_lRefCount);
}
//
// IUnknown::Release
//
ULONG __stdcall CDropSource::Release(void)
{
// decrement object reference count
LONG count = InterlockedDecrement(&m_lRefCount);
if(count == 0)
{
delete this;
return 0;
}
else
{
return count;
}
}
//
// IUnknown::QueryInterface
//
HRESULT __stdcall CDropSource::QueryInterface(REFIID iid, void **ppvObject)
{
// check to see what interface has been requested
if(iid == IID_IDropSource || iid == IID_IUnknown)
{
AddRef();
*ppvObject = this;
return S_OK;
}
else
{
*ppvObject = 0;
return E_NOINTERFACE;
}
}
//
// CDropSource::QueryContinueDrag
//
// Called by OLE whenever Escape/Control/Shift/Mouse buttons have changed
//
HRESULT __stdcall CDropSource::QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState)
{
// if the <Escape> key has been pressed since the last call, cancel the drop
if(fEscapePressed == TRUE)
return DRAGDROP_S_CANCEL;
// if the <LeftMouse> button has been released, then do the drop!
if((grfKeyState & MK_LBUTTON) == 0)
return DRAGDROP_S_DROP;
// continue with the drag-drop
return S_OK;
}
//
// CDropSource::GiveFeedback
//
// Return either S_OK, or DRAGDROP_S_USEDEFAULTCURSORS to instruct OLE to use the
// default mouse cursor images
//
HRESULT __stdcall CDropSource::GiveFeedback(DWORD dwEffect)
{
return DRAGDROP_S_USEDEFAULTCURSORS;
}
//
// Helper routine to create an IDropSource object
//
HRESULT CreateDropSource(IDropSource **ppDropSource)
{
if(ppDropSource == 0)
return E_INVALIDARG;
*ppDropSource = new CDropSource();
return (*ppDropSource) ? S_OK : E_OUTOFMEMORY;
}