单元文件的头文件中:
C/C++ code
private: // User declarations
void __fastcall WndProc(TMessage &Msg);
单元文件的.cpp文件中:
C/C++ code
// 重载窗体WndProc函数
void __fastcall TForm1::WndProc(TMessage &Msg)
{
if(Msg.Msg == WM_DROPFILES)
{
// 在开始拖拽前先取得文件的总数
TWMDropFiles wmDropFiles = (TWMDropFiles &)Msg;
TCHAR szFileName[MAX_PATH];
UINT nFileCount = ::DragQueryFile((HDROP)wmDropFiles.Drop, 0xFFFFFFFF, NULL, 0);
for (UINT i = 0; i < nFileCount; ++ i)
{
::ZeroMemory(szFileName, MAX_PATH);
::DragQueryFile((HDROP)wmDropFiles.Drop, i, szFileName, MAX_PATH);
Memo1->Lines->Add(szFileName);
}
::DragFinish ((HDROP)wmDropFiles.Drop);
}
TForm::WndProc(Msg);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
::DragAcceptFiles(Handle, True);
}
C/C++ code
private: // User declarations
void __fastcall WndProc(TMessage &Msg);
单元文件的.cpp文件中:
C/C++ code
// 重载窗体WndProc函数
void __fastcall TForm1::WndProc(TMessage &Msg)
{
if(Msg.Msg == WM_DROPFILES)
{
// 在开始拖拽前先取得文件的总数
TWMDropFiles wmDropFiles = (TWMDropFiles &)Msg;
TCHAR szFileName[MAX_PATH];
UINT nFileCount = ::DragQueryFile((HDROP)wmDropFiles.Drop, 0xFFFFFFFF, NULL, 0);
for (UINT i = 0; i < nFileCount; ++ i)
{
::ZeroMemory(szFileName, MAX_PATH);
::DragQueryFile((HDROP)wmDropFiles.Drop, i, szFileName, MAX_PATH);
Memo1->Lines->Add(szFileName);
}
::DragFinish ((HDROP)wmDropFiles.Drop);
}
TForm::WndProc(Msg);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
::DragAcceptFiles(Handle, True);
}