Jump to content
  • Advertisement
Sign in to follow this  
link161

Having a problem in MFC

This topic is 2303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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:


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);
}


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:


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();
}
}


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

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!