-
Notifications
You must be signed in to change notification settings - Fork 8
/
DragDrop.h
167 lines (146 loc) · 3.84 KB
/
DragDrop.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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#pragma once
#include <shellapi.h>
#include "export_table_adapter.h"
class CTestDropTarget :public IDropTarget
{
public:
CTestDropTarget()
{
nRef = 0;
}
virtual ~CTestDropTarget() {}
//////////////////////////////////////////////////////////////////////////
// IUnknown
virtual HRESULT STDMETHODCALLTYPE QueryInterface(
/* [in] */ REFIID riid,
/* [iid_is][out] */ __RPC__deref_out void __RPC_FAR *__RPC_FAR *ppvObject)
{
HRESULT hr = S_FALSE;
if (riid == __uuidof(IUnknown))
*ppvObject = (IUnknown*) this, hr = S_OK;
else if (riid == __uuidof(IDropTarget))
*ppvObject = (IDropTarget*)this, hr = S_OK;
if (SUCCEEDED(hr)) AddRef();
return hr;
}
virtual ULONG STDMETHODCALLTYPE AddRef(void) { return ++nRef; }
virtual ULONG STDMETHODCALLTYPE Release(void) {
ULONG uRet = --nRef;
if (uRet == 0) delete this;
return uRet;
}
//////////////////////////////////////////////////////////////////////////
// IDropTarget
virtual HRESULT STDMETHODCALLTYPE DragEnter(
/* [unique][in] */ __RPC__in_opt IDataObject *pDataObj,
/* [in] */ DWORD grfKeyState,
/* [in] */ POINTL pt,
/* [out][in] */ __RPC__inout DWORD *pdwEffect)
{
*pdwEffect = DROPEFFECT_LINK;
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE DragOver(
/* [in] */ DWORD grfKeyState,
/* [in] */ POINTL pt,
/* [out][in] */ __RPC__inout DWORD *pdwEffect)
{
*pdwEffect = DROPEFFECT_LINK;
return S_OK;
}
virtual HRESULT STDMETHODCALLTYPE DragLeave(void)
{
return S_OK;
}
protected:
int nRef;
};
class CTreeViewDropTarget : public CTestDropTarget
{
protected:
STreeView *m_pTreeView1;
STreeView *m_pTreeView2;
public:
CTreeViewDropTarget(STreeView *pTreeView1, STreeView *pTreeView2) :m_pTreeView1(pTreeView1),m_pTreeView2(pTreeView2)
{
if (m_pTreeView1) m_pTreeView1->AddRef();
if (m_pTreeView2) m_pTreeView2->AddRef();
}
~CTreeViewDropTarget()
{
if (m_pTreeView1) m_pTreeView1->Release();
if (m_pTreeView2) m_pTreeView2->Release();
}
public:
virtual HRESULT STDMETHODCALLTYPE Drop(
/* [unique][in] */ __RPC__in_opt IDataObject *pDataObj,
/* [in] */ DWORD grfKeyState,
/* [in] */ POINTL pt,
/* [out][in] */ __RPC__inout DWORD *pdwEffect)
{
FORMATETC format =
{
CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL
};
STGMEDIUM medium;
if (FAILED(pDataObj->GetData(&format, &medium)))
{
return S_FALSE;
}
HDROP hdrop = static_cast<HDROP>(GlobalLock(medium.hGlobal));
if (!hdrop)
{
return S_FALSE;
}
bool success = false;
TCHAR filename[MAX_PATH];
success = !!DragQueryFile(hdrop, 0, filename, MAX_PATH);
DragFinish(hdrop);
GlobalUnlock(medium.hGlobal);
if (success)
{
HANDLE hFile = CreateFile(
filename, //PE文件名
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
return S_FALSE;
}
// DWORD dwFileSize;
// GetFileSize(hFile, &dwFileSize);
// DWORD dwMinFileSize = sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS32);
// if (dwMinFileSize > dwFileSize)
// {
// CloseHandle(hFile);
// return S_FALSE;
// }
HANDLE hFileMapping = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
if (hFileMapping == NULL || hFileMapping == INVALID_HANDLE_VALUE)
{
return S_FALSE;
}
LPBYTE lpBaseAddress = (LPBYTE)MapViewOfFile(hFileMapping, // handle to map object
FILE_MAP_READ, 0, 0, 0);
if (m_pTreeView1)
{
CImportTableTreeViewAdapter *treead = (CImportTableTreeViewAdapter*)m_pTreeView1->GetAdapter();
treead->Updata(lpBaseAddress);
}
if (m_pTreeView2)
{
CExportTableTreeViewAdapter *treead = (CExportTableTreeViewAdapter*)m_pTreeView2->GetAdapter();
treead->Updata(lpBaseAddress);
}
UnmapViewOfFile(lpBaseAddress);
CloseHandle(hFileMapping);
CloseHandle(hFile);
}
*pdwEffect = DROPEFFECT_LINK;
return S_OK;
}
};