我在学习时想到一个问题解决不了  下面是.cpp文件的代码  如何实现画出来的椭圆和小圆能各自变色了  ,下面的代码只能实现小圆鼠标左击变色  鼠标左击椭圆不能变色
#include "stdafx.h"
#include "ex04a.h"#include "ex04aDoc.h"
#include "ex04aView.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CEx04aViewIMPLEMENT_DYNCREATE(CEx04aView, CView)BEGIN_MESSAGE_MAP(CEx04aView, CView)
//{{AFX_MSG_MAP(CEx04aView)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CEx04aView construction/destructionCEx04aView::CEx04aView():m_rectEllipse(0,0,100,100)
{
// TODO: add construction code here
    m_nColor = GRAY_BRUSH;
}CEx04aView::~CEx04aView()
{
}BOOL CEx04aView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}/////////////////////////////////////////////////////////////////////////////
// CEx04aView drawingvoid CEx04aView::OnDraw(CDC* pDC)
{
CEx04aDoc* pDoc = GetDocument();  // 这行与下面一行可以 注释掉 是因为此工程没涉及到文本 
ASSERT_VALID(pDoc);  
// TODO: add draw code for native data here
//画图要在 view 的onDraw函数里写代码,如接下来2行代码
pDC->SelectStockObject(m_nColor);
pDC->Ellipse(m_rectEllipse); CRect rectClient;
GetClientRect(rectClient); //取窗口物理尺寸(单位:像素) 
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(2000,2000);  //设定窗口尺寸,窗口尺寸以逻辑单位计算,窗口逻辑大小:1000*1000,
pDC->SetViewportExt(rectClient.right,-rectClient.bottom);//设定视口尺寸,视口尺寸以物理单位计算,改变Y坐标方向--viewport使用物理大小
pDC->SetViewportOrg(rectClient.right/2,rectClient.bottom/2);
pDC->Ellipse(CRect(0,0,500,500)); //以逻辑单位画图---普通GDI API使用逻辑单位
 
//下面只改了一些参数 效果一样.
/*CRect rectClient;
GetClientRect(rectClient); //取窗口物理尺寸(单位:像素) 
pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetWindowExt(1000,1000);  //设定窗口尺寸,窗口尺寸以逻辑单位计算,窗口逻辑大小:1000*1000,
pDC->SetViewportExt(rectClient.right,-rectClient.bottom);//设定视口尺寸,视口尺寸以物理单位计算,改变Y坐标方向--viewport使用物理大小
pDC->SetViewportOrg(rectClient.left,rectClient.bottom);
pDC->Ellipse(CRect(0,0,1000,1000)); //以逻辑单位画图---普通GDI API使用逻辑单位*/}/////////////////////////////////////////////////////////////////////////////
// CEx04aView printingBOOL CEx04aView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}void CEx04aView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}void CEx04aView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}/////////////////////////////////////////////////////////////////////////////
// CEx04aView diagnostics#ifdef _DEBUG
void CEx04aView::AssertValid() const
{
CView::AssertValid();
}void CEx04aView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CEx04aDoc* CEx04aView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx04aDoc)));
return (CEx04aDoc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CEx04aView message handlersvoid CEx04aView::OnLButtonDown(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
if(m_rectEllipse.PtInRect(point))
{
if(m_nColor == GRAY_BRUSH)
{
m_nColor=WHITE_BRUSH;
}
else
{
m_nColor=GRAY_BRUSH;
}
InvalidateRect(m_rectEllipse);
}
CView::OnLButtonDown(nFlags, point);
//最后一句不要删除
//CEx04aView类是从CView继承类,在CView的派生类CDrawDemoView中使用过(UINT nFlags, CPoint point)等参数后,
//系统要将他们返回会基类,如果你改变参数的内容基类将无法得到这些参数,
//对这个函数没影响是由于你没调用他的基类函数,如果你调用基类函数并且使用这两个返回的参数,就有可能错误。
//所以这个函数尽量不要改变参数的值,但是可以使用 
}