示例#1
0
HRESULT CMainFrameDropTarget::PasteText(CLIPFORMAT cfData, COleDataObject& data)
{
    HRESULT hrPasteResult = E_FAIL;
    HANDLE hMem;
    if ((hMem = data.GetGlobalData(cfData)) != NULL)
    {
        LPCSTR pszUrlA;
        if ((pszUrlA = (LPCSTR)GlobalLock(hMem)) != NULL)
        {
            // skip white space
            while (isspace((unsigned char)*pszUrlA))
                pszUrlA++;

            hrPasteResult = S_FALSE; // default: nothing was pasted
            if (_strnicmp(pszUrlA, "ed2k://|", 8) == 0)
            {
                CString strData(pszUrlA);
                int iPos = 0;
                CString str = strData.Tokenize(_T("\r\n"), iPos);
                while (!str.IsEmpty())
                {
                    theApp.emuledlg->ProcessED2KLink(str);
                    hrPasteResult = S_OK;
                    str = strData.Tokenize(_T("\r\n"), iPos);
                }
            }

            GlobalUnlock(hMem);
        }
        GlobalFree(hMem);
    }
    return hrPasteResult;
}
示例#2
0
void CHexEdit::OnEditPaste() 
{
	COleDataObject	obj;	
	if (obj.AttachClipboard()) 
	{
		HGLOBAL hmem = NULL;
		if (obj.IsDataAvailable(RegisterClipboardFormat("BinaryData"))) 
		{
			hmem = obj.GetGlobalData(RegisterClipboardFormat("BinaryData"));
		}	
		else if (obj.IsDataAvailable(CF_TEXT)) 
		{
			hmem = obj.GetGlobalData(CF_TEXT);
		}
		if(hmem)
		{
			LPBYTE	p = (BYTE*)::GlobalLock(hmem);
			DWORD	dwSizeMem=::GlobalSize(hmem);
			DWORD	dwSizeSel=GetSelLength();
			DWORD	dwLen =dwSizeMem>dwSizeSel?dwSizeSel:dwSizeMem;
			int		insert;
			
			NormalizeSel();
			if(m_selStart == 0xffffffff)
			{
				if(m_currentMode == EDIT_LOW)
					m_currentAddress++;
				insert = m_currentAddress;
				SelInsert(m_currentAddress, dwLen);
			}
			else
			{
				insert = m_selStart;
				SelDelete(m_selStart,m_selStart+dwLen-1);
				SelInsert(insert, dwLen);
			}
			memcpy(m_pData+insert, p, dwLen);
			
			m_currentAddress = insert+dwLen;
//			RepositionCaret(m_currentAddress);
			ResetPos();
			Invalidate(FALSE);
			::GlobalUnlock(hmem);
		}
	}
}
示例#3
0
void CHexEdit::OnEditPaste() 
{
	COleDataObject	obj;	
	if (obj.AttachClipboard()) 
	{
		HGLOBAL hmem = NULL;
		if (obj.IsDataAvailable(RegisterClipboardFormat(L"BinaryData"))) 
		{
			hmem = obj.GetGlobalData(RegisterClipboardFormat(L"BinaryData"));
		}	
		else if (obj.IsDataAvailable(CF_TEXT)) 
		{
			hmem = obj.GetGlobalData(CF_TEXT);
		}
		if(hmem)
		{
			LPBYTE	p = (BYTE*)::GlobalLock(hmem);
			DWORD	dwLen = ::GlobalSize(hmem);
			int		insert;
			int		oa = m_currentAddress;
			
			NormalizeSel();
			if(m_selStart == 0xffffffff)
			{
				if(m_currentMode == EDIT_LOW)
					m_currentAddress++;
				insert = m_currentAddress;
				SelInsert(m_currentAddress, dwLen);
			}
			else
			{
				insert = m_selStart;
				SelDelete(m_selStart, m_selEnd);
				SelInsert(insert, dwLen);
				SetSel(-1, -1);
			}

			memcpy(m_pData+insert, p, dwLen);

			m_currentAddress = oa;
			RedrawWindow();
			::GlobalUnlock(hmem);
		}
	}
}
示例#4
0
文件: kguipc.cpp 项目: CarlHuff/kgui
void kGUISystemWin::Paste(kGUIString *s)
{
	COleDataObject	obj;

	if (obj.AttachClipboard())
	{
#if 0
		if (obj.IsDataAvailable(CF_UNICODETEXT))
		{
			HGLOBAL hmem = obj.GetGlobalData(CF_UNICODETEXT);
			CMemFile sf((BYTE*) ::GlobalLock(hmem),(UINT) ::GlobalSize(hmem));
			CString buffer;

			LPSTR str = buffer.GetBufferSetLength((int)::GlobalSize(hmem));
			sf.Read(str,(UINT) ::GlobalSize(hmem));
			::GlobalUnlock(hmem);

			s->SetEncoding(ENCODING_UTF8);
			s->SetString(buffer);
		}
		else if (obj.IsDataAvailable(CF_TEXT))
#else
		if (obj.IsDataAvailable(CF_TEXT))
#endif
		{
			HGLOBAL hmem = obj.GetGlobalData(CF_TEXT);
			CMemFile sf((BYTE*) ::GlobalLock(hmem),(UINT) ::GlobalSize(hmem));
			CString buffer;

			LPSTR str = buffer.GetBufferSetLength((int)::GlobalSize(hmem));
			sf.Read(str,(UINT) ::GlobalSize(hmem));
			::GlobalUnlock(hmem);

//			s->SetEncoding(ENCODING_UTF8);
			s->SetEncoding(ENCODING_8BIT);
			s->SetString(buffer);
		}
	}
}
示例#5
0
STDMETHODIMP CBmpCtxMenuExt::Initialize (
                               LPCITEMIDLIST pidlFolder,
                               LPDATAOBJECT  pDO,
                               HKEY          hkeyProgID )
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

COleDataObject dataobj;
HGLOBAL        hglobal;
HDROP          hdrop;
bool           bOK = false;

    dataobj.Attach ( pDO, FALSE );      // FALSE = don't release IDataObject interface when destroyed

    // Get the first selected file name.  I'll keep this simple and just check
    // the first name to see if it's a .BMP.

    hglobal = dataobj.GetGlobalData ( CF_HDROP );

    if ( NULL == hglobal )
        return E_INVALIDARG;

    hdrop = (HDROP) GlobalLock ( hglobal );

    if ( NULL == hdrop )
        return E_INVALIDARG;

    // Get the name of the first selected file.

    if ( DragQueryFile ( hdrop, 0, m_szFile, MAX_PATH ))
        {
        // Is its extension .BMP?
        if ( PathMatchSpec ( m_szFile, _T("*.bmp") ))
            {
            // Load the bitmap and attach our CBitmap object to it.
            HBITMAP hbm = (HBITMAP) LoadImage ( NULL, m_szFile, IMAGE_BITMAP, 0, 0, 
                                                LR_LOADFROMFILE );

            if ( NULL != hbm )
                {
                // We loaded the bitmap, so attach the CBitmap to it.
                VERIFY( m_bmp.Attach ( hbm ) );
                bOK = true;
                }
            }
        }

    GlobalUnlock ( hglobal );

    return bOK ? S_OK : E_FAIL;
}
示例#6
0
	bool zstringEx::tools_getClipboardText()
	{    
		COleDataObject obj;

		if (obj.AttachClipboard()) 
		{
				if (obj.IsDataAvailable(CF_TEXT)) 
				{
					HGLOBAL hmem = obj.GetGlobalData(CF_TEXT);                  
					CMemFile sf((BYTE*) ::GlobalLock(hmem), (UINT)::GlobalSize(hmem));
					mem_data.mem_resizenull((UINT)::GlobalSize(hmem));
					sf.Read(mem_data.mem_string, (UINT)::GlobalSize(hmem));
					::GlobalUnlock(hmem);
					sf.Close();	
					return true;
				}
		}
		return false;
	}
示例#7
0
HRESULT CMainFrameDropTarget::PasteHDROP(COleDataObject &data)
{
	HRESULT hrPasteResult = E_FAIL;
	HANDLE hMem;
	if ((hMem = data.GetGlobalData(CF_HDROP)) != NULL)
	{
		LPDROPFILES lpDrop;
		if ((lpDrop = (LPDROPFILES)GlobalLock(hMem)) != NULL)
		{
			if (lpDrop->fWide)
			{
				LPCWSTR pszFileNameW = (LPCWSTR)((LPBYTE)lpDrop + lpDrop->pFiles);
				while (*pszFileNameW != L'\0')
				{
					USES_CONVERSION;
					if (FAILED(AddUrlFileContents(W2CT(pszFileNameW))))
						break;
					hrPasteResult = S_OK;
					pszFileNameW += wcslen(pszFileNameW) + 1;
				}
			}
			else
			{
				LPCSTR pszFileNameA = (LPCSTR)((LPBYTE)lpDrop + lpDrop->pFiles);
				while (*pszFileNameA != '\0')
				{
					USES_CONVERSION;
					if (FAILED(AddUrlFileContents(A2CT(pszFileNameA))))
						break;
					hrPasteResult = S_OK;
					pszFileNameA += strlen(pszFileNameA) + 1;
				}
			}
			GlobalUnlock(hMem);
		}
		GlobalFree(hMem);
	}
	return hrPasteResult;
}
示例#8
0
HRESULT CMainFrameDropTarget::PasteHTML(COleDataObject& data)
{
    HRESULT hrPasteResult = E_FAIL;
    HGLOBAL hMem;
    if ((hMem = data.GetGlobalData(m_cfHTML)) != NULL)
    {
        LPCSTR pszClipboard;
        if ((pszClipboard = (LPCSTR)GlobalLock(hMem)) != NULL)
        {
            hrPasteResult = S_FALSE; // default: nothing was pasted
            LPCSTR pszHTML = strchr(pszClipboard, '<');
            if (pszHTML != NULL)
            {
                CComBSTR bstrHTMLText((LPCOLESTR)CA2W(pszHTML));
                PASTEURLDATA Paste(bstrHTMLText);
                hrPasteResult = PasteHTML(&Paste);
            }
            GlobalUnlock(hMem);
        }
        GlobalFree(hMem);
    }
    return hrPasteResult;
}
示例#9
0
//IDropTarget
	STDMETHODIMP CDropT::DragEnter(IDataObject* pDataObj, DWORD grfKeyState,
														 POINTL pt, DWORD* pdwEffect)
	{
		COleDataObject dataObj;
		HGLOBAL global = NULL;
		HDROP dropFile = NULL;

		dataObj.Attach(pDataObj, FALSE);
		if(global = dataObj.GetGlobalData(CF_HDROP))
		{
			UINT numDropFile = 0;
			wchar_t buff[MAX_PATH] = {0};
			dropFile = static_cast<HDROP>(GlobalLock(global));
			numDropFile = DragQueryFile(dropFile, 0xFFFFFFFF, buff, MAX_PATH);
			for(UINT i = 0; i != numDropFile; ++i)
			{
				if(DragQueryFile(dropFile, i, buff, MAX_PATH))
				{
					m_lsDroppedFiles.push_back(buff);
				}
			}
			GlobalUnlock(global);
		}

		dataObj.Detach();

		if(!m_lsDroppedFiles.empty())
		{
			*pdwEffect = DROPEFFECT_COPY;
		}
		else
		{
			*pdwEffect = DROPEFFECT_NONE;
		}
		return S_OK;	
	}
示例#10
0
文件: ddmgr.cpp 项目: aolko/construct
////////////////////////////////////////////////////////
//This function loads CF_TEXT data from the clipboard
//or drag/drop into a CStringArray, one line of text
//per array entry. A null in the input text
//denotes a new line.
//
//If pasting from clipboard, pDataObject should be NULL.
//
//You usually call this function from:
//
//1) Your view class's OnDrop() method when a drag-
//   drop operation ends, to load the data for use.
//
//2) Your view (or document) class's OnEditPaste()
//   method when doing a paste from the clipboard.
////////////////////////////////////////////////////////
BOOL CDragDropMgr::GetCFText(
                   CStringArray*   pcsText,
                   COleDataObject* pDataObject)
{
    BOOL bOk = FALSE;

    CString csLine = "";

    COleDataObject* pObj = NULL;

    //If from clipboard, then there is no
    //data object passed in, so use a local copy
    if (pDataObject == NULL)
        pObj = new COleDataObject();

    else
        pObj = pDataObject;

    //Make sure basic data is OK
    if (pObj == NULL)
        return FALSE;

    else if ((pDataObject == NULL &&
              !pObj->AttachClipboard())       ||
              pcsText== NULL                  ||
              !pObj->IsDataAvailable(CF_TEXT))
    {
        pObj->Release();

        if (pDataObject == NULL)
            delete pObj;

        return FALSE;
    }

    //The format etc struct tells how the data
    //should be transferred.
    //Do NOT use the MFC defaults here - they are no good
    FORMATETC fe;

    fe.cfFormat = CF_TEXT;
    fe.tymed    = TYMED_HGLOBAL;
    fe.lindex   = -1;
    fe.dwAspect = DVASPECT_CONTENT;
    fe.ptd      = NULL;

    //Fetch the data from the OLE data object
    HGLOBAL hMem = pObj->GetGlobalData(CF_TEXT,&fe);

    if (hMem != NULL)
    {
        char* pchT = (char*)::GlobalLock(hMem);

        if (pchT != NULL)
        {
            DWORD dwSize = ::GlobalSize(hMem);

            int  i     = 0;
            BOOL bDone = FALSE;

            while (!bDone)
            {
               //Hit a crlf: Add current line
               if (pchT[i+1] == '\n' && pchT[i] == '\r')
               {
                  pcsText->Add(csLine);
                  csLine = "";
                  i += 2;
               }

               //End of the block: Add final line
               else if (pchT[i] == '\0' || i >= DD_MAXCHARS)
               {
                  pcsText->Add(csLine);
                  bDone = TRUE;;
               }

               //Normal character: Add to line being built
               else
               {
                  csLine += pchT[i];
                  i++;
               }
            }

            ::GlobalUnlock(hMem);

            bOk = TRUE;
        }
    }   //hmem not null

    pObj->Release();

    if (pDataObject == NULL)
        delete pObj;

    return bOk;
}
示例#11
0
文件: ddmgr.cpp 项目: aolko/construct
////////////////////////////////////////////////////////
//This function loads data from the clipboard
//or drag/drop into a local object of the proper
//type for use.
//
//If pasting from clipboard, pDataObject should be NULL.
//
//You usually call this function from:
//
//1) Your view class's OnDrop() method when a drag-
//   drop operation ends, to load the data for use.
//
//2) Your view (or document) class's OnEditPaste()
//   method when doing a paste from the clipboard.
////////////////////////////////////////////////////////
BOOL CDragDropMgr::DoDrop(
                   CObject*        pO,
                   COleDataObject* pDataObject,
                   LPCTSTR         lpstrFormat)
{
//	try
	{
		UINT format = ::RegisterClipboardFormat(lpstrFormat);

		COleDataObject* pObj = NULL;

		// If from clipboard, then there is no
		// data object passed in, so use a local copy
		if (pDataObject == NULL)
			pObj = new COleDataObject();

 		else
			pObj = pDataObject;

		// Make sure basic data is OK
    	if (pObj == NULL)
    	    return FALSE;

		else if (pDataObject == NULL &&
 			!pObj->AttachClipboard())
			return FALSE;

		else if (format == 0 || pO == NULL)
			return FALSE;

		else if (!pObj->IsDataAvailable(format))
			return FALSE;

		FORMATETC fe;

		fe.cfFormat = format;
		fe.tymed    = TYMED_HGLOBAL;
		fe.lindex   = -1;
		fe.dwAspect = DVASPECT_CONTENT;
		fe.ptd      = NULL;

		// Fetch the data from the OLE data object
		HGLOBAL hMem = pObj->GetGlobalData(format,&fe);

		if (hMem == NULL)
			return FALSE;

	//	TRY
		{
			CMemFile mf((BYTE*)::GlobalLock(hMem), ::GlobalSize(hMem));

			CArchive ar(&mf, CArchive::load);
			pO->Serialize(ar); 
			 ar.Close();

			::GlobalUnlock(hMem);

			pObj->Release();

			if (pDataObject == NULL)
				delete pObj;

			return TRUE;
		}

	/*	CATCH_ALL(ce)
		{
			pObj->Release();

			if (pDataObject == NULL)
				delete pObj;

		return FALSE;
		}

		END_CATCH_ALL*/
	}

/*	catch(...)
	{
		CErrorDlg error;
		error.Error("Drag/drop error", "A serious error occured while dropping objects. Please report this to the Construct team.");
		return FALSE;
	}*/

	return TRUE;
}