void CGelView::OnEditCopy() { 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); CDC* pDC = GetDC(); double xpi = (double)pDC->GetDeviceCaps(HORZSIZE) / (double)pDC->GetDeviceCaps(HORZRES); double ypi = (double)pDC->GetDeviceCaps(VERTSIZE) / (double)pDC->GetDeviceCaps(VERTRES); double tXSize, tYSize; tXSize = GetGelSize().cx * xpi * 100.0; tYSize = GetGelSize().cy * ypi * 100.0; CRect rectView(0,0,(int)tXSize, (int)tYSize ); CMetaFileDC dcMeta; dcMeta.CreateEnhanced(pDC, NULL, rectView, "GeneDoc\0MetaFile\0\0" ); dcMeta.SetAttribDC( pDC->m_hAttribDC ); OnPrepareDC( &dcMeta ); DrawGel( &dcMeta, rectView ); HENHMETAFILE hMeta = dcMeta.CloseEnhanced(); if ( SetClipboardData(CF_ENHMETAFILE, hMeta) == NULL ) { AfxMessageBox( "Select Failed in SetClipBoardData", MB_OK | MB_ICONEXCLAMATION ); } // CBitmap // if ( !CloseClipboard() ) { AfxMessageBox( "CloseClipboard Failed", MB_OK | MB_ICONEXCLAMATION ); } ReleaseDC(pDC); // Moved this down here so nt4.0 would work. return; }
void CMyView::ResizeParentToFit(const SIZE& desired_size, BOOL bShrinkOnly) { // determine current size of the client area as if no scrollbars present CRect rectClient; GetWindowRect(rectClient); CRect rect = rectClient; CalcWindowRect(rect); rectClient.left += rectClient.left - rect.left; rectClient.top += rectClient.top - rect.top; rectClient.right -= rect.right - rectClient.right; rectClient.bottom -= rect.bottom - rectClient.bottom; rectClient.OffsetRect(-rectClient.left, -rectClient.top); ASSERT(rectClient.left == 0 && rectClient.top == 0); // determine desired size of the view CRect rectView(0, 0, desired_size.cx, desired_size.cy); if (bShrinkOnly) { if (rectClient.right <= desired_size.cx) rectView.right = rectClient.right; if (rectClient.bottom <= desired_size.cy) rectView.bottom = rectClient.bottom; } CalcWindowRect(rectView, CWnd::adjustOutside); rectView.OffsetRect(-rectView.left, -rectView.top); ASSERT(rectView.left == 0 && rectView.top == 0); if (bShrinkOnly) { if (rectClient.right <= desired_size.cx) rectView.right = rectClient.right; if (rectClient.bottom <= desired_size.cy) rectView.bottom = rectClient.bottom; } // dermine and set size of frame based on desired size of view CRect rectFrame; CFrameWnd* pFrame = GetParentFrame(); ASSERT_VALID(pFrame); pFrame->GetWindowRect(rectFrame); CSize size = rectFrame.Size(); size.cx += rectView.right - rectClient.right; size.cy += rectView.bottom - rectClient.bottom; pFrame->SetWindowPos(NULL, 0, 0, size.cx, size.cy, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE); }