STDMETHODIMP DropTarget_Drop(DropTarget *dt, IDataObject *ido, DWORD keyState, POINTL pt, DWORD *effect) { STGMEDIUM medium; FORMATETC fmtetc; HRESULT hRes; freeDropFiles(); DPRINTF(("DropTarget_Drop\n")); fmtetc.cfFormat = CF_HDROP; fmtetc.ptd = NULL; fmtetc.lindex = -1; fmtetc.dwAspect = DVASPECT_CONTENT; fmtetc.tymed = TYMED_HGLOBAL; DPRINTF(("Looking for file...\n")); hRes = ido->lpVtbl->GetData(ido, &fmtetc, &medium); if(hRes == S_OK) { HGLOBAL hDrop = medium.hGlobal; DWORD i; DPRINTF(("Success\n")); numDropFiles = DragQueryFile(hDrop, -1, NULL, 0); dropFiles = calloc(numDropFiles, sizeof(char*)); for(i=0; i<numDropFiles; i++) { WCHAR *tmpPath; int len; len = DragQueryFileW(hDrop, i, NULL, 0); tmpPath = calloc(len+1, sizeof(WCHAR)); DragQueryFileW(hDrop, i, tmpPath, len+1); len = WideCharToMultiByte(CP_UTF8, 0, tmpPath, -1, NULL, 0,NULL,NULL); dropFiles[i] = malloc(len); WideCharToMultiByte(CP_UTF8,0,tmpPath,-1,dropFiles[i],len,NULL,NULL); free(tmpPath); DPRINTF(("File: %s\n", dropFiles[i])); } DragFinish(hDrop); signalDrop(pt); if(medium.pUnkForRelease == NULL) { GlobalFree(hDrop); } else { medium.pUnkForRelease->lpVtbl->Release(medium.pUnkForRelease); } return S_OK; } if(FAILED(hRes)) { DPRINTF(("GetData failed (errCode = %x)\n", hRes)); } fmtetc.cfFormat = CF_DIB; fmtetc.ptd = NULL; fmtetc.lindex = -1; fmtetc.dwAspect = DVASPECT_CONTENT; fmtetc.tymed = TYMED_HGLOBAL; DPRINTF(("Looking for HDIB...\n")); hRes = ido->lpVtbl->GetData(ido, &fmtetc, &medium); if(hRes == S_OK) { TCHAR tmpName[MAX_PATH+1]; HANDLE hDib = medium.hGlobal; DPRINTF(("Success\n")); GetTempPath(MAX_PATH,tmpName); strcat(tmpName,"$$squeak$$.bmp"); if(WriteDIB(tmpName, hDib)) { numDropFiles = 1; dropFiles = calloc(1, sizeof(void*)); dropFiles[0] = _strdup(tmpName); } if(medium.pUnkForRelease == NULL) { GlobalFree(hDib); } else { medium.pUnkForRelease->lpVtbl->Release(medium.pUnkForRelease); } signalDrop(pt); return S_OK; } if(FAILED(hRes)) { DPRINTF(("GetData failed (errCode = %x)\n", hRes)); } fmtetc.cfFormat = CF_BITMAP; fmtetc.ptd = NULL; fmtetc.lindex = -1; fmtetc.dwAspect = DVASPECT_CONTENT; fmtetc.tymed = TYMED_HGLOBAL; DPRINTF(("Looking for bitmap...\n")); hRes = ido->lpVtbl->GetData(ido, &fmtetc, &medium); if(hRes == S_OK) { TCHAR tmpName[MAX_PATH+1]; HANDLE hDib; HBITMAP hBM = medium.hBitmap; DPRINTF(("Success\n")); GetTempPath(MAX_PATH,tmpName); strcat(tmpName,"$$squeak$$.bmp"); hDib = DibFromBitmap(hBM, BI_RGB, 0, NULL); if(hDib) { if(WriteDIB(tmpName, hDib)) { numDropFiles = 1; dropFiles = calloc(1, sizeof(void*)); dropFiles[0] = _strdup(tmpName); } DeleteObject(hDib); } if(medium.pUnkForRelease == NULL) { DeleteObject(hBM); } else { medium.pUnkForRelease->lpVtbl->Release(medium.pUnkForRelease); } signalDrop(pt); return S_OK; } if(FAILED(hRes)) { DPRINTF(("GetData failed (errCode = %x)\n", hRes)); } fmtetc.cfFormat = CF_ENHMETAFILE; fmtetc.ptd = NULL; fmtetc.lindex = -1; fmtetc.dwAspect = DVASPECT_CONTENT; fmtetc.tymed = TYMED_ENHMF; DPRINTF(("Looking for ENHMF...\n")); hRes = ido->lpVtbl->GetData(ido, &fmtetc, &medium); if(hRes == S_OK) { TCHAR tmpName[MAX_PATH+1]; HANDLE hMF = medium.hGlobal; HANDLE hDib; BITMAPINFO bmi; ENHMETAHEADER header; DPRINTF(("Success\n")); if(GetEnhMetaFileHeader(hMF, sizeof(header), &header) == 0) { DPRINTF(("GetEnhMetaFileHeader failed\n")); } bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 24; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biWidth = header.rclBounds.right - header.rclBounds.left; bmi.bmiHeader.biHeight = header.rclBounds.bottom - header.rclBounds.top; DPRINTF(("w=%d\nh=%d\n", bmi.bmiHeader.biWidth, bmi.bmiHeader.biHeight)); { HDC hDC, mDC; HANDLE old, hBM; RECT rect; hDC = GetDC(stWindow); if(!hDC) DPRINTF(("GetDC() failed\n")); // hDib = CreateDIBitmap(hDC, &bmi, 0, NULL, &bmi, DIB_RGB_COLORS); hBM = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, NULL, NULL, 0); if(!hBM) DPRINTF(("CreateDIBSection() failed\n")); mDC = CreateCompatibleDC(hDC); if(!mDC) DPRINTF(("CreateCompatibleDC() failed\n")); old = SelectObject(mDC, hBM); rect.left = rect.top = 0; rect.right = bmi.bmiHeader.biWidth; rect.bottom = bmi.bmiHeader.biHeight; if(!PlayEnhMetaFile(mDC, hMF, &rect)) DPRINTF(("PlayEnhMetaFile() failed\n")); SelectObject(mDC, old); DeleteDC(mDC); ReleaseDC(stWindow, hDC); hDib = DibFromBitmap(hBM, BI_RGB, 0, NULL); DeleteObject(hBM); } GetTempPath(MAX_PATH,tmpName); strcat(tmpName,"$$squeak$$.bmp"); if(WriteDIB(tmpName, hDib)) { numDropFiles = 1; dropFiles = calloc(1, sizeof(void*)); dropFiles[0] = _strdup(tmpName); } GlobalFree(hDib); if(medium.pUnkForRelease == NULL) { DeleteObject(hMF); } else { medium.pUnkForRelease->lpVtbl->Release(medium.pUnkForRelease); } signalDrop(pt); return S_OK; } if(FAILED(hRes)) { DPRINTF(("GetData failed (errCode = %x)\n", hRes)); } return S_OK; }
void CPhylogenView::ClipFunction() { if ( !OpenClipboard() ) { AfxMessageBox("Cannot Open Clipboard", MB_OK | MB_ICONEXCLAMATION); return; } if ( !EmptyClipboard() ) { AfxMessageBox("Cannot Empty Clipboard", MB_OK | MB_ICONEXCLAMATION); return; } CGenedocDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->BeginWaitCursor(); // Let em know // Size of Bitmap CBitmap CopyBmp; CDC * pDC = GetDC(); CDC cDC; if ( ! cDC.CreateCompatibleDC( pDC ) ) { AfxMessageBox( "Create CompatibleDC fails", MB_OK | MB_ICONEXCLAMATION ); CloseClipboard(); ReleaseDC(pDC); pDoc->EndWaitCursor(); // Let em know return; } if ( !CopyBmp.CreateCompatibleBitmap( pDC, m_MaxScrolls.cx, m_MaxScrolls.cy ) ) { AfxMessageBox( "CreateBitmap fails", MB_OK | MB_ICONEXCLAMATION ); CloseClipboard(); ReleaseDC(pDC); pDoc->EndWaitCursor(); // Let em know return; } CBitmap* oBmp = cDC.SelectObject ( &CopyBmp ); if ( oBmp == NULL ) { AfxMessageBox ( "Cannot Select Bitmap", MB_OK | MB_ICONEXCLAMATION ); CloseClipboard(); ReleaseDC(pDC); pDoc->EndWaitCursor(); // Let em know return; } // Clear out the new bitmap if ( !cDC.BitBlt( 0, 0, m_MaxScrolls.cx, m_MaxScrolls.cy, NULL, 0, 0, WHITENESS ) ) { AfxMessageBox ( "Error in BitBlt WHITENESS", MB_OK | MB_ICONEXCLAMATION ); CloseClipboard(); ReleaseDC(pDC); pDoc->EndWaitCursor(); // Let em know return; } // TODO: add draw code for native data here if ( pDoc->m_pPGBase != NULL ) { CSize TextSize; if ( pDoc->m_UserVars.m_DispTreeWeight ) { TextSize = pDC->GetTextExtent( "0000", 4 ); } else { TextSize = pDC->GetTextExtent( "00", 2 ); } m_CharWidth = TextSize.cx; m_CharHeight = TextSize.cy; // CSize WinSize = GetTotalSize(); m_DrawpDC = &cDC; m_NumRows = 0; m_CallBackSwitch = CB_DRAWROWS; pDoc->m_pPGBase->CallFromSeq( this ); } ReleaseDC(pDC); cDC.SelectObject(oBmp); // extern HANDLE DibFromBitmap ( HBITMAP hbm, DWORD biStyle, WORD biBits, HPALETTE hpal); HANDLE hdib = DibFromBitmap ( (HBITMAP)CopyBmp.m_hObject, BI_RGB, 1, NULL ); if ( hdib != NULL ) { if ( SetClipboardData(CF_DIB, hdib) == NULL ) { AfxMessageBox( "Select Failed in SetClipBoardData", MB_OK | MB_ICONEXCLAMATION ); } } else { AfxMessageBox( "Convert to DIB Failed" ); } // if ( !CloseClipboard() ) { AfxMessageBox( "CloseClipboard Failed", MB_OK | MB_ICONEXCLAMATION ); } pDoc->EndWaitCursor(); // Let em know return; }