主题:调试
我按书上做一个指针式时钟, B04View.cpp 的代码如下,
// B04View.cpp : implementation of the CB04View class
//
#include "stdafx.h"
#include "B04.h"
#include "math.h"
#include "B04Doc.h"
#include "B04View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CB04View
IMPLEMENT_DYNCREATE(CB04View, CView)
BEGIN_MESSAGE_MAP(CB04View, CView)
//{{AFX_MSG_MAP(CB04View)
ON_WM_TIMER()
ON_WM_CREATE()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CB04View construction/destruction
CB04View::CB04View()
{
// TODO: add construction code here
}
CB04View::~CB04View()
{
}
BOOL CB04View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CB04View drawing
void CB04View::OnDraw(CDC* pDC)
{
CB04Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
RECT Rect;
GetClientRect(&Rect);
int CenterX=Rect.right/2;
int CenterY=Rect.bottom/2;
CTime Time=CTime::GetCurrentTime();
CString str;
int i,x,y;
CSize size;
CPen Pen(PS_SOLID,5,RGB(255,255,0));
CPen *OldPen=pDC->SelectObject(&Pen);
pDC->Ellipse(5,5,Rect.right-5,Rect.bottom-5);
double Radians;
pDC->SetTextColor(RGB(255,0,0));
for(i=1;i<=12;i++)
{
str.Format("%d",i);
size=pDC->GetTextExtent(str,str.GetLength());
Radians=(double)i*6.28/12.0;
x=CenterX-(size.cx/2)+(int)((double)(CenterX-20)*sin(Radians));
y=CenterY-(size.cy/2)+(int)((double)(CenterY-20)*cos(Radians));
pDC->TextOut(x,y,str);
}
Radians=(double)Time.GetHour()+(double)Time.GetMinute()/60.0+(double)Time.GetSecond()/3600.0;
Radians*=6.28/12.0;
CPen HourPen(PS_SOLID,5,RGB(0,255,0));
pDC->SelectObject(&HourPen);
pDC->MoveTo(CenterX,CenterY);
pDC->LineTo(CenterX+(int)((double)(CenterX/3)*sin(Radians)),CenterY-(int)((double)(CenterY/3)*cos(Radians)));
Radians=(double)Time.GetMinute()+(double)Time.GetSecond()/60.0;
Radians*=6.28/60.0;
CPen MinutePen(PS_SOLID,3,RGB(0,0,255));
pDC->SelectObject(&MinutePen);
pDC->MoveTo(CenterX,CenterY);
pDC->LineTo(CenterX+(int)((double)(CenterX*2)/3*sin(Radians),CenterY-(int)((double)(CenterY*2)/3*cos(Radians))));
Radians=(double)Time.GetSecond();
Radians*=6.28/60.0;
CPen SecondPen(PS_SOLID,1,RGB(0,255,255));
pDC->SelectObject(&SecondPen);
pDC->MoveTo(CenterX,CenterY);
pDC->LineTo(CenterX+(int)((double)(CenterX*4)/5)*sin(Radians),CenterY-(int)((double)(CenterY*4)/5*cos(Radians)));
pDC->SelectObject(OldPen);
}
/////////////////////////////////////////////////////////////////////////////
// CB04View printing
BOOL CB04View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CB04View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CB04View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CB04View diagnostics
#ifdef _DEBUG
void CB04View::AssertValid() const
{
CView::AssertValid();
}
void CB04View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CB04Doc* CB04View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CB04Doc)));
return (CB04Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CB04View message handlers
void CB04View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
InvalidateRect(NULL,true);
UpdateWindow();
CView::OnTimer(nIDEvent);
}
int CB04View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,1000,NULL);
return 0;
}
在调试时,显示出错的代码段为:
pDC->LineTo(CenterX+(int)((double)(CenterX*2)/3*sin(Radians),CenterY-(int)((double)(CenterY*2)/3*cos(Radians))));
它的调试错误为:
E:\aa\B04\B04View.cpp(97) : error C2664: 'int __thiscall CDC::LineTo(struct tagPOINT)' : cannot convert parameter 1 from 'int' to 'struct tagPOINT'
No constructor could take the source type, or constructor overload resolution was ambiguous
请问下各位高手,如何解决?
// B04View.cpp : implementation of the CB04View class
//
#include "stdafx.h"
#include "B04.h"
#include "math.h"
#include "B04Doc.h"
#include "B04View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CB04View
IMPLEMENT_DYNCREATE(CB04View, CView)
BEGIN_MESSAGE_MAP(CB04View, CView)
//{{AFX_MSG_MAP(CB04View)
ON_WM_TIMER()
ON_WM_CREATE()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CB04View construction/destruction
CB04View::CB04View()
{
// TODO: add construction code here
}
CB04View::~CB04View()
{
}
BOOL CB04View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CB04View drawing
void CB04View::OnDraw(CDC* pDC)
{
CB04Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
RECT Rect;
GetClientRect(&Rect);
int CenterX=Rect.right/2;
int CenterY=Rect.bottom/2;
CTime Time=CTime::GetCurrentTime();
CString str;
int i,x,y;
CSize size;
CPen Pen(PS_SOLID,5,RGB(255,255,0));
CPen *OldPen=pDC->SelectObject(&Pen);
pDC->Ellipse(5,5,Rect.right-5,Rect.bottom-5);
double Radians;
pDC->SetTextColor(RGB(255,0,0));
for(i=1;i<=12;i++)
{
str.Format("%d",i);
size=pDC->GetTextExtent(str,str.GetLength());
Radians=(double)i*6.28/12.0;
x=CenterX-(size.cx/2)+(int)((double)(CenterX-20)*sin(Radians));
y=CenterY-(size.cy/2)+(int)((double)(CenterY-20)*cos(Radians));
pDC->TextOut(x,y,str);
}
Radians=(double)Time.GetHour()+(double)Time.GetMinute()/60.0+(double)Time.GetSecond()/3600.0;
Radians*=6.28/12.0;
CPen HourPen(PS_SOLID,5,RGB(0,255,0));
pDC->SelectObject(&HourPen);
pDC->MoveTo(CenterX,CenterY);
pDC->LineTo(CenterX+(int)((double)(CenterX/3)*sin(Radians)),CenterY-(int)((double)(CenterY/3)*cos(Radians)));
Radians=(double)Time.GetMinute()+(double)Time.GetSecond()/60.0;
Radians*=6.28/60.0;
CPen MinutePen(PS_SOLID,3,RGB(0,0,255));
pDC->SelectObject(&MinutePen);
pDC->MoveTo(CenterX,CenterY);
pDC->LineTo(CenterX+(int)((double)(CenterX*2)/3*sin(Radians),CenterY-(int)((double)(CenterY*2)/3*cos(Radians))));
Radians=(double)Time.GetSecond();
Radians*=6.28/60.0;
CPen SecondPen(PS_SOLID,1,RGB(0,255,255));
pDC->SelectObject(&SecondPen);
pDC->MoveTo(CenterX,CenterY);
pDC->LineTo(CenterX+(int)((double)(CenterX*4)/5)*sin(Radians),CenterY-(int)((double)(CenterY*4)/5*cos(Radians)));
pDC->SelectObject(OldPen);
}
/////////////////////////////////////////////////////////////////////////////
// CB04View printing
BOOL CB04View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CB04View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CB04View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CB04View diagnostics
#ifdef _DEBUG
void CB04View::AssertValid() const
{
CView::AssertValid();
}
void CB04View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CB04Doc* CB04View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CB04Doc)));
return (CB04Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CB04View message handlers
void CB04View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
InvalidateRect(NULL,true);
UpdateWindow();
CView::OnTimer(nIDEvent);
}
int CB04View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,1000,NULL);
return 0;
}
在调试时,显示出错的代码段为:
pDC->LineTo(CenterX+(int)((double)(CenterX*2)/3*sin(Radians),CenterY-(int)((double)(CenterY*2)/3*cos(Radians))));
它的调试错误为:
E:\aa\B04\B04View.cpp(97) : error C2664: 'int __thiscall CDC::LineTo(struct tagPOINT)' : cannot convert parameter 1 from 'int' to 'struct tagPOINT'
No constructor could take the source type, or constructor overload resolution was ambiguous
请问下各位高手,如何解决?