Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
CFSTR_FILEDESCRIPTORで実在しないファイルをエクスプローラへドラッグ&ドロップする実験 (WPF)
#define UNICODE
#define _UNICODE
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#include <string.h>
#include <Windows.h>
#include <ShlObj.h>
#using <WindowsBase.dll>
#using <PresentationCore.dll>
#using <PresentationFramework.dll>
using namespace System;
using namespace System::IO;
using namespace System::Windows;
using namespace System::Windows::Input;
DataObject^ GetFileDescriptorAndContent()
auto dataObj = gcnew DataObject;
auto buffer = gcnew array<BYTE>(sizeof FILEGROUPDESCRIPTOR);
pin_ptr<BYTE> p = &buffer[0];
auto fileGroupDescriptor = reinterpret_cast<FILEGROUPDESCRIPTOR*>(p);
fileGroupDescriptor->cItems = 1;
fileGroupDescriptor->fgd[0].dwFlags = static_cast<DWORD>(FD_PROGRESSUI | FD_UNICODE);
wcscpy_s(fileGroupDescriptor->fgd[0].cFileName, L"test.txt");
dataObj->SetData(CFSTR_FILEDESCRIPTOR, gcnew MemoryStream(buffer));
auto data = gcnew array<BYTE> { 'a', 'b', 'c' };
auto content = gcnew MemoryStream;
content->Write(data, 0, data->Length);
dataObj->SetData(CFSTR_FILECONTENTS, content);
return dataObj;
void OnMouseDown(Object^ sender, MouseButtonEventArgs^ e)
DragDrop::DoDragDrop(safe_cast<DependencyObject^>(sender), GetFileDescriptorAndContent(), DragDropEffects::Copy);
int main()
auto w = gcnew Window;
w->MouseLeftButtonDown += gcnew MouseButtonEventHandler(OnMouseDown);
auto app = gcnew Application;
return app->Run(w);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.