RECT auf dem CDC als Objekt fassen!?

Cappaja

Erfahrenes Mitglied
hallo,

ich habe ein koordinatensystem in welches signale gezeichnet werden. mit einem linksklick setze ich einen cursor an die CPoint.x koordinate. an derselben x-koordinate zeichne ich am ende des cursors ein dreieck (ausserhalb des koordinatensystems). dieses möchte ich jetzt gerne mit einem linksklick und gedrückter maustaste in x-richtung verschieben können.

bislang habe ich die drei systemmessages für lbuttondown, mousemove und lbuttonup wie folgt implementiert. m_rectClient ist dabei ein 20x20 px großer bereich welcher mein dreieck zum schieben bereitstellen soll. InpRect stellt das Koordinatensystem dar.

mein problem findest sich in OnMouseMove() wieder, hier muss ich es irgendwie anstellen die ausgewählte region des dreiecks als objekt zu fassen und zu verschieben, wie mache ich das?

C++:
void CWiwoDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	m_rectClient.left   = point.x-10;
	m_rectClient.right  = point.x+10;
	m_rectClient.bottom = InpRect.top;
	m_rectClient.top    = InpRect.top-20;

	CRgn rgnRect;
	CRect r = m_rectClient;
	int nX = point.x;

	VERIFY(rgnRect.CreateRectRgnIndirect(&r));

	if(rgnRect.PtInRegion(point))
	{
		TRACE("\nregion for cursor move!");
		SetCapture();
		m_bCatched = TRUE;
		::SetCursor(::LoadCursor(NULL, IDC_HAND));
		rgnRect.Detach();
	}

	Invalidate();
	
	CDialog::OnLButtonDown(nFlags, point);
}

C++:
void CWiwoDlg::OnMouseMove(UINT nFlags, CPoint point) 
{	
	if(m_bCatched)
	{
		CClientDC DC(this);
		DC.SetMapMode(MM_ISOTROPIC);
		DC.SetWindowExt(20, 20);
	}
	
	CDialog::OnMouseMove(nFlags, point);
}

C++:
void CWiwoDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	if(m_bCatched)
	{
		ReleaseCapture();
		m_bCatched = FALSE;
	}
	
	CDialog::OnLButtonUp(nFlags, point);
}
 
Zuletzt bearbeitet:
da es irgendwie nicht klappte habe ich zu anderen (wohl umständlicheren) mitteln gegriffen. ich stelle die meine lösung dennoch mal hinein. während dem schieben lasse ich das neuzeichnen weg, was das einzige an dieser stelle allerdings unwichtige manko ist. ansonsten funktioniert es wunderbar. hier noch der code:

C++:
void CWiwoDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// if cursor has moved -> commit new x-pos
	if(m_bNewCursorPos)
	{
		m_savePlaceHolder1.right = m_ptMousePos.x+1;
		m_savePlaceHolder1.left  = m_ptMousePos.x;
		m_bNewCursorPos = FALSE;
	}

	if(m_bNewCursorPos2)
	{
		m_savePlaceHolder2.right = m_ptMousePos2.x+1;
		m_savePlaceHolder2.left  = m_ptMousePos2.x;
		m_bNewCursorPos2 = FALSE;
	}

	// guilty region for cursor1
	m_rectClient.left   = m_savePlaceHolder1.left-7;
	m_rectClient.right  = m_savePlaceHolder1.right+8;
	m_rectClient.bottom = m_savePlaceHolder1.top;
	m_rectClient.top    = m_savePlaceHolder1.top-10;

	// guilty region for cursor2
	m_rectClient2.left   = m_savePlaceHolder2.left-7;
	m_rectClient2.right  = m_savePlaceHolder2.right+8;
	m_rectClient2.bottom = m_savePlaceHolder2.top;
	m_rectClient2.top    = m_savePlaceHolder2.top-10;

	// is the point in guilty region?
	m_bC1InRegion = CheckRect(point, m_rectClient);
	m_bC2InRegion = CheckRect(point, m_rectClient2);

	if(m_bC1InRegion)
	{
		TRACE("\nregion for cursor1 move!");
		SetCapture();
		m_bCatched = TRUE;
		::SetCursor(::LoadCursor(NULL, IDC_HAND));
	}

	if(m_bC2InRegion)
	{
		TRACE("\nregion for cursor2 move!");
		SetCapture();
		m_bCatched2 = TRUE;
		::SetCursor(::LoadCursor(NULL, IDC_HAND));
	}
	
	CDialog::OnLButtonDown(nFlags, point);
}

C++:
void CWiwoDlg::OnMouseMove(UINT nFlags, CPoint point) 
{	
	if(m_bCatched)
	{
		m_pGraph->m_arrayX[0] = point.x;
		m_pGraph->DrawVCursor(m_pGraph->m_arrayX);	
	}

	if(m_bCatched2)
	{
		m_pGraph->m_arrayX[1] = point.x;
		m_pGraph->DrawVCursor(m_pGraph->m_arrayX);	
	}
	
	CDialog::OnMouseMove(nFlags, point);
}

C++:
void CWiwoDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	if(m_bCatched)
	{
		// this move is guilty!
		if(InpRect.left <= point.x && InpRect.right >= point.x)
		{
			m_ptMousePos = point;
		}
		// this move was below the left limit!
		else if(InpRect.left > point.x)
		{
			m_ptMousePos.x = InpRect.left;
			m_pGraph->m_arrayX[0] = m_ptMousePos.x;
			m_pGraph->DrawVCursor(m_pGraph->m_arrayX);
		}
		// this move was above the right limit!
		else if(InpRect.right < point.x)
		{
			m_ptMousePos.x = InpRect.right;
			m_pGraph->m_arrayX[0] = m_ptMousePos.x;
			m_pGraph->DrawVCursor(m_pGraph->m_arrayX);
		}

		ReleaseCapture();
		m_bCatched = FALSE;
		m_bNewCursorPos = TRUE;
		m_pGraph->PaintGraph();
	}

	if(m_bCatched2)
	{
		// this move is guilty!
		if(InpRect.left <= point.x && InpRect.right >= point.x)
		{
			m_ptMousePos2 = point;
		}
		// this move was below the left limit!
		else if(InpRect.left > point.x)
		{
			m_ptMousePos2.x = InpRect.left;
			m_pGraph->m_arrayX[1] = m_ptMousePos2.x;
			m_pGraph->DrawVCursor(m_pGraph->m_arrayX);
		}
		// this move was above the right limit!
		else if(InpRect.right < point.x)
		{
			m_ptMousePos2.x = InpRect.right;
			m_pGraph->m_arrayX[1] = m_ptMousePos2.x;
			m_pGraph->DrawVCursor(m_pGraph->m_arrayX);
		}

		ReleaseCapture();
		m_bCatched2 = FALSE;
		m_bNewCursorPos2 = TRUE;
		m_pGraph->PaintGraph();
	}
	
	CDialog::OnLButtonUp(nFlags, point);
}

da ich 2 cursor verwende habe ich hier den doppelten aufwand. jedoch kann man das ganze noch in eine funktion mit mehreren übergabeparametern packen und schon hätte man nur noch halb soviel code, aber für heute habe ich echt genug :D

mfg cappaja
 

Neue Beiträge

Zurück