1) VC++ 6.0 新建一个基于对话框的MFC的工程,取名MfcDropFiles;

  2) 去除默认的控件,包括确定/取消按钮,以及一个静态文本;

  3) 在对话框空白区域拖放一个ListBox控件,ID为ID_LIST_FILE,设置属性Accept files;

  4)为MfcDropFilesDlg添加消息WM_DROPFILES

 afx_msg void OnDropFiles(HDROP hDropInfo);
ON_MESSAGE(WM_DROPFILES,OnDropFiles) void CMfcDropFilesDlg::OnDropFiles( HDROP hDropInfo )
{
int DropCount = DragQueryFile(hDropInfo, -, NULL, );
for(int i=; i < DropCount; i++)
{
TCHAR szFullFileName[MAX_PATH];
DragQueryFile(hDropInfo, i, szFullFileName, MAX_PATH);
m_ListBox.AddString(szFullFileName);
}
DragFinish(hDropInfo); CDialog::OnDropFiles(hDropInfo);
}

  5) 实现窗口可拖放改变大小,控件随窗口大小一起改变

  对话框窗口大小可改变:设置对话框属性Styles->Border为Resizing

  

  定义成员变量m_rect记录对话框窗口的大小,自定义函数ChangeSize,重载WM_SIZE消息,具体代码如下:

// MfcDropFilesDlg.h
private:
CRect m_rect;
void ChangeSize(UINT nID,int cx,int cy); // Generated message map functions
//{{AFX_MSG(CMfcDropFilesDlg)
...
afx_msg void OnDropFiles(HDROP hDropInfo);
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP() // MfcDropFilesDlg.cpp
BEGIN_MESSAGE_MAP(CMfcDropFilesDlg, CDialog)
//{{AFX_MSG_MAP(CMfcDropFilesDlg)
...
ON_MESSAGE(WM_DROPFILES,OnDropFiles)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP() void CMfcDropFilesDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy); if(SIZE_MINIMIZED != nType)
{
ChangeSize(IDC_LIST_FILE, cx, cy);
GetClientRect(&m_rect);
}
} void CMfcDropFilesDlg::ChangeSize( UINT nID,int cx,int cy )
{
CRect rect;
CWnd* pWnd = GetDlgItem(nID);
if (!pWnd)
{
return;
}
pWnd->GetWindowRect(&rect); // 获取控件的区域大小
ScreenToClient(&rect); // 将控件大小转换为在对话框中的区域坐标
// 调整控件大小
rect.left = rect.left * cx/ m_rect.Width();
rect.right = rect.right * cx / m_rect.Width();
rect.top = rect.top * cy/ m_rect.Height();
rect.bottom = rect.bottom * cy / m_rect.Height();
// 执行控件大小调整
pWnd->MoveWindow(rect);
}

  6)运行结果

  

  

  /*****************************************************************************************************************************/

  Syntax
    UINT DragQueryFile( HDROP hDrop,
          UINT iFile,
          LPTSTR lpszFile,
          UINT cch
          );
  Parameters
    hDrop
    Identifier of the structure containing the file names of the dropped files.
    iFile
    Index of the file to query. If the value of the iFile parameter is 0xFFFFFFFF, DragQueryFile returns a count of the files dropped.

    If the value of the iFile parameter is between zero and the total number of files dropped, DragQueryFile copies the file name with the corresponding value to the buffer pointed to by the lpszFile parameter.
    lpszFile
    The address of a buffer to receive the file name of a dropped file when the function returns. This file name is a null-terminated string. If this parameter is NULL,   DragQueryFile returns the required size, in characters, of the buffer.
    cch
    Size, in characters, of the lpszFile buffer.

  Return Value

  When the function copies a file name to the buffer, the return value is a count of the characters copied, not including the terminating null character.

  If the index value is 0xFFFFFFFF, the return value is a count of the dropped files. Note that the index variable itself returns unchanged, and will therefore remain 0xFFFFFFFF.

  If the index value is between zero and the total number of dropped files and the lpszFile buffer address is NULL, the return value is the required size, in characters, of the buffer, not including the terminating null character.

  /*****************************************************************************************************************************/

  代码下载:(仅供参考)

  百度云:http://pan.baidu.com/s/1bpMlgvH     密码:g0fu

VC++ :实现简单的文件拖放(Drag and Drop)功能的更多相关文章

  1. HTML5 之拖放(drag与drop)

    拖放(Drag 和 drop)是 HTML5 标准的组成部分. 拖放是一种常见的特性,即抓取对象以后拖到另一个位置. 在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放. HTML5 拖放实例 ...

  2. Android开发者指南-用户界面-拖放-Drag and Drop[原创译文]

      英文原文:http://developer.android.com/guide/topics/ui/drag-drop.html 版本:Android 4.0 r1 译者注:黄色底色为未决译文 快 ...

  3. 在Blazor中实现拖放(drag and drop)

    前言 我在实现一个含有待办列表功能的页面时,发现了一个好看的设计,它将待办分为--"待办","正在进行",和"已完成"三种状态,并且将待办通 ...

  4. HTML 5 拖放(Drag 和drop)

    浏览器支持 Internet Explorer 9.Firefox.Opera 12.Chrome 以及 Safari 5. 1.把标签 draggable 属性设置为 true. 2.向标签添加on ...

  5. HTML5 拖放---drag和drop

    拖放四步走:第一步:设置元素可拖放,即把 draggable属性设置为 true:  例:<div id="div" draggable="true"&g ...

  6. 拖放(Drag和Drop)--html5

    拖放,就是抓取一个对象后拖放到另一个位置.很常用的一个功能,在还没有html5的时候,我们实现这个功能,通常会用大量的js代码,再利用mousemove,mouseup等鼠标事件来实现,总的来说比较麻 ...

  7. HTML5 拖放(Drag 和 Drop)功能开发——基础实战

    随着HTML5的普及度越来越高,现在写代码也遇到一些了,经过同事的点播开展了一次Dojo活动用以技术交流,我也乘此机会将HTML5的拖放功能整理了一下. 简介 拖拽(Drag/Drop)是个非常普遍的 ...

  8. Blazor 使用拖放(drag and drop)上传文件

    在很多上传文件的应用实例中, 都可以看到[拖放文件到此上传]这种骚功能 ,今天我们就来试试Blazor能不能完成这个想法. 简述HTML5拖放 拖放是HTML5标准的一部分,任何元素都能够拖放,也能够 ...

  9. OLE文件拖放

    使用IDropTarget接口同时支持文本和文件拖放 关于Windows的外壳扩展编程,拖放是比较简单的一种,在网上可以找到不少介绍这个技巧的文章.大部分是介绍使用MFC的COleDropTarget ...

随机推荐

  1. atitit.ajax上传文件的实现原理 与设计

    atitit.ajax上传文件的实现原理 与设计 1. 上传文件的三大难题 1 1.1. 本地预览 1 1.2. 无刷新 1 1.3. 进度显示 1 2.  传统的html4  + ajax 是无法直 ...

  2. IOS7的蛋疼各种收集

    ------------------ ios7基于viewController隐藏状态条:通过ViewController重载方法返回枚举值的方法来控制状态栏的隐藏和样式.首先,需要在Info.pli ...

  3. 安卓测试之ADB命令

    什么是ADB: adb的全称为Android Debug Bridge,就是起到调试桥的作用.借助adb工具,我们可以管理设备或手机模拟器的状态.还可以进行很多手机操作,如安装软件.系统升级.运行sh ...

  4. 给singer的左侧添加fixedTitle,并显示向上滚动偏移效果;

    1.将写好的dom绝对定位到顶部: 2.dom值为singerlist的currentIndex.title(通过计算属性获取),如果有则显示fixedTitle,没有则隐藏: 3.计算diff:当d ...

  5. java 多线程10:synchronized锁机制 之 锁定类静态方法 和锁定类.Class 和 数据String的常量池特性

    同步静态方法 synchronized还可以应用在静态方法上,如果这么写,则代表的是对当前.java文件对应的Class类加锁.看一下例子,注意一下printC()并不是一个静态方法: public ...

  6. 一款基jquery超炫的动画导航菜单

    今天给大家分享一款基jquery超炫的动画导航菜单.这款导航菜单,初始时页面中间一个按钮,单击按钮,菜单从左侧飞入页中.再次单击按钮,导航飞入左侧消息.动画效果很非常炫.一起看下效果图: 在线预览   ...

  7. 【WPF】当 ItemsSource 正在使用时操作无效。改用 ItemsControl.ItemsSource 访问和修改元素

    问题: 中文版报错:Additional information: 当 ItemsSource 正在使用时操作无效.改用 ItemsControl.ItemsSource 访问和修改元素. 英文版报错 ...

  8. uWSGI的stats注释,送给需要的人,欢迎指正

    吐槽先,对于uWSGI状态信息没有文档说明这样一个现实,我只想说一句:F*CK YOU!!! 花了2天时间,累得眼珠子疼,针对这鬼畜的stats,借助Total Commander和VS大概撸了一边u ...

  9. 有关一道printf 的面试题

    今天有个学生面试,面试题目里面有一道有关 printf 的输出问题 源代码如下: #include <stdio.h> int main(void) { int a = 10, b = 2 ...

  10. Oracle数据误删除的恢复操作

    flashbackup 闪回操作: 1. 打开表的闪回功能: alter table dw_stg.fm_user_play_d enable row movement; 2. 查询要闪回的表的记录信 ...