Sign in to follow this  
link161

Having a problem in MFC

Recommended Posts

Hello,
I'm having a problem getting some code to run properly here, The basis is I have an ellipse, I need to have it so when you left click it, it changes color. I have the OnLButtonDown handler set up but I'm not getting any results. Any one think they could take a look? here is the handler code:

[CODE]
void CAssignment3Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{

CClientDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.SetMapMode(MM_ANISOTROPIC);
dc.SetWindowExt(100,100);
dc.SetViewportExt(rect.Width(),rect.Height());

CRect ellBound(ellLeft,ellSize);
CRgn ellCircle;
dc.LPtoDP(ellBound);
ellCircle.CreateEllipticRgnIndirect(ellBound);
if(ellCircle.PtInRegion(point))
{
if(!mCapture)
{
SetCapture();
mCapture = true;
}
EllipseCl = RGB(0,0,255);
CBrush bEll(HS_CROSS, EllipseCl);
dc.SelectObject(bEll);
InvalidateRect(ellBound,FALSE);
}

CDialogEx::OnLButtonDown(nFlags, point);
}
[/CODE]

ellLeft is a pont set the the top left of the ellipse rect, and ellSize is a CSize set to the width and height.

here is my on paint function if you need:

[CODE]
void CAssignment3Dlg::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);

dc.SetMapMode(MM_ANISOTROPIC);
dc.SetWindowExt(100,100);
dc.SetViewportExt(rect.Width (), rect.Height ());
CPen Pen(PS_DASH,1,RGB(0,0,0));
dc.SelectObject(Pen);
dc.Rectangle(80,40,90,55);
CBrush bBrush(RGB(0,0,0));
dc.SelectObject(bBrush);
dc.Rectangle(45,20,60,80);
CBrush rCrossBrush(HS_CROSS, RGB(255,0,0));
dc.SelectObject(rCrossBrush);
dc.Ellipse(10,10,20,20);
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialogEx::OnPaint();
}
}
[/CODE]

Just a nudge in the right direction would be greatly appriciated!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this