我想用在点击鼠标后获得鼠标的坐标,然后再根据相应的坐标位置,使相应的棋子移动。但总是出现问题,希望高人们看看。// 3_1View.cpp : implementation of the CMy3_1View class
//
 
#include "stdafx.h"
#include "3_1.h" 
#include "3_1Doc.h"
#include "3_1View.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif 
/////////////////////////////////////////////////////////////////////////////
// CMy3_1ViewIMPLEMENT_DYNCREATE(CMy3_1View, CView)BEGIN_MESSAGE_MAP(CMy3_1View, CView)
//{{AFX_MSG_MAP(CMy3_1View)
ON_WM_LBUTTONUP()
ON_WM_SETCURSOR()
ON_COMMAND(ID_START, OnStart)
ON_COMMAND(ID_PLAYER, OnPlayer)
ON_COMMAND(ID_CPMPUTER, OnCpmputer)
//}}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()/////////////////////////////////////////////////////////////////////////////
// CMy3_1View construction/destruction
int wpx1=30,wpy1=35;
int wpx2=130,wpy2=35;
int wpx3=230,wpy3=35;
int wpx4=330,wpy4=35; int bpx1=330,bpy1=335;
int bpx2=230,bpy2=335;
int bpx3=130,bpy3=335;
int bpx4=30,bpy4=335; 
CMy3_1View::CMy3_1View()
{
// TODO: add construction code here
//hcursorblack=AfxGetApp()->LoadCursor(IDC_CURSOR1);
hcursorwhite=AfxGetApp()->LoadCursor(IDC_CURSOR2);
 m_bmwhite.LoadBitmap(IDB_WHITE);
 m_bmblack.LoadBitmap(IDB_BLACK); 
    colorwhite=true;
//默认为人对机
vscomputer=1;
}CMy3_1View::~CMy3_1View()
{
}BOOL CMy3_1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs return CView::PreCreateWindow(cs);
}/////////////////////////////////////////////////////////////////////////////
// CMy3_1View drawingvoid CMy3_1View::OnDraw(CDC *pDC)
{
CMy3_1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//画背景
    CBrush mybrush1;
  mybrush1.CreateSolidBrush(RGB(192,192,192));
  CRect myrect1(0,0,1200,800);
  pDC->FillRect(myrect1,&mybrush1);
 
CBrush mybrush;
  mybrush.CreateSolidBrush(RGB(0,0,0));
for(int a=0;a<3;a++)
for(int b=0;b<3;b++)
{
CRect myrect(97+a*120,97+b*120,103+a*120,103+b*120);
pDC->FillRect(myrect,&mybrush);

    //画黑框线
CPen mypen;
CPen*myoldPen;
mypen.CreatePen(PS_SOLID,1,RGB(0,0,0));
    myoldPen=pDC->SelectObject(&mypen);
    for(int i=0;i<4;i++)
{
pDC->MoveTo(40,40+i*100);
pDC->LineTo(340,40+i*100);
pDC->MoveTo(40+i*100,40);
pDC->LineTo(40+i*100,340);
} CDC Dc;
if(Dc.CreateCompatibleDC(pDC)==FALSE)
      AfxMessageBox("Can't create DC");
 
Dc.SelectObject(m_bmwhite);
pDC->BitBlt(wpx1,wpy1,160,160,&Dc,0,0,SRCCOPY);
pDC->BitBlt(wpx2,wpy2,160,160,&Dc,0,0,SRCCOPY);
pDC->BitBlt(wpx3,wpy3,160,160,&Dc,0,0,SRCCOPY);
pDC->BitBlt(wpx4,wpy4,160,160,&Dc,0,0,SRCCOPY);
Dc.SelectObject(m_bmblack);
  pDC->BitBlt(bpx1,bpy1,160,160,&Dc,0,0,SRCCOPY);
pDC->BitBlt(bpx2,bpy2,160,160,&Dc,0,0,SRCCOPY);
pDC->BitBlt(bpx3,bpy3,60,160,&Dc,0,0,SRCCOPY);
pDC->BitBlt(bpx4,bpy4,160,160,&Dc,0,0,SRCCOPY);   
 //在不同位置显示位图
     
/*  
for(i=0;i<4;i++)
qi[i].bitmap.LoadBitmap(IDB_WHITE);  
for(i=4;i<8;i++)
qi[i].bitmap.LoadBitmap(IDB_BLACK);
//棋子开始出现的位置
for(i=0;i<4;i++)
{
Dc.SelectObject(qi[i].bitmap);  
pDC->BitBlt(wpx1,wpy1,160,160,&Dc,0,0,SRCCOPY);
wpx1+=100;
}
for(i=4;i<8;i++)
{
        Dc.SelectObject(qi[i].bitmap);  
pDC->BitBlt(bpx1,bpy1,160,160,&Dc,0,0,SRCCOPY);
bpx1+=100;
}*/
//gam.Draw(pDC);  
}/////////////////////////////////////////////////////////////////////////////
// CMy3_1View printingBOOL CMy3_1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}void CMy3_1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}void CMy3_1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}/////////////////////////////////////////////////////////////////////////////
// CMy3_1View diagnostics#ifdef _DEBUG
void CMy3_1View::AssertValid() const
{
CView::AssertValid();
}void CMy3_1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}CMy3_1Doc* CMy3_1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy3_1Doc)));
return (CMy3_1Doc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CMy3_1View message handlers 
void CMy3_1View::OnLButtonUp(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default  
//if(Dc.CreateCompatibleDC(pDC)==FALSE)
    //  AfxMessageBox("Can't create DC");
 //显示棋子  
/////////////////////人对机
if(vscomputer==1)
{
GetCursorPos(&point);
//over(point);
colorwhite=false;
//保存白棋位置
vspoint=point;
//重画
    CDC *pDC=GetDC();
    OnDraw(pDC);
        ReleaseDC(pDC); 
int x=point.x;
int y=point.y;
if(x<=70)
{
wpy1=135;
}else if(80<x&&x<=170)
{
wpy2=135;
}else if(190<x&&x<=310)
{
wpy3=135;
}else if(310<x)
{
wpy4=135;
}
//计算机下棋
computerdown();     
}   
CView::OnLButtonUp(nFlags, point);
}BOOL CMy3_1View::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
// TODO: Add your message handler code here and/or call defaultif(nHitTest==HTCLIENT)
{
if(colorwhite)
{
CMainFrame*pFrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
CStatusBar*pStatus=&pFrm->m_wndStatusBar;
if(pStatus)
{
pStatus->GetStatusBarCtrl().SetIcon(0,AfxGetApp()->LoadIcon(IDI_WHITE));
pStatus->SetPaneText(0,"白棋下");
}
SetCursor(hcursorwhite);
}
else
{
CMainFrame*pFrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
CStatusBar*pStatus=&pFrm->m_wndStatusBar;
if(pStatus)
{
//显示图像
//pStatus->GetStatusBarCtrl().SetIcon(0,AfxGetApp()->LoadIcon(IDI_BLACK));
//显示文字  
pStatus->SetPaneText(0,"123");
}
 SetCursor(hcursorwhite);
}
return 1;
}
return CView::OnSetCursor(pWnd, nHitTest, message);
}
void CMy3_1View::over(CPoint point)
{  
}
void CMy3_1View::OnStart() 
{
// TODO: Add your command handler code here 
}
//黑棋下
void CMy3_1View::putdown(CPoint point)

}
//轮到计算机下棋
void CMy3_1View::computerdown()

CDC *pDC=GetDC();
CDC Dc;
/*bpy1-=100;
    Dc.SelectObject(m_bmblack);
  pDC->BitBlt(bpx1,bpy1,160,160,&Dc,0,0,SRCCOPY);
pDC->BitBlt(bpx2,bpy2,160,160,&Dc,0,0,SRCCOPY);
pDC->BitBlt(bpx3,bpy3,60,160,&Dc,0,0,SRCCOPY);
pDC->BitBlt(bpx4,bpy4,160,160,&Dc,0,0,SRCCOPY); */
}
//检查四个方向,各算出五个棋子的和并赋值
void CMy3_1View::bestputdown(int i,int j)
{

//vscomputer:2表示人对人,1表示人对机
void CMy3_1View::OnPlayer() 
{
// TODO: Add your command handler code here
vscomputer=2;
OnStart();
}
void CMy3_1View::OnCpmputer() 
{
// TODO: Add your command handler code here
vscomputer=1;
OnStart();
}