A
A
Artyom2015-12-01 19:28:52
C++ / C#
Artyom, 2015-12-01 19:28:52

Handling events when the left mouse button is pressed?

Hello. There are png files that are uploaded to the window at certain coordinates. There are also lines.
bd9303b6683541e8a4d50b00c0bdf625.jpg
Question: How to make an event handler so that when you click on a certain hand image, the lines change color to the desired one.
view of my project.

void CRPSView::OnDraw(CDC* pDC)
    {
    	CRPSDoc* pDoc = GetDocument();
    	ASSERT_VALID(pDoc);
    	if (!pDoc)
    		return;
    
    	/*CBrush br;
    	CBrush* br_st;*/
    
    	CPen pen;
    	CPen* pen_st;
    
    	/*CFont font;
    	CFont* font_st;*/
    
    	CRect rect;
    	this->GetClientRect(&rect);
    	CImage C;
    	CDC mem;
    	CBitmap bm;
    	BITMAP bb;
    	mem.CreateCompatibleDC(pDC);
    
    
    	if (draw == 1)
    	{
    
    		C.Load(L"1.png");
    		bm.Attach(C);
    		mem.SelectObject(&bm);
    		bm.GetBitmap(&bb);
    		int q, e;
    		q = (rect.Width() - bb.bmWidth) / 4;//спок
    		e = (rect.Height() - bb.bmHeight)/2;
    		pDC->BitBlt(q, e, bb.bmWidth, bb.bmHeight, &mem, 0, 0, SRCCOPY);
    
    		C.Load(L"2.png");
    		bm.Attach(C);
    		mem.SelectObject(&bm);
    		bm.GetBitmap(&bb);
    		int x, y;
    		x = (rect.Width() - bb.bmWidth) / 2;//камень
    		y = (rect.Height() - bb.bmHeight) * 0;
    		pDC->BitBlt(x, y, bb.bmWidth, bb.bmHeight, &mem, 0, 0, SRCCOPY);
    
    		C.Load(L"3.png");
    		bm.Attach(C);
    		mem.SelectObject(&bm);
    		bm.GetBitmap(&bb);
    		int w, r;
    		w = (rect.Width() - bb.bmWidth) / 2.5;//ящерица
    		r = (rect.Height() - bb.bmHeight);
    		pDC->BitBlt(w, r, bb.bmWidth, bb.bmHeight, &mem, 0, 0, SRCCOPY);
    		
    		C.Load(L"4.png");
    		bm.Attach(C);
    		mem.SelectObject(&bm);
    		bm.GetBitmap(&bb);
    		int t, u;
    		t = (rect.Width() - bb.bmWidth)/1.3;//ножницы
    		u = (rect.Height() - bb.bmHeight)/2;
    		pDC->BitBlt(t, u, bb.bmWidth, bb.bmHeight, &mem, 0, 0, SRCCOPY);
    		
    		C.Load(L"5.png");
    		bm.Attach(C);
    		mem.SelectObject(&bm);
    		bm.GetBitmap(&bb);
    		int o, p;
    		o = (rect.Width() - bb.bmWidth) / 1.6;//бумага
    		p = (rect.Height() - bb.bmHeight);
    		pDC->BitBlt(o, p, bb.bmWidth, bb.bmHeight, &mem, 0, 0, SRCCOPY);
    
    		pen.CreatePen(PS_SOLID, 7, RGB(0, 0, 255));
    		pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 2.2, rect.bottom / 4);
    		pDC->LineTo(rect.right / 3.1, rect.bottom / 2.6);
    		pen.DeleteObject();
    
    		pen.CreatePen(PS_SOLID, 7, RGB(0, 0, 255));
    		pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 3.1, rect.bottom / 1.34);
    		pDC->LineTo(rect.right / 1.4, rect.bottom / 1.34);
    		pen.DeleteObject();
    
    		pen.CreatePen(PS_SOLID, 7, RGB(0, 0, 255));
    		pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 1.4, rect.bottom / 1.34);
    		pDC->LineTo(rect.right / 2, rect.bottom / 12);
    		pen.DeleteObject();
    
    		/*pen.CreatePen(PS_SOLID, 7, RGB(117, 187, 253));
    		pen_st = pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 2.6, rect.Height() / 10);
    		pDC->LineTo(rect.right / 1.4, rect.bottom / 2.1);
    		pen.DeleteObject();*/
    
    		/*pen.CreatePen(PS_SOLID, 7, RGB(117, 187, 253));
    		pen_st = pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 1.4, rect.bottom / 2.1);
    		pDC->LineTo(rect.right / 2.6, rect.bottom / 1.1);
    		pen.DeleteObject();
    
    		pen.CreatePen(PS_SOLID, 7, RGB(117, 187, 253));
    		pen_st = pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 2.6, rect.bottom / 1.1);
    		pDC->LineTo(rect.right / 2.6, rect.Height() / 10);
    		pen.DeleteObject();*/
    
    		/*pen.CreatePen(PS_SOLID, 7, RGB(216, 133, 25));
    		pen_st = pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 1.6, rect.Height() / 10);
    		pDC->LineTo(rect.right / 3.4, rect.bottom / 2.1);
    		pen.DeleteObject();*/
    
    		/*pen.CreatePen(PS_SOLID, 7, RGB(216, 133, 25));
    		pen_st = pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 3.4, rect.bottom / 2.1);
    		pDC->LineTo(rect.right / 1.6, rect.bottom / 1.1);
    		pen.DeleteObject();
    
    		pen.CreatePen(PS_SOLID, 7, RGB(216, 133, 25));
    		pen_st = pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 1.6, rect.bottom / 1.1);
    		pDC->LineTo(rect.right / 1.6, rect.Height() / 10);
    		pen.DeleteObject();
    
    		pen.CreatePen(PS_SOLID, 7, RGB(0, 100, 0));
    		pen_st = pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 3.2, rect.Height() / 4);
    		pDC->LineTo(rect.right / 1.4, rect.Height() / 4);
    		pen.DeleteObject();*/
    
    		pen.CreatePen(PS_SOLID, 7, RGB(0, 100, 0));
    		pen_st = pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 1.4, rect.Height() / 4);
    		pDC->LineTo(rect.right / 2, rect.bottom / 1.09);
    		pen.DeleteObject();
    
    		pen.CreatePen(PS_SOLID, 7, RGB(0, 100, 0));
    		pen_st = pDC->SelectObject(&pen);
    		pDC->MoveTo(rect.right / 2, rect.bottom / 1.09);
    		pDC->LineTo(rect.right / 3.2, rect.Height() / 4);
    		pen.DeleteObject();
    		
    	}
    	// TODO: добавьте здесь код отрисовки для собственных данных
    }

    ...
    
    void CRPSView::OnRps()
    {
    	draw = 1;
    	Invalidate();
    	// TODO: добавьте свой код обработчика команд
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alec Onim, 2015-12-02
@Caitiff_One

I would make a class for lines, with a drawing method and parameters - color and coordinates of the beginning and end :) and then you get the coordinates, respectively, determine which line you need to change and change its color: D draw in a cycle, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question