// crainDlg.cpp : implementation file
//
#include "stdafx.h"
#include "crain.h"
#include "crainDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCrainDlg dialog
CCrainDlg::CCrainDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCrainDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCrainDlg)
m_dropnumber = 0;
m_ripplenumber = 0;
m_wind = 0;
//}}AFX_DATA_INIT
israinning=false;
soundon=false;
m_wind=0;
m_ripplenumber=0;
m_dropnumber=0;
dc=new struct dropletchain;
dc->drop=NULL;
dc->pre=dc;
dc->next=dc;
rc=new struct ripplechain;
rc->aripple=NULL;
rc->pre=rc;
rc->next=rc;
int i ;
for(i=0;i<1000;i++)
{
vsin[i]=sin(i*6.284/1000);
vcos[i]=cos(i*6.284/1000);
}
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCrainDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCrainDlg)
DDX_Text(pDX, IDC_EDIT5, m_dropnumber);
DDX_Text(pDX, IDC_EDIT6, m_ripplenumber);
DDX_Text(pDX, IDC_EDIT1, m_wind);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCrainDlg, CDialog)
//{{AFX_MSG_MAP(CCrainDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_LBUTTONDOWN()
ON_WM_CANCELMODE()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_WM_MOUSEMOVE()
ON_WM_CAPTURECHANGED()
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCrainDlg message handlers
BOOL CCrainDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CCrainDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCrainDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
HCURSOR CCrainDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//DEL void CCrainDlg::show()
//DEL {
//DEL
//DEL }
void CCrainDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
}
void CCrainDlg::OnCancelMode()
{
CDialog::OnCancelMode();
}
void CCrainDlg::draw()
{
CWnd * PaintWind=this->GetDlgItem(ID_P);
CDC * PaintWindDC=PaintWind->GetDC();
PaintWind->GetClientRect(aRect);
Rect1.bottom=aRect.bottom ;
Rect1.right =aRect.right ;
Rect1.left =aRect.left ;
Rect1.top =aRect.bottom * 2 / 3;
PaintWindDC->SetROP2(R2_XORPEN);
struct dropletchain * adropchain;
droplet * adrop;
if(dc->next != dc)
{
adropchain=dc->next;
while(adropchain!=dc)
{
adrop=adropchain->drop;
if(adrop->visibility)
{
aBrush.DeleteObject();
aBrush.CreateSolidBrush(adrop->color);
aRgn.DeleteObject ();
aRgn.CreateEllipticRgn (adrop->x-adrop->radius,
adrop->y-adrop->radius,
adrop->x+adrop->radius,
adrop->y+adrop->radius);
PaintWindDC->FillRgn(&aRgn,&aBrush);
}
adropchain=adropchain->next;
}
}
struct ripplechain * aripplechain;
ripple * aripple;
if(rc->next != rc)
{
aripplechain=rc->next;
while(aripplechain!=rc)
{
aripple=aripplechain ->aripple;
aripple->shown=1-aripple->shown ;
this->drawellipse (PaintWindDC,aripple->xdrop-aripple->radius,
aripple->ydrop-aripple->radius/2,
aripple->xdrop+aripple->radius,
aripple->ydrop+aripple->radius/2,aripple->color );
this->drawellipse (PaintWindDC,aripple->xdrop-aripple->radius-1,
aripple->ydrop-aripple->radius/2-1,
aripple->xdrop+aripple->radius+1,
aripple->ydrop+aripple->radius/2+1,aripple->color );
aripplechain=aripplechain->next;
}
}
PaintWind->ReleaseDC (PaintWindDC);
}
void CCrainDlg::drive()
{
char s[10];
struct dropletchain * ndc=new struct dropletchain;
droplet * ndrop=new droplet;
ndrop->color=RGB(rand()%256,rand()%256,rand()%256);
ndrop->visibility =1;
ndrop->radius =rand()%3+1;
ndrop->x=rand()%(aRect.right -aRect.left);
ndrop->y=rand()%(Rect1.top -aRect.top );
ndrop->xvelocity=0;
ndrop->yvelocity =10;
ndc->drop =ndrop;
ndc->pre =dc;
ndc->next =dc->next ;
ndc->next->pre =ndc;
dc->next =ndc;
this->m_dropnumber ++;
sprintf(s,"%d",m_dropnumber);
this->SetDlgItemText(IDC_EDIT5,s);
struct dropletchain * adropchain;
droplet * adrop;
if(dc->next != dc)
{
adropchain=dc->next;
while(adropchain!=dc)
{
adrop=adropchain->drop;
adrop->x+=(adrop->xvelocity+xacce) ;
adrop->y+=(adrop->yvelocity+yacce) ;
if(adrop->x>aRect.right ||
adrop->x<aRect.left ||
adrop->y<aRect.top||
adrop->y>aRect.bottom )
{
adropchain->next->pre=adropchain->pre;
adropchain=adropchain->next;
delete adropchain->pre->next->drop ;
delete adropchain->pre->next ;
adropchain->pre->next=adropchain;
this->m_dropnumber --;
sprintf(s,"%d",m_dropnumber);
this->SetDlgItemText(IDC_EDIT5,s);
}
else if(adrop->y>Rect1.top+40 && rand()%4==1)
{
struct ripplechain * arc=