Skip to content

Instantly share code, notes, and snippets.

@egtra
Created September 11, 2014 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egtra/448af58012267057ff17 to your computer and use it in GitHub Desktop.
Save egtra/448af58012267057ff17 to your computer and use it in GitHub Desktop.
CFSTR_FILEDESCRIPTORで実在しないファイルをエクスプローラへドラッグ&ドロップする実験 (Windows Forms)
#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 <System.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::IO;
using namespace System::Windows::Forms;
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, MouseEventArgs^ e)
{
if ((e->Button & MouseButtons::Left) != MouseButtons())
{
safe_cast<Control^>(sender)->DoDragDrop(GetFileDescriptorAndContent(), DragDropEffects::Copy);
}
}
[STAThread]
int main()
{
auto f = gcnew Form;
f->MouseDown += gcnew MouseEventHandler(OnMouseDown);
Application::Run(f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment