////////////////////////////////////////////////////////////////////////////// // CDemoView drawing void CDemoView::OnDraw(CDC* pDC) { CDemoDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); BOOL bPrinting = pDC->IsPrinting(); CMemDC* pMemDC = NULL; if (!bPrinting) pDC = pMemDC = new CMemDC(pDC); if (!bPrinting && m_brHatch.m_hObject){ CRect rect; GetClientRect(&rect); rect.right = max(rect.right , m_totalDev.cx); rect.bottom = max(rect.bottom, m_totalDev.cy); m_brHatch.UnrealizeObject(); CPoint pt(0, 0); pDC->LPtoDP(&pt); pt = pDC->SetBrushOrg(pt.x % 8, pt.y % 8); CBrush* old = pDC->SelectObject(&m_brHatch); pDC->FillRect(&rect, &m_brHatch); pDC->SelectObject(old); } CxImage* ima = pDoc->GetImage(); if (ima) { if (bPrinting) { // get size of printer page (in pixels) int cxPage = pDC->GetDeviceCaps(HORZRES); int cyPage = pDC->GetDeviceCaps(VERTRES); //int dcbpp = pDC->GetDeviceCaps(BITSPIXEL); //int dcnc = pDC->GetDeviceCaps(NUMCOLORS); //int dcp = pDC->GetDeviceCaps(PLANES); // get printer pixels per inch int cxInch = pDC->GetDeviceCaps(LOGPIXELSX); int cyInch = pDC->GetDeviceCaps(LOGPIXELSY); // Best Fit case: create a rectangle which preserves the aspect ratio int cx = ima->GetXDPI() ? (ima->GetWidth()*cxInch)/ima->GetXDPI():ima->GetWidth()*cxInch/96; int cy = ima->GetYDPI() ? (ima->GetHeight()*cyInch)/ima->GetYDPI():ima->GetHeight()*cyInch/96; // print it! /*HDC TmpDC=CreateCompatibleDC(pDC->GetSafeHdc()); HBITMAP bm =::CreateCompatibleBitmap(pDC->GetSafeHdc(), cx, cy); HBITMAP oldbm = (HBITMAP)::SelectObject(TmpDC,bm); BitBlt(TmpDC,0,0,cx,cy,0,0,0,WHITENESS); ima->Draw(TmpDC,CRect(0,0,cx,cy)); BitBlt(pDC->GetSafeHdc(),100,100,cx,cy,TmpDC,0,0,SRCCOPY); DeleteObject(SelectObject(TmpDC,oldbm)); DeleteDC(TmpDC);*/ CxImage tmp; tmp.Copy(*ima); RGBQUAD c={255,255,255,0}; if (tmp.GetTransIndex()>=0) tmp.SetPaletteColor((BYTE)tmp.GetTransIndex(),c); tmp.SetTransColor(c); tmp.AlphaStrip(); tmp.Stretch(pDC->GetSafeHdc(), CRect(100,100,cx,cy)); } else { if (pDoc->GetStretchMode()) { CRect rect; GetClientRect(&rect); ima->Draw(pDC->GetSafeHdc(), rect,0,pDoc->GetSmoothMode()!=0); } else { float zoom=pDoc->GetZoomFactor(); if (zoom==1) ima->Draw(pDC->GetSafeHdc()); else ima->Draw(pDC->GetSafeHdc(), CRect(0,0,(int)(ima->GetWidth()*zoom),(int)(ima->GetHeight()*zoom)), 0,pDoc->GetSmoothMode()!=0); } if ( m_tracker.m_rect.Width()>0 && m_tracker.m_rect.Height()>0 ) m_tracker.Draw(pDC); } } delete pMemDC; }
void CDemoView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { switch (lHint) { case WM_USER_NEWIMAGE: { m_tracker.m_rect = CRect(0,0,0,0); CDemoDoc* pDoc = GetDocument(); CxImage* ima = pDoc->GetImage(); if (ima) { int px=GetScrollPos(SB_HORZ); int py=GetScrollPos(SB_VERT); CSize sz(GetTotalSize()); int x=(int)(ima->GetWidth()*pDoc->GetZoomFactor()); int y=(int)(ima->GetHeight()*pDoc->GetZoomFactor()); SetScrollSizes(MM_TEXT, CSize(x,y)); CSize sz2(GetTotalSize()); CWnd* pFrame=GetParentFrame(); RECT rClient; pFrame->GetClientRect(&rClient); if (sz.cx!=0 && sz.cy!=0){ if (x>rClient.right) SetScrollPos(SB_HORZ,sz2.cx*px/sz.cx); else SetScrollPos(SB_HORZ,0); if (y>rClient.bottom) SetScrollPos(SB_VERT,sz2.cy*py/sz.cy); else SetScrollPos(SB_VERT,0); } if (!(pFrame->IsIconic()||pFrame->IsZoomed())){ RECT rMainCl,rFrame,rMainFr; ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetClientRect(&rMainCl); ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetWindowRect(&rMainFr); pFrame->GetWindowRect(&rFrame); pFrame->SetWindowPos(0,0,0, (4+rFrame.right-rFrame.left-rClient.right+rClient.left)+ min(rMainCl.right-(rFrame.left-rMainFr.left+12),x), (4+rFrame.bottom-rFrame.top-rClient.bottom+rClient.top)+ min(rMainCl.bottom-(rFrame.top-rMainFr.top+12),y), SWP_NOMOVE|SWP_NOZORDER); //ResizeParentToFit(1); } if (!ima->SelectionIsValid()) KillTimer(1); #ifdef VATI_EXTENSIONS ima->SetJpegQualityF(theApp.m_optJpegQuality); #if CXIMAGE_SUPPORT_JPG ima->SetCodecOption(theApp.m_optJpegOptions,CXIMAGE_FORMAT_JPG); #endif #if CXIMAGE_SUPPORT_RAW ima->SetCodecOption(theApp.m_optRawOptions,CXIMAGE_FORMAT_RAW); #endif #endif CMainFrame* pMain = (CMainFrame*) AfxGetMainWnd(); if (pMain->m_HistoBar.IsWindowVisible()){ pDoc->m_hmax=ima->Histogram(pDoc->m_hr,pDoc->m_hg,pDoc->m_hb,pDoc->m_hgray); pMain->m_HistoBar.Invalidate(); } else { pDoc->m_hmax = 0; } } break; } default: { CDemoDoc* pDoc = GetDocument(); if (pDoc){ CxImage* ima = pDoc->GetImage(); if (ima){ if (pDoc->GetStretchMode()) SetScrollSizes(MM_TEXT, CSize(0,0)); else SetScrollSizes(MM_TEXT,CSize((int)(ima->GetWidth()*pDoc->GetZoomFactor()), (int)(ima->GetHeight()*pDoc->GetZoomFactor()))); } } } } CScrollView::OnUpdate(pSender, lHint, pHint); }