zoukankan      html  css  js  c++  java
  • 如何在对话框中实现文件拖放功能

    如何在对话框中实现文件拖放功能

    1. 在对话框上添加一个Picture Control,然后把Accept Files属性修改成True。如果是想托图片的话需要把Type改成Bitmap
    2. 在头文件里加入:afx_msg void OnDropFiles(HDROP hDropInfo);
    3. cpp文件里加入:ON_WM_DROPFILES()
    4. OnInitDialog()的最后加入:DragAcceptFiles(TRUE);
    5. cpp文件里添加:void CTestDragDlg::OnDropFiles(HDROP hDropInfo){

          

           int nFileCount = DragQueryFile(hDropInfo, -1, NULL, 0);

           TCHAR *strFilePath;

           int dwSize;

          

           if (nFileCount==1)

           {

     

     

                  dwSize = DragQueryFile(hDropInfo, 0, NULL, 0);

                  strFilePath = new TCHAR[dwSize+1];

                  if (strFilePath)

                  {

    DragQueryFile(hDropInfo, 0, strFilePath, dwSize+1);

    //Retrieves the names of dropped files that result from a successful drag-and-drop operation.

                        

    //Do sth to prove succeed

                         delete []strFilePath;

                  }

           }

           CDialog::OnDropFiles(hDropInfo);

           DragFinish(hDropInfo);

           Invalidate();

    }

     

    到此为止已经结束。为了证明拖拽文件ok可以做一个小测试。

    1. 在对话框中加入一个edit box

    然后在头文件中加入:CString m_StrPath;

    cpp文件的DoDataExchange(CDataExchange* pDX)函数中加入

    DDX_Text(pDX, IDC_EDIT0, m_StrPath);

     

    1. DragQueryFile后添加:

    m_StrPath.Format("%s",strFilePath);

                UpdateData(FALSE);

    然后测试就会发现只要拖拽一个文件就会在edit box里出现此文件的全路径。

     

    from:http://blog.sina.com.cn/s/blog_6a6d5ba80100lcay.html

  • 相关阅读:
    CentOS安装部署Nodejs
    CentOS安装部署Git
    CentOS安装部署Mysql 5.7
    CentOS 7 安装Java环境(脚本一键式安装)
    Java技术 | 细谈Java中UUID的简单了解与使用
    Navicat Premium 版本 12.1 激活成永久
    Java技术 | 细谈 Java 8 中的 Base64
    安装部署Elastic Search
    从零开始搭建linux下laravel 5.5所需环境(二)
    从零开始搭建linux下laravel 5.5所需环境(一)
  • 原文地址:https://www.cnblogs.com/lidabo/p/2781473.html
Copyright © 2011-2022 走看看