添加WM_DROPFILES消息
void CMyEdit::OnDropFiles(HDROP hDropInfo)
{
int fcount = ::DragQueryFile(hDropInfo,-1,NULL,NULL)
for(int i=0i<fcounti++)
{
int fsize = ::DragQueryFile(hDropInfo,i,NULL,NULL)
HANDLE hHeap = ::GetProcessHeap()
char *fname = (char *)::HeapAlloc(hHeap,HEAP_ZERO_MEMORY,fsize++)
::DragQueryFile(hDropInfo,i,fname,fsize)
this->SetWindowText(fname)
::HeapFree(hDropInfo,HEAP_ZERO_MEMORY,fname)
}
CEdit::OnDropFiles(hDropInfo)
}
在对话框OnInitDialog()中开启编辑框文件拖放功能
m_edit.DragAcceptFiles(1)
首先设置Form的AllowDrop=true
public partial class Form1 : Form{
public Form1()
{
InitializeComponent()
}
private void btnStart_Click(object sender, EventArgs e)
{
}
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Link
}
else
{
e.Effect = DragDropEffects.None
}
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString()
// 接下来可以通过filestream来上传文件。
}
}
在DragDrop事件中能够得到拖放到窗体上的文件路径,然后使用filestream就可以上传了。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)