Click here to Skip to main content
15,920,828 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: LNK2001 error question Pin
Nibu babu thomas6-Aug-08 20:48
Nibu babu thomas6-Aug-08 20:48 
QuestionAccessing microsoft index service with ADO Pin
tustin6-Aug-08 14:09
tustin6-Aug-08 14:09 
QuestionLPITEMIDLIST Pin
Bram van Kampen6-Aug-08 13:17
Bram van Kampen6-Aug-08 13:17 
AnswerRe: LPITEMIDLIST Pin
Stephen Hewitt6-Aug-08 14:04
Stephen Hewitt6-Aug-08 14:04 
GeneralRe: LPITEMIDLIST Pin
Bram van Kampen6-Aug-08 15:25
Bram van Kampen6-Aug-08 15:25 
QuestionRe: LPITEMIDLIST Pin
David Crow7-Aug-08 3:35
David Crow7-Aug-08 3:35 
QuestionRe: LPITEMIDLIST Pin
Bram van Kampen7-Aug-08 8:19
Bram van Kampen7-Aug-08 8:19 
QuestionScrolling won't work when zooming in CScrollView [modified] Pin
ccaprani6-Aug-08 12:49
ccaprani6-Aug-08 12:49 
I've been two days at this problem and can't figure it out - I'd really appreciate your advice and time to help me Smile | :)

The problem is this:

My application draws a road and shows vehicles moving on it. When scrolled right and I zoom in, the scrollbars move to the left, back towards the origin. Conversly, when I zoom out they scroll to the right. As you can see from the code below I have tried adjusting for the viewport origin, but still no luck.

Some more information:

My logical coords have their origin at the start and centre of the road. I therefore set my viewport origin at (left border, Rect.Height()/2). To scale I use a scale factor times my draw area. I am not using CZoomView[^] because I need the above special considerations.

Here is the code I have:

void CTrafficView::OnPrepareDC(CDC *pDC, CPrintInfo *pInfo)
{
	CScrollView::OnPrepareDC(pDC, pInfo);

	pDC->SetMapMode(MM_ANISOTROPIC);	// for scaling
	pDC->SetWindowExt(m_DrawArea);		// in logical units

	int xExtent = m_Scale * m_DrawArea.cx;
	int yExtent = m_Scale * m_DrawArea.cy;
	pDC->SetViewportExt(xExtent, yExtent);

	// keep the road divider in the centre of screen
	// by moving the viewport origin
	GetClientRect(&m_ClientRect);	// the height of the window
	CPoint viewOrg;
	viewOrg.y = m_ClientRect.Height()/2;	// - yExtent/2;
	viewOrg.x = m_Border_Lhs*m_Scale;

	viewOrg -= GetDeviceScrollPosition();	// so scrolling accounted for
	pDC->SetViewportOrg(viewOrg);
}

void CTrafficView::ResetScrollBars()
{
	// set up device context and new scroll sizes
	CClientDC aDC(this);
	OnPrepareDC(&aDC);
	CSize temp = m_DrawArea;	// since we don't want drawArea changed
	aDC.LPtoDP(&temp);
	SetScrollSizes(MM_TEXT, temp);
}

void CTrafficView::OnToolsZoomin() 
{
	// move scrolls bars to centre of logical view
	CPoint pt;
	GetClientRect(&m_ClientRect);
        pt.x = (m_ClientRect.Width()  / 2);
        pt.y = (m_ClientRect.Height() / 2);
	
	CClientDC aDC(this);
	OnPrepareDC(&aDC);
	CPoint vp = aDC.GetViewportOrg();

	pt = pt - vp;	// adjust device point to viewport point

	CScrollView::ScrollToPosition(pt);	// scroll to viewport point

	m_Scale += 0.2;				// MAGIC NUMBER - should it be an option?
	ResetScrollBars();
	
	Invalidate();	// draw it
}

Thanks so much for any help you can give - I have to present my program at a meeting with the client tomorrow Frown | :(

modified on Thursday, August 7, 2008 7:26 AM

Questionvc++ 6 mfc, dialog with child, messed up Pin
rolfhorror6-Aug-08 7:59
rolfhorror6-Aug-08 7:59 
QuestionRe: vc++ 6 mfc, dialog with child, messed up Pin
Mark Salsbery6-Aug-08 9:18
Mark Salsbery6-Aug-08 9:18 
AnswerRe: vc++ 6 mfc, dialog with child, messed up [modified] Pin
rolfhorror6-Aug-08 10:04
rolfhorror6-Aug-08 10:04 
GeneralRe: vc++ 6 mfc, dialog with child, messed up Pin
Mark Salsbery7-Aug-08 4:45
Mark Salsbery7-Aug-08 4:45 
GeneralRe: vc++ 6 mfc, dialog with child, messed up Pin
rolfhorror7-Aug-08 8:18
rolfhorror7-Aug-08 8:18 
QuestionRe: vc++ 6 mfc, dialog with child, messed up Pin
David Crow7-Aug-08 3:38
David Crow7-Aug-08 3:38 
Question2005 C++ Resource editor replaces #defs with strings Pin
anand91966-Aug-08 7:24
anand91966-Aug-08 7:24 
AnswerRe: 2005 C++ Resource editor replaces #defs with strings Pin
Joe Woodbury6-Aug-08 10:43
professionalJoe Woodbury6-Aug-08 10:43 
QuestionOpenGL and HW acceleration [modified] Pin
Dave Calkins6-Aug-08 3:45
Dave Calkins6-Aug-08 3:45 
QuestionError message observed while using Standard User Analyzer Pin
V K 26-Aug-08 2:18
V K 26-Aug-08 2:18 
Questionnewbie C question Pin
johnny alpaca6-Aug-08 2:12
johnny alpaca6-Aug-08 2:12 
AnswerRe: newbie C question Pin
toxcct6-Aug-08 2:32
toxcct6-Aug-08 2:32 
GeneralRe: newbie C question Pin
_AnsHUMAN_ 6-Aug-08 2:36
_AnsHUMAN_ 6-Aug-08 2:36 
GeneralRe: newbie C question Pin
toxcct6-Aug-08 2:38
toxcct6-Aug-08 2:38 
GeneralRe: newbie C question Pin
johnny alpaca6-Aug-08 2:39
johnny alpaca6-Aug-08 2:39 
GeneralRe: newbie C question Pin
Kwanalouie6-Aug-08 2:55
Kwanalouie6-Aug-08 2:55 
GeneralRe: newbie C question Pin
Maximilien6-Aug-08 2:58
Maximilien6-Aug-08 2:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.