// ExplorerDelayDropDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ExplorerDelayDrop.h"
#include "ExplorerDelayDropDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CExplorerDelayDropDlg dialog
CExplorerDelayDropDlg::CExplorerDelayDropDlg(CWnd* pParent /*=NULL*/)
: CDialog(CExplorerDelayDropDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CExplorerDelayDropDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_FILE_LIST, m_fileList);
}
BEGIN_MESSAGE_MAP(CExplorerDelayDropDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_NOTIFY(LVN_BEGINDRAG, IDC_FILE_LIST, &CExplorerDelayDropDlg::OnBeginDrag)
END_MESSAGE_MAP()
// CExplorerDelayDropDlg message handlers
BOOL CExplorerDelayDropDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
AfxOleInit();
m_fileList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
m_fileList.InsertColumn(0, _T("File"), LVCFMT_LEFT,75);
m_fileList.InsertColumn(1, _T("Details"), LVCFMT_LEFT,175);
for(TCHAR c = _T('A'); c < _T('F'); c++)
{
CString text1, text2;
text1.Format(_T("%c.txt"),c);
text2.Format(_T("File full of %cs"),c);
m_fileList.SetItemText(
m_fileList.InsertItem(c - _T('A'),text1),1,text2);
}
return TRUE;
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CExplorerDelayDropDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CExplorerDelayDropDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CExplorerDelayDropDlg::OnBeginDrag(NMHDR *pNMHDR, LRESULT *pResult)
{
UINT uFileCount = m_fileList.GetSelectedCount();
UINT uBuffSize = sizeof(FILEGROUPDESCRIPTOR) +
(uFileCount-1) * sizeof(FILEDESCRIPTOR);
HGLOBAL hFileDescriptor = GlobalAlloc (
GHND | GMEM_SHARE, uBuffSize );
if(hFileDescriptor)
{
FILEGROUPDESCRIPTOR* pGroupDescriptor =
(FILEGROUPDESCRIPTOR*) GlobalLock ( hFileDescriptor );
if(pGroupDescriptor)
{
FILEDESCRIPTOR* pFileDescriptorArray =
(FILEDESCRIPTOR*)((LPBYTE)pGroupDescriptor + sizeof(UINT));
pGroupDescriptor->cItems = uFileCount;
POSITION pos = m_fileList.GetFirstSelectedItemPosition();
int index = 0;
m_DataSrc.m_Files.RemoveAll();
while( NULL != pos )
{
int nSelItem = m_fileList.GetNextSelectedItem( pos );
ZeroMemory(&pFileDescriptorArray[index],
sizeof(FILEDESCRIPTOR));
lstrcpy ( pFileDescriptorArray[index].cFileName,
m_fileList.GetItemText( nSelItem, 0 ) );
m_DataSrc.m_Files.Add(pFileDescriptorArray[index].cFileName);
pFileDescriptorArray[index].dwFlags = FD_FILESIZE|FD_ATTRIBUTES;
pFileDescriptorArray[index].nFileSizeLow = 512;
pFileDescriptorArray[index].nFileSizeHigh = 0;
pFileDescriptorArray[index].dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
index++;
}
}
else
{
GlobalFree ( hFileDescriptor );
}
}
GlobalUnlock ( hFileDescriptor );
FORMATETC etcDescriptor = {
RegisterClipboardFormat(CFSTR_FILEDESCRIPTOR),
NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
m_DataSrc.CacheGlobalData ( RegisterClipboardFormat(
CFSTR_FILEDESCRIPTOR), hFileDescriptor, &etcDescriptor );
FORMATETC etcContents = {
RegisterClipboardFormat(CFSTR_FILECONTENTS),
NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
m_DataSrc.DelayRenderFileData(RegisterClipboardFormat(
CFSTR_FILECONTENTS), &etcContents);
DROPEFFECT dwEffect = m_DataSrc.DoDragDrop (
DROPEFFECT_COPY | DROPEFFECT_MOVE );
if(dwEffect == DROPEFFECT_NONE )
{
GlobalFree( hFileDescriptor );
}
*pResult = 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ExplorerDelayDrop.zip (13个子文件)
resource.h 597B
stdafx.h 3KB
MyOleDataSource.h 350B
ExplorerDelayDrop.cpp 2KB
MyOleDataSource.cpp 1KB
ExplorerDelayDrop.vcproj 6KB
stdafx.cpp 217B
ExplorerDelayDropDlg.cpp 4KB
ExplorerDelayDropDlg.h 812B
ExplorerDelayDrop.rc 5KB
res
ExplorerDelayDrop.ico 21KB
ExplorerDelayDrop.rc2 408B
ExplorerDelayDrop.h 570B
共 13 条
- 1
资源评论
- linshuzhi2016-04-06一般般,可以参考下
zhhhz
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功