MFC应用代码
+ -

MFC对话框响应拖文件WM_DROPFILES

2022-10-20 21 0

首先初始化启用DragAcceptFiles

    DragAcceptFiles(TRUE);

然后在添加类向导中增加消息:WM_DROPFILES

void CVCMAppDlg::OnDropFiles(HDROP hDropInfo)
{
    CDialogEx::OnDropFiles(hDropInfo);
      UINT count;
    TCHAR filePath[MAX_PATH] = { 0 };
    count = DragQueryFile(hDropInfo, -1, NULL, 0);

  if (1 == count)
  {
      DragQueryFile(hDropInfo, 0, filePath, sizeof(filePath));
      this->SetWindowTextW(filePath);
      UpdateData(FALSE);
      DragFinish(hDropInfo); //拖放成功后,释放内存
  }
  else
  {
      CString szFilePath;
      for (UINT i = 0; i < count; i++)
      {
          int pahtLen = DragQueryFile(hDropInfo, i, filePath, sizeof(filePath));
          szFilePath = szFilePath + filePath + _T("\r\n");
      }
      this->SetWindowTextW(szFilePath);
      UpdateData(FALSE);
      DragFinish(hDropInfo);
  }
    DragFinish(hDropInfo);
}

0 篇笔记 写笔记

MFC对话框响应拖文件WM_DROPFILES
首先初始化启用DragAcceptFiles DragAcceptFiles(TRUE);然后在添加类向导中增加消息:WM_DROPFILESvoid CVCMAppDlg::OnDropFiles(HDROP hDropInfo){ CDialogEx::OnDropFile......
作者信息
我爱内核
Windows驱动开发,网站开发
好好学习,天天向上。
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!