控件如何接受文件拖动

lessonwill 2003-01-12 08:34:39
想用vc及mfc实现下述功能:
1.将文本文件拖入编辑框,内容在其中自动显示;
2.将文件拖入列表框,文件名在其中显示
请求帮忙!
...全文
336 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lessonwill 2003-01-13
  • 打赏
  • 举报
回复
Chice_wxg(),你的这段代码我该放在什么地方呢
我用的vc,但我不知道在vc里用sdk的方式处理消息,代码该怎么放
还有,mfc的方式怎么处理?
demetry 2003-01-13
  • 打赏
  • 举报
回复
看了这个你就明白了。

http://expert.csdn.net/Expert/topic/1346/1346358.xml?temp=.586239
lessonwill 2003-01-13
  • 打赏
  • 举报
回复
CWnd::OnDropFiles
afx_msg void OnDropFiles( HDROP hDropInfo );

我想,能不能通过重载这个函数来实现它?
lessonwill 2003-01-13
  • 打赏
  • 举报
回复
这种消息不能自classwizard添加吧,怎么处理?
需要修改哪些地方的代码》能不能讲讲,谢谢!
lessonwill 2003-01-13
  • 打赏
  • 举报
回复
老大,对话框的,哪来的mainframe啦
我倒是想到了解决办法,但试验不成功,帮忙查查错吧!
基于对话框的程序,有一个列表框,想实现:当文件拖入该列表框时,框中显示其文件名。
我这样做的:
1.对话框头文件中添:
afx_msg void OnDropFiles(HDROP hDropInfo);
2.BEGIN_MESSAGE_MAP下添:
ON_WM_DROPFILES()
3.添加函数:
void CReplaceDlg::OnDropFiles(HDROP hDropInfo)
{
char dropfname[2000];
int i=DragQueryFile(hDropInfo,1,dropfname,2000);
CString str(dropfname,i);
m_edit2=str;
UpdateData(FALSE);
CDialog::OnDropFiles(hDropInfo);
}
4.更改accpet标签
然后运行,但列表框中未出现我要的文件名,不过经我测试它的确接受到了消息。不知道错在哪里?
搞定我就给帖子加分,然后给分!
dxhdxh2k 2003-01-13
  • 打赏
  • 举报
回复
void CMainFrame::OnDropFiles(HDROP hDropInfo)
{
POINT pt;
WORD cFiles, a;
char lpszFile[80];

DragQueryPoint(hDropInfo, &pt);

cFiles = DragQueryFile(hDropInfo, 0xFFFFFFFF, (LPSTR) NULL, 0);
for(a = 0; a < cFiles; pt.y += 20, a++)
{
DragQueryFile(hDropInfo, a, lpszFile, sizeof(lpszFile));
MessageBox(lpszFile,"aaaaaaa");
//TextOut(GetSafeDC(), pt.x, pt.y, lpszFile, lstrlen(lpszFile));
}
//DragFinish(hDropInfo);
CFrameWnd::OnDropFiles(hDropInfo);
}
给分啊!
dxhdxh2k 2003-01-13
  • 打赏
  • 举报
回复
classwizard->添加消息WM_DROPFILES,在其中输入以下行列:

POINT pt;
WORD cFiles, a;
char lpszFile[80];

DragQueryPoint(hDropInfo, &pt);

cFiles = DragQueryFile(hDropInfo, 0xFFFFFFFF, (LPSTR) NULL, 0);
for(a = 0; a < cFiles; pt.y += 20, a++)
{
DragQueryFile(hDropInfo, a, lpszFile, sizeof(lpszFile));
MessageBox(lpszFile,"aaaaaaa");;
}
给分啊!
sjd163 2003-01-12
  • 打赏
  • 举报
回复
up
dxhdxh2k 2003-01-12
  • 打赏
  • 举报
回复
up
Chice_wxg 2003-01-12
  • 打赏
  • 举报
回复 1
设置窗口 DragAcceptFiles(TRUE);

然后处理 WM_DROPFILES 消息


SDK代码如下:
For example, an application can call the DragAcceptFiles function when it starts and call a drag-drop function when it receives a WM_DROPFILES message, as shown in the following example.

case WM_CREATE:
DragAcceptFiles(hwnd, TRUE);
break;

case WM_DROPFILES:
DragFunc(hwnd, wParam); /* application-defined function */
break;

case WM_DESTROY:
DragAcceptFiles(hwnd, FALSE);
break;


The following example uses the DragQueryPoint function to determine where to begin to write text. The first call to the DragQueryFile function determines the number of dropped files. The loop writes the name of each file, beginning at the point returned by DragQueryPoint.

POINT pt;
WORD cFiles, a;
char lpszFile[80];

DragQueryPoint((HANDLE) wParam, &pt);

cFiles = DragQueryFile((HANDLE) wParam, 0xFFFF, (LPSTR) NULL, 0);
for(a = 0; a < cFiles; pt.y += 20, a++) {
DragQueryFile((HANDLE) wParam, a, lpszFile, sizeof(lpszFile));
TextOut(hdc, pt.x, pt.y, lpszFile, lstrlen(lpszFile));
}

DragFinish((HANDLE) wParam);

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧