瑞星卡卡安全论坛技术交流区系统软件 这是设计的一个记时器(紧代码分析)@@@@

1   1  /  1  页   跳转

这是设计的一个记时器(紧代码分析)@@@@

这是设计的一个记时器(紧代码分析)@@@@

////////////////////////////////////////
//AC25View.h : interface of the CA25View class
//CA25View
///////////////////////////////////////
class CA25View : public CView
{
  protected: //create form serialization only
  CA25View();
  DECLARE_DYNCREATE(CA25View)
  public:
  CA25Doc* GetDocument();
  public:
  //{{AFX_VIRTUAL(CA25View)
  public:
  virtual void OnDraw(CDC* pDC); //overridden to draw this view
  vitrual BOOL PreCreateWindow(CREATESTRUCT& cs);
  protected:
  virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
  virtual void OnBeginPrinting(CDC* pDC,CPrintInfo* pInfo);
  virtual void OnEndPrinting(CDC* pDC,CPrintInfo* pInfo);
  //}}AFX_VIRTUAL
  public:
  virtual ~CA25View();
  #ifdef_DEBUG
  virtual void AssertValid() const;
  virtual void Dump(CDumpContext& dc) const;
  #endif
  protected:
  //{{AFX_MSG(CA25View)
  afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  afx_msg void OnTimer(UINT nIDEvent);
  //}}AFX_MSG
  DECLARE_MESSAGE_MAP()
};
 
  IMPLEMENT_DYNCREATE(CA25View,CView)
  BEGIN_MESSAGE_MAP(CA25View,CView)
  //{{AFX_MSG_MAP(CA25View)
  ON_WM_CREATE()
  ON_WM_TIMER()
  //}}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()
  void CA25View::OnDraw(CDC* pDC)
{
  CA25Doc* 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;
  CPen Pen(PS_SOLID,5,RGB(255,255,0));
  CPen *OldPen = pDC->SelectObject(&Pen);
  Pdc->Ellipse(5,5,Rect.right-5,Rect.bottm-5);
  double Radians;
  pDC->SetTextColor(RGB(255,255,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,t,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;
  CPen MinutePen(PS_SOLID,3,RGB(0,0,225));
  pDC->SelectObject(&MinutePen);
  pDC->MoveTO(CenterX,CenterY);
  pDC->LineTo(CenterX + (it)((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,I,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);
}

  int CA25View::OnCreate(LPREATESTRUCT lpCreateStruct)
  {
    if(CView::OnCreate(lpCreateStruct) == -1)
    return -1;
    SetTimer(1,1000,NULL);
    return 0;
  }

void CA25iew::OnTimer(UINT nIDEvent)
{
  //TODO: Add your message handler code here and/or call default InvalidateRect(NULL,true);
  Update Windows();
  CView::OnTimer(nIDEvent);
}
 
 
 
最后编辑2006-08-21 19:52:28
分享到:
gototop
 

有什么不对的地方吗???
我才到高级控件
是初学者,
有不对的 地方要请教!!
gototop
 
1   1  /  1  页   跳转
页面顶部
Powered by Discuz!NT