21xrx.com
2025-03-30 16:38:51 Sunday
文章检索 我的文章 写文章
VC++6.0 爱心程序代码
2023-07-09 05:17:18 深夜i     43     0
VC++ 0 爱心程序 代码

VC++6.0是一个非常经典的程序开发工具,其支持的编程语言包括C++和MFC。很多开发者都会用其开发一些简单、有趣的程序,比如爱心程序。

下面是一段VC++6.0的爱心程序代码,可以用于制作一个简单的爱心表白程序:

#include <afxwin.h>
#include <afxext.h>
#include <afxdisp.h>
#include <afxdtctl.h>
#include <afxcmn.h>
#include <afxrich.h>
#include <afxpriv.h>
#include <afxmt.h>
#include <afxtempl.h>
class CHeartView : public CView
{
protected: // create from serialization only
  CHeartView();
  DECLARE_DYNCREATE(CHeartView)
// Attributes
public:
  CHeartDoc* GetDocument();
// Operations
public:
// Overrides
  // ClassWizard generated virtual function overrides
  //{{AFX_VIRTUAL(CHeartView)
  public:
  virtual void OnDraw(CDC* pDC); 
  //}}AFX_VIRTUAL
// Implementation
public:
  virtual ~CHeartView();
#ifdef _DEBUG
  virtual void AssertValid() const;
  virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
  //{{AFX_MSG(CHeartView)
  // NOTE - the ClassWizard will add and remove member functions here.
  // DO NOT EDIT what you see in these blocks of generated code!
  //}}AFX_MSG
  DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in HeartView.cpp
inline CHeartDoc* CHeartView::GetDocument()
  { return (CHeartDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
// CHeartView
IMPLEMENT_DYNCREATE(CHeartView, CView)
CHeartView::CHeartView()
CHeartView::~CHeartView()
void CHeartView::OnDraw(CDC* pDC)
{
  CHeartDoc* pDoc = GetDocument();
  ASSERT_VALID(pDoc);
  // TODO: add draw code for native data here
  int a[50],b[50],p[50],q[50],i;
  double t,x,y;
  for(t=0,i=0;t<24.1;t+=0.5,i++)
  {
    a[i]=int(10*(6*cos(t)-cos(6*t)));
    b[i]=int(10*(6*sin(t)-sin(6*t)));
    p[i]=300-a[i];
    q[i]=200-b[i];
  }
  CPen pen(PS_SOLID,2,RGB(255,0,0));
  CPen* oldpen=pDC->SelectObject(&pen);
  pDC->PolyBezier(p,q,25);
  CPen pen1(PS_SOLID,2,RGB(0,220,0));
  pDC->SelectObject(&pen1);
  pDC->PolyBezier(p+25,q+25,25);
  pDC->SelectObject(oldpen);
}
#ifdef _DEBUG
void CHeartView::AssertValid() const
{
  CView::AssertValid();
}
void CHeartView::Dump(CDumpContext& dc) const
{
  CView::Dump(dc);
}
CHeartDoc* CHeartView::GetDocument() // non-debug version is inline
{
  ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHeartDoc)));
  return (CHeartDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHeartView message handlers
BEGIN_MESSAGE_MAP(CHeartView, CView)
  //{{AFX_MSG_MAP(CHeartView)
  // NOTE - the ClassWizard will add and remove mapping macros here.
  // DO NOT EDIT what you see in these blocks of generated code!
  //}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHeartView drawing
void CHeartView::OnDraw(CDC* pDC)
{
  CHeartDoc* pDoc = GetDocument();
  ASSERT_VALID(pDoc);
  if (!pDoc)
    return;
  CRect r;
  GetClientRect(&r);
  CBrush br(RGB(255,192,203));
  pDC->FillRect(&r,&br);
  pDC->SetMapMode(MM_LOMETRIC);
  int a[50],b[50],p[50],q[50],i;
  double t,x,y;
  for(t=0,i=0;t<24.1;t+=0.5,i++)
  {
    a[i]=int(10*(6*cos(t)-cos(6*t)));
    b[i]=int(10*(6*sin(t)-sin(6*t)));
    p[i]=300-a[i];
    q[i]=200-b[i];
  }
  CPen pen(PS_SOLID,2,RGB(255,0,0));
  CPen* oldpen=pDC->SelectObject(&pen);
  pDC->PolyBezier(p,q,25);
  CPen pen1(PS_SOLID,2,RGB(0,220,0));
  pDC->SelectObject(&pen1);
  pDC->PolyBezier(p+25,q+25,25);
  pDC->SelectObject(oldpen);
  CString str="我爱你,心形属于你.";
  pDC->TextOut(320,290,str);
}

这段代码实现了一个红绿相间的心形图案,并且在屏幕中间输出一个简单的表白信息。实际上,这只是VC++6.0爱心程序的一种实现方式,开发者可以根据自己的需求进行修改和创新。通过这个小程序,可以感受到程序开发的乐趣,并且给心仪的对象表达自己的真挚情感!

  
  

评论区