Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CFSTR_FILEDESCRIPTORで実在しないファイル(相対パスでフォルダ名指定あり)をエクスプローラへドラッグ&ドロップする実験 (WPF)
#define UNICODE
#define _UNICODE
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1
#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 1
#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, LR"(hoge\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);
}
[STAThread]
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.