Created
May 24, 2015 08:31
-
-
Save egtra/f6aaca0e5eb2c72c0242 to your computer and use it in GitHub Desktop.
CFSTR_FILEDESCRIPTORで実在しないフォルダをエクスプローラへドラッグ&ドロップする実験 (WPF)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 | FD_ATTRIBUTES); | |
fileGroupDescriptor->fgd[0].dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY; | |
wcscpy_s(fileGroupDescriptor->fgd[0].cFileName, L"test"); | |
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