拖拽到控件

来源:互联网 发布:天星教育php招聘 编辑:程序博客网 时间:2024/06/05 08:26

1wm_drop


2



CoInitialize(NULL);



if (!AfxOleInit())
{
AfxMessageBox(_T("Ole Initialization Failed"));
return FALSE;

}

----------------------------------------------------------------------------------------------------------------------

int CGetEdit::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
if (CEdit::OnCreate(lpCreateStruct) == -1)
return -1;


BOOL success = m_OleTarget.Register(this);
DWORD s = GetLastError();
if(!success )
MessageBox(_T("Ole Register Drop Target Failed"));             


m_OleTarget.SetParent(this);


return 0;
}---------------------------------------------------------------------------------------------------------------------

COleListDropTarget::COleListDropTarget(CWnd* pParent)
{
m_pParent = pParent;
}


COleListDropTarget::~COleListDropTarget()
{
}
//
// OnDragEnter is called by OLE dll's when drag cursor enters
// a window that is REGISTERed with the OLE dll's
//
DROPEFFECT COleListDropTarget::OnDragEnter(CWnd* pWnd, COleDataObject* 
           pDataObject, DWORD dwKeyState, CPoint point )
{
if (!pDataObject->IsDataAvailable(CF_TEXT))
{
return DROPEFFECT_NONE;

}


    // if the control key is held down, return a drop effect COPY 
    if((dwKeyState&MK_CONTROL) == MK_CONTROL)
        return DROPEFFECT_COPY;
    // Otherwise return a drop effect of MOVE
    else
        return DROPEFFECT_MOVE;    
}


//
// OnDragLeave is called by OLE dll's when drag cursor leaves
// a window that is REGISTERed with the OLE dll's
//
void COleListDropTarget::OnDragLeave(CWnd* pWnd)
{
    // Call base class implementationhttp://topic.csdn.net/u/20110524/20/389fd829-b4e5-4378-af1b-b9e2d0648eff.html
    COleDropTarget::OnDragLeave(pWnd);
}


// 
// OnDragOver is called by OLE dll's when cursor is dragged over 
// a window that is REGISTERed with the OLE dll's
//
DROPEFFECT COleListDropTarget::OnDragOver(CWnd* pWnd, COleDataObject* 
           pDataObject, DWORD dwKeyState, CPoint point )
{     
if (!pDataObject->IsDataAvailable(CF_TEXT))
return DROPEFFECT_NONE;


    if((dwKeyState&MK_CONTROL) == MK_CONTROL)
        return DROPEFFECT_NONE;  
    else
        return DROPEFFECT_MOVE;  // move source
}


extern HWND myhwnd;


BOOL COleListDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject, 
                 DROPEFFECT dropEffect, CPoint point )
{           
    HGLOBAL  hGlobal;
    LPCSTR   pData;                     


if (pDataObject->IsDataAvailable(CF_TEXT))
{
STGMEDIUM Stg;
BOOL bValue = pDataObject->GetData(CF_TEXT, &Stg);

char *strText = (char*)GlobalLock(Stg.hGlobal);

int   nLen   =   strlen(strText)   +   1;
int   nwLen   =   MultiByteToWideChar(CP_ACP,   0,   strText,   nLen,   NULL,   0);
TCHAR   lpszFile[256];
MultiByteToWideChar(CP_ACP,   0,   strText,   nLen,   lpszFile,   nwLen);


((CGetEdit *)m_pParent)->SetWindowText(lpszFile);
// CString strUrl;
// strUrl.Format(_T("%s"),strText);
// GetDlgItem(myhwnd, IDC_GET_LIST)->SetWindowText();


// ((CGetList *)m_pParent)->AddUrl(strUrl);


GlobalUnlock(Stg.hGlobal);
GlobalFree(Stg.hGlobal);


}


    if((dropEffect&DROPEFFECT_MOVE) != DROPEFFECT_MOVE)
        return FALSE;


    // Get text data from COleDataObject
    hGlobal=pDataObject->GetGlobalData(CF_TEXT);


    // Get pointer to data
    pData=(LPCSTR)GlobalLock(hGlobal);    
    ASSERT(pData!=NULL); 


    // Unlock memory - Send dropped text into the "bit-bucket"
    GlobalUnlock(hGlobal);


    return TRUE;
}


void COleListDropTarget::SetParent(CWnd *pParent)
{
m_pParent = pParent;
}