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); } } }
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); } } }