Здравствуйте, alexqc, Вы писали:
[]
Например так —
class drop_names
{
std::vector<TCHAR> drop_data_;
size_t cur_index;
bool locked_;
public:
drop_names() : cur_index(0), locked_(false) { }
bool add(const TCHAR* name)
{
_ASSERTE(!locked_);
if (locked_)
return false;
const size_t name_size = lstrlen(name);
drop_data_.resize(cur_index + name_size + 1);
memcpy(&drop_data_[0] + cur_index, name, name_size * sizeof(TCHAR));
cur_index += name_size;
drop_data_[cur_index] = _T('\0');
++cur_index;
return true;
}
const TCHAR* lock()
{
drop_data_.push_back(_T('\0'));
++cur_index;
locked_ = true;
return &drop_data_[0];
}
size_t size() const { return cur_index * sizeof(TCHAR); }
};
const TCHAR* name1 = _T("c:\\temp\\mycoolfile1.txt");
const TCHAR* name2 = _T("c:\\temp\\mycoolfile2.txt");
drop_names names;
names.add(name1);
names.add(name2);
const TCHAR* file_names = names.lock();
DROPFILES drop_struct = { sizeof(drop_struct), { 0, 0 }, 0, 0 };
const size_t drop_size = sizeof(drop_struct) + names.size();
HGLOBAL drop_data = GlobalAlloc(0, drop_size);
HGLOBAL drop_effect = GlobalAlloc(0, sizeof(DWORD));
unsigned char* clip_data = reinterpret_cast<unsigned char*>(drop_data);
unsigned long* clip_effect = reinterpret_cast<unsigned long*>(drop_effect);
*clip_effect = DROPEFFECT_COPY; /* or DROPEFFECT_MOVE */
memcpy(clip_data, &drop_struct, sizeof(drop_struct));
memcpy(clip_data + sizeof(drop_struct), file_names, names.size());
BOOL res = OpenClipboard();
_ASSERTE(res);
res = EmptyClipboard();
_ASSERTE(res);
HANDLE data = SetClipboardData(CF_HDROP, drop_data);
_ASSERTE(data);
const UINT cf = RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT);
_ASSERTE(cf);
data = SetClipboardData(cf, drop_effect);
_ASSERTE(data);
CloseClipboard();
ЗЫ Особо не тестил, так что може где огрехи есть, но думаю идея понятна.