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
|
// DropURL.cpp : implementation file
//
#include "stdafx.h"
#include "Dipstick.h"
#include "DropURL.h"
#include "DragPad.h"
#include "Dipstick.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDropURL
IMPLEMENT_DYNCREATE(CDropURL, CCmdTarget)
CDropURL::CDropURL()
: m_Pad(NULL)
{
}
CDropURL::~CDropURL()
{
}
BEGIN_MESSAGE_MAP(CDropURL, CCmdTarget)
//{{AFX_MSG_MAP(CDropURL)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_INTERFACE_MAP(CDropURL, CCmdTarget)
INTERFACE_PART(CDropURL, IID_IDropTarget, DDropTarget)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDropURL message handlers
STDMETHODIMP_(ULONG) CDropURL::XDDropTarget::AddRef()
{
METHOD_PROLOGUE(CDropURL, DDropTarget)
return pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) CDropURL::XDDropTarget::Release()
{
METHOD_PROLOGUE(CDropURL, DDropTarget)
return pThis->ExternalRelease();
}
STDMETHODIMP_(HRESULT) CDropURL::XDDropTarget::QueryInterface(REFIID iid,void FAR* FAR * ppvObj)
{
METHOD_PROLOGUE(CDropURL, DDropTarget)
return pThis->ExternalQueryInterface(&iid,ppvObj);
}
STDMETHODIMP_(HRESULT) CDropURL::XDDropTarget::DragEnter(IDataObject *pDataObject,DWORD grfKeyState,POINTL pt,DWORD *pdwEffect)
{
METHOD_PROLOGUE(CDropURL, DDropTarget)
TRACE0("DragEnter\n");
return pThis->DragEnter(pDataObject,grfKeyState,pt,pdwEffect);
}
STDMETHODIMP_(HRESULT) CDropURL::XDDropTarget::DragOver(DWORD grfKeyState,POINTL pt,DWORD *pdwEffect)
{
METHOD_PROLOGUE(CDropURL, DDropTarget)
return S_OK;
}
STDMETHODIMP_(HRESULT) CDropURL::XDDropTarget::DragLeave(void)
{
METHOD_PROLOGUE(CDropURL, DDropTarget)
TRACE0("DragLeave\n");
return S_OK;
}
STDMETHODIMP_(HRESULT) CDropURL::XDDropTarget::Drop(IDataObject *pDataObject,DWORD grfKeyState,POINTL pt,DWORD *pdwEffect)
{
METHOD_PROLOGUE(CDropURL, DDropTarget)
TRACE0("Drop\n");
return pThis->Drop(pDataObject,grfKeyState,pt,pdwEffect);
}
HRESULT CDropURL::DragEnter(IDataObject *pDataObject,DWORD grfKeyState,POINTL pt,DWORD *pdwEffect)
{
CString host = GetHostName(pDataObject);
if(host.IsEmpty()){
(*pdwEffect)=DROPEFFECT_NONE;
return S_FALSE;
}else{
(*pdwEffect)=DROPEFFECT_LINK;
return S_OK;
}
}
CString CDropURL::GetHostName(IDataObject *pDataObject,CString *_url)
{
FORMATETC fetc;
fetc.cfFormat=CF_TEXT;
fetc.ptd=NULL;
fetc.dwAspect=DVASPECT_CONTENT;
fetc.lindex=-1;
fetc.tymed=TYMED_HGLOBAL;
STGMEDIUM stgm;
LPVOID globe = NULL;
CString url;
CString rv;
stgm.pUnkForRelease=NULL;
do{
if(pDataObject->GetData(&fetc,&stgm)!=S_OK)
break;
ASSERT(stgm.tymed==TYMED_HGLOBAL);
if(GlobalSize(stgm.hGlobal)>=1024)
break;
VERIFY(globe=GlobalLock(stgm.hGlobal));
url=(LPTSTR)globe;
TRACE0("["+url+"]\n");
if(_url)
(*_url) = url;
rv = m_Pad->m_Daddy->GetHostName(url);
}while(FALSE);
if(globe)
GlobalUnlock(stgm.hGlobal);
if(stgm.pUnkForRelease)
stgm.pUnkForRelease->Release();
return rv;
}
HRESULT CDropURL::Drop(IDataObject *pDataObject,DWORD grfKeyState,POINTL pt,DWORD *pwdEffect)
{
CString url;
CString host = GetHostName(pDataObject,&url);
if(host.IsEmpty())
return S_FALSE;
#ifdef TRUE
// URL Mode
CString *u = new CString(url);
m_Pad->m_Daddy->PostMessage(WM_DNP_URLPING,0,(LPARAM)u);
#else
CString *hn = new CString(host);
m_Pad->m_Daddy->PostMessage(WM_DNP_HOSTPING,0,(LPARAM)hn);
#endif
return S_OK;
}
void CDropURL::OnFinalRelease()
{
TRACE0("Final Release\n");
CCmdTarget::OnFinalRelease();
}
|