BCB 中实现文件拖放操作
private : // User declarations
void __fastcall AcceptFiles (TMessage& Msg);
public : // User declarations
__fastcall TForm1(TComponent* Owner);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER( WM_DROPFILES, TMessage, AcceptFiles)
END_MESSAGE_MAP(TForm)
//在.cpp文件里
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
DragAcceptFiles( this->Handle, true);
}
void __fastcall TForm1 ::AcceptFiles(TMessage& Msg)
{
const int m_nMaxFileNameLen=255;
int i, m_nCount;
char m_sFileName[m_nMaxFileNameLen];
//ZeroMemory(m_sFileName,m_nMaxFileNameLen+1);
m_nCount=DragQueryFile((HANDLE)Msg.WParam, 0xffffffff, m_sFileName , m_nMaxFileNameLen);
//ZeroMemory(m_sFileName,m_nMaxFileNameLen+1);
for (i=0;i<m_nCount;i ++)
{
DragQueryFile((HANDLE )Msg.WParam, i, m_sFileName , m_nMaxFileNameLen);
MessageBox( this->Handle,m_sFileName,"Drop File" ,MB_OK);
//ZeroMemory(m_sFileName,m_nMaxFileNameLen+1);
}
DragFinish ((HANDLE)Msg.WParam);
}