Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 | FD_ATTRIBUTES);
fileGroupDescriptor->fgd[0].dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
wcscpy_s(fileGroupDescriptor->fgd[0].cFileName, L"test");
dataObj->SetData(CFSTR_FILEDESCRIPTOR, gcnew MemoryStream(buffer));
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
You can’t perform that action at this time.