📄 childview.cpp
字号:
// ChildView.cpp : implementation of the CChildView class
//
#include "stdafx.h"
#include "ca.h"
#include "ChildView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChildView
CChildView::CChildView()
{
}
CChildView::~CChildView()
{
}
BEGIN_MESSAGE_MAP(CChildView,CWnd )
//{{AFX_MSG_MAP(CChildView)
ON_WM_PAINT()
ON_COMMAND(ID_DO_PAINT, OnDoPaint)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);
return TRUE;
}
void CChildView::OnPaint()
{
CPaintDC dc(this); // device context for painting
AfxGetMainWnd()->SetWindowText("一维随机元胞自动机(分形频道:fractal.cn)2004");
if(rand() < RAND_MAX/2) {
DrawCa(&dc);
}
else PostMessage(WM_COMMAND, ID_PEANO_CURVE);
}
void CChildView::DrawCa(CDC *pDC)
{
RECT rt;
GetClientRect(&rt);
char* status = new char[rt.right-rt.left+1];
char* status2 = new char[rt.right-rt.left+1];
int i,j;
for(i=0; i < rt.right-rt.left; i++)
{
status[i] = 0;
status2[i] = 0;
}
status++;
status2++;
for(j=0; j < rt.right-rt.left; j++)
{
int c=rand()%2;
if (c==1)
{
status[j] = 1;
pDC->SetPixel(0, j, RGB(0xff, 0, 0xff));
}
}
for(i=1; i<rt.bottom -rt.top ; i++) {
for(j=1; j<rt.right-rt.left; j++) {
if (status[j-1]==0 && status[j] == 0 && status[j+1] == 1)
status2[j] = 1;
else if (status[j-1]==1 && status[j] == 0 && status[j+1] == 0)
status2[j] = 1;
else status2[j] = 0;
if (status2[j]) pDC->SetPixel(j, i+2, RGB(0, 0, 0));
}
memcpy(status-1, status2-1, rt.right-rt.left+1);
}
status--;
status2--;
delete []status;
delete []status2;
}
void CChildView::OnDoPaint()
{
CDC *pDC = GetDC();
DrawCa(pDC);
ReleaseDC(pDC);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -