Bonjour,

Je réalise une petite application MDI pour visualiser des images. J'ai implemeté un facteur d'echelle permettant le zoom de l'image grace à la mollette de la souris. grâce au code suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 
void CView::OnEditionZoomPlus(){
	m_Scale += 0.10;
	InvalidateRect(0);
}
 
void CView::OnDraw(CDC* pDC)
{
	CDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	CRect aRect;
	GetClientRect(aRect);
	pDoc->myImage.displayImage( aRect,pDC);
}
 
void CView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{	
	CScrollView::OnPrepareDC(pDC, pInfo);
	CFusionDoc* pDoc = GetDocument();
	pDC->SetMapMode(MM_ANISOTROPIC);
	int ord = -pDoc->GetDocumentHeight();	
 
	int xLogPixels = pDC->GetDeviceCaps(LOGPIXELSX);
	int yLogPixels = pDC->GetDeviceCaps(LOGPIXELSY);
	int xExtent	   = pDoc->GetDocumentWidth()   * m_Scale  * xLogPixels / 100;
	int yExtent    = ord * m_Scale  * yLogPixels / 100;
 
	pDC->SetWindowExt(pDoc->GetDocumentWidth(), ord);
	pDC->SetViewportExt(xExtent, yExtent);
}
Cela fonctionne bien seulement quand j'affiche l'image, la vue est bcp plus grande que l'image et il apparait un fond blanc. J'aimerai pouvoir redimensionner ma vue à la taille de l'image. Pour cela j'ai utilisé ResizeParentToFit() de cette manière :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
void CView::OnDraw(CDC* pDC)
{
	CDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
 
	CRect aParentRect;
	CRect aDestRect(pDC->GetViewportOrg(),pDC->GetViewportExt());
	pDoc->myImage.displayImage( aDestRect,pDC);
 
	CApp* app = (CApp*)AfxGetApp();
	app->GetMainWnd()->GetClientRect(aParentRect);
	if( ((-aParentRect.bottom) > anotherRect.bottom) || (aParentRect.right < anotherRect.right) ){
		ResizeParentToFit(TRUE);
	}
	else{
		ResizeParentToFit(FALSE);
	}
}
mais cela ne fonctionne pas bien. En effet, la vue se redimensionne mais ) la taille de l'image mais le defilement avec les barres saccade et les barres n'apparaissent pas qd je le souhaite.

Qqun a-t-il une solution?