Chinaunix首页 | 论坛 | 博客
  • 博客访问: 408052
  • 博文数量: 78
  • 博客积分: 3642
  • 博客等级: 中校
  • 技术积分: 695
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-23 15:33
文章分类

全部博文(78)

文章存档

2007年(53)

2006年(25)

分类:

2007-03-24 15:51:32

//IDropTarget的Drop中实现

STDMETHODIMP Drop(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect)
{
    HRESULT hr;
    STGMEDIUM stgMedium;
    FORMATETC cFmt;
    UINT CF_URL;
    UINT CF_HTML;
    
    CF_URL = RegisterClipboardFormat(CFSTR_SHELLURL);
    CF_HTML = RegisterClipboardFormat(_T("HTML Format"));

    //HTML

    cFmt.lindex = -1;
    cFmt.cfFormat = CF_HTML;
    cFmt.ptd = 0;
    cFmt.dwAspect = 1;
    cFmt.tymed = TYMED_HGLOBAL;

    hr = pDataObject->GetData(&cFmt, &stgMedium);
    if(SUCCEEDED(hr))
    {
        char *utf = (CHAR*)(stgMedium.hGlobal);//utf8编码

        //..........

        ::ReleaseStgMedium(&stgMedium);
        return S_OK;
    }

     //URL

    cFmt.lindex = -1;
    cFmt.cfFormat = CF_URL;
    cFmt.ptd = 0;
    cFmt.dwAspect = 1;
    cFmt.tymed = TYMED_HGLOBAL;

    hr = pDataObject->GetData(&cFmt, &stgMedium);
    if(SUCCEEDED(hr))
    {
        char *url = (char*)(stgMedium.hGlobal)//ascii编程

        //.........

        ::ReleaseStgMedium(&stgMedium);
        return S_OK;
    }

    //FILE.

    cFmt.lindex = -1;
    cFmt.cfFormat = CF_HDROP;
    cFmt.ptd = 0;
    cFmt.dwAspect = 1;
    cFmt.tymed = TYMED_HGLOBAL;
    
    hr = pDataObject->GetData(&cFmt, &stgMedium);
    if(SUCCEEDED(hr))
    {
        HDROP hDrop;
        hDrop = (HDROP)(stgMedium.hGlobal);
        UINT iFiles,ich =0;
        TCHAR Buffer[MAX_PATH] = _T("");
        memset(&iFiles,0xff,sizeof(iFiles));
        //Get the Drag _Files Number.

        int Count = ::DragQueryFile(hDrop,iFiles,Buffer,0);
        if(Count)
        {
            for (int i=0;i<Count;i++)
            {
                if(::DragQueryFile(hDrop,i,Buffer,sizeof(Buffer)))
                {
                    //File name is in Buffer now.

                    //...........

                }
            }
        }
        //.................

        ::DragFinish(hDrop);
        ::ReleaseStgMedium(&stgMedium);
        return S_OK;
    }
    return E_FAILED;
}

阅读(1836) | 评论(0) | 转发(0) |
0

上一篇:IE7中激活的tab

下一篇:MSHTML的DOM模型

给主人留下些什么吧!~~