You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
2.7 KiB
129 lines
2.7 KiB
//--------------------------------------------------------------------------- |
|
|
|
#include <fmx.h> |
|
#pragma hdrstop |
|
#include <FMX.Platform.Win.hpp> |
|
#include <ShellAPI.h> |
|
#include <cstdlib> |
|
#include <memory> |
|
#include <vector> |
|
#include <iostream> |
|
|
|
#include "Unit1.h" |
|
//--------------------------------------------------------------------------- |
|
#pragma package(smart_init) |
|
#pragma resource "*.fmx" |
|
|
|
#if _WIN64 |
|
#define Parm GWLP_WNDPROC |
|
#elif _WIN32 |
|
#define Parm GWL_WNDPROC |
|
#elif __APPLE__ |
|
// macOS |
|
#else |
|
#error Not a supported platform |
|
#endif |
|
|
|
std::vector <AnsiString>filenames; |
|
|
|
TForm1 *Form1; |
|
//--------------------------------------------------------------------------- |
|
|
|
/* |
|
void __fastcall TForm1::msg_hnd(TWMDropFiles Msg) |
|
{ |
|
int count; |
|
int i; |
|
char fname[256]; |
|
|
|
count=DragQueryFile((HDROP)Msg.Drop, 0xFFFFFFFF, NULL, 255); |
|
DragQueryFile((HDROP)Msg.Drop, 0, fname, 255); |
|
///ファイル処理(fname); |
|
Memo1->Lines->Add(fname); |
|
if (count>1) { |
|
for(i=1;i<count;i++) { |
|
DragQueryFile((HDROP)Msg.Drop, i, fname, 255); |
|
//ファイル処理2(fname) |
|
Memo1->Lines->Add(fname); |
|
} |
|
} |
|
DragFinish((HDROP)Msg.Drop); // メモリ開放 |
|
} |
|
*/ |
|
|
|
HWND m_Hwnd; |
|
|
|
WNDPROC m_WndOldProc; |
|
|
|
long m_OldWndProc; |
|
|
|
/* |
|
const unsigned int count = DragQueryFile((HDROP)Message.Drop, -1, NULL, 0); |
|
for (unsigned int i = 0; i < count; ++i) |
|
{ |
|
|
|
*/ |
|
|
|
LRESULT CALLBACK WndProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam) |
|
{ |
|
int count; |
|
int i; |
|
char fname[256]; |
|
|
|
|
|
if(Msg == WM_DROPFILES){ |
|
|
|
//ShowMessage("drop files fired and catched"); |
|
|
|
const unsigned int count = DragQueryFile((HDROP)wParam,-1,NULL,0); |
|
for( unsigned int i = 0 ; i < count ; ++i ){ |
|
const unsigned int length = DragQueryFile((HDROP)wParam, i, NULL, 0); |
|
std::unique_ptr<wchar_t[]> filename(new wchar_t[length + 1]); |
|
|
|
//ドロップされたファイルの名前を取得する |
|
DragQueryFile((HDROP)wParam, i, filename.get(), length + 1); |
|
AnsiString temp; |
|
temp = filename.get(); |
|
//Form1->Memo1->Lines->Add(temp); |
|
filenames.push_back(temp); |
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return CallWindowProc(m_WndOldProc,hWnd,Msg,wParam,lParam); |
|
|
|
} |
|
|
|
__fastcall TForm1::TForm1(TComponent* Owner) |
|
: TForm(Owner) |
|
{ |
|
|
|
|
|
m_Hwnd = Fmx::Platform::Win::FormToHWND(Form1); |
|
DragAcceptFiles(m_Hwnd,true); |
|
|
|
m_OldWndProc = GetWindowLongPtr(m_Hwnd, Parm); |
|
m_WndOldProc = (WNDPROC)SetWindowLongPtr(m_Hwnd, Parm,(LONG)WndProc); |
|
|
|
} |
|
|
|
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) |
|
{ |
|
SetWindowLongPtr(m_Hwnd,Parm,m_OldWndProc); |
|
} |
|
|
|
void __fastcall TForm1::Button1Click(TObject *Sender) |
|
{ |
|
// dump file names to Memo1 |
|
//using iterator |
|
|
|
for( auto index = filenames.begin() ; index != filenames.end() ; index++ ) |
|
Memo1->Lines->Add(*index); |
|
|
|
} |
|
//--------------------------------------------------------------------------- |
|
|
|
|