Example #1
0
void DragDrop(const char* szFile)
{
//	CoUninitialize();
	CoInitialize(NULL);
	OleInitialize(NULL);

	CIDropSource* pdsrc = new CIDropSource;
	CIDataObject* pdobj = new CIDataObject(pdsrc);

	FORMATETC fmtetc = {0}; 
	fmtetc.cfFormat = CF_HDROP; 
	fmtetc.dwAspect = DVASPECT_CONTENT; 
	fmtetc.lindex = -1; 
	fmtetc.tymed = TYMED_HGLOBAL;

	STGMEDIUM medium = {0};
	DROPFILES* pdf = (DROPFILES*)GlobalAlloc(GMEM_FIXED, sizeof(DROPFILES) + 256);
	memset(pdf, 0, 256);
	pdf->pFiles = sizeof(DROPFILES);
	pdf->fWide = 0;
	pdf->pt.x = 0;
	pdf->pt.y = 0;
	pdf->fNC = 1;
	strcpy(&((char*)pdf)[sizeof(DROPFILES)], szFile);
	medium.tymed = TYMED_HGLOBAL;
	medium.hGlobal = pdf;
//	medium.hGlobal = (WCHAR*)GlobalAlloc(GMEM_FIXED, sizeof(WCHAR)*256);
//	MultiByteToWideChar(CP_ACP, 0, "c:\\switchflip.log", -1, medium.lpszFileName, 256);

	pdobj->SetData(&fmtetc,&medium,TRUE);

	DWORD dwEffect = 0;
	DWORD dwReturn = ::DoDragDrop(pdobj, pdsrc, DROPEFFECT_COPY, &dwEffect);
//	Debug("dwEffect = %d       dwReturn = %d", dwEffect, dwReturn);
}
void CTuotuoTabCtrl::DraggingItem(int iMouseX, int iMouseY)
{
	m_bDraggingSource = true;
	m_iDraggingItemIndex = m_pSelectedItem->GetIndex();
	m_nDragToPos = m_pSelectedItem->GetIndex();
	m_iBeginDragItemOffset = iMouseX - m_pSelectedItem->GetIndex() * m_iCurrentWidth - m_iScrollOffset;

	CIDropSource* pdsrc = new CIDropSource();
	pdsrc->AddRef();
	CIDataObject* pdobj = new CIDataObject(pdsrc);
	pdobj->AddRef();

	HWND hTargetFrame = NULL;
	FORMATETC fmtetc = { CF_TEXT, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
	CStringA str = m_pSelectedItem->GetURLText();
	STGMEDIUM medium = { TYMED_HGLOBAL };
	int iLen = str.GetLength() + 1 + sizeof(DragGlobalData);
	medium.hGlobal = ::GlobalAlloc(GMEM_MOVEABLE, iLen);
	char *pMem = (char*)::GlobalLock(medium.hGlobal);
	strcpy_s(pMem, iLen - 1, str);
	DragGlobalData *pData = (DragGlobalData*)(pMem + iLen - sizeof(DragGlobalData));
	pData->pDraggingItem = m_pSelectedItem;
	pData->hDragToFrame = &hTargetFrame;
	pData->dwProcessID = ::GetCurrentProcessId();
//	CTabDraggingWindow::_()->SetParam(1);
	::GlobalUnlock(medium.hGlobal);
	pdobj->SetData(&fmtetc, &medium, TRUE);

	float fPercent = (float)m_iBeginDragItemOffset / (float)m_iCurrentWidth;
//	CTabDraggingWindow::_()->SetTabDragging(pData->pDraggingItem->GetText(), (HICON)pData->pDraggingItem->GetIcon(), pData->pDraggingItem->GetChildFrame()->FS()->MDI()->m_hWnd, pData->pDraggingItem->GetAxControl(), fPercent);

	RECT rcClient;
	GetClientRect(&rcClient);
	if (iMouseY > rcClient.bottom || iMouseY < 0)
	{
		m_pDraggingItem = m_pSelectedItem;
		DragItemOut();
	}

	bool bReturnFocusToCurrentPage = false;
	DWORD dwEffect;
	HRESULT hr = ::DoDragDrop(pdobj, pdsrc, DROPEFFECT_MOVE, &dwEffect);
//	CTabDraggingWindow::_()->SetParam(0);
//	CTabDraggingWindow::_()->StopTabDragging();
	pdsrc->Release();
	pdobj->Release();

	m_bDraggingSource = false;
	m_pDraggingItem = NULL;

	if (hr == DRAGDROP_S_DROP)
	{
		if (hTargetFrame)
		{
			DragItemEnd_Source(hTargetFrame);
			if (hTargetFrame == FS()->MainFrame()->m_hWnd)
				bReturnFocusToCurrentPage = true;			// 如果是在自己的框架里面拖动,则归还焦点
		}
		else
		{
			DragItemCancel();
		}
	}
	else if (hr == DRAGDROP_S_CANCEL)
	{
		bReturnFocusToCurrentPage = true;			// 如果是取消拖拽,则归还焦点到iewnd
		DragItemCancel();
	}

	m_nDragToPos = -2;
}