📄 demoview.cpp
字号:
// DEMOView.cpp : implementation of the CDEMOView class
//
#include "stdafx.h"
#include "DEMO.h"
#include "math.h"
#include "DEMODoc.h"
#include "DEMOView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define SK 5 ////////////////////////////////////
unsigned char PN0[64]={1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0};
unsigned char PN1[64]={1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1};
unsigned char PN2[64]={1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned char PN3[64]={1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0};
int B0=0;
int B1=0;
int B2=0;
int B3=0;
unsigned char DeCode(unsigned char *pN,unsigned char *pPN)
{
int Sigma=0;
for(int i=0;i<64;i++)
{
Sigma+=pN[i]*pPN[i];
}
return Sigma;
}
void DrawWave(int head,int x,int y,unsigned char *pL,CDC *pDC)
{
CPen penRed(PS_SOLID,2,RGB(0xff,0x00,0x00));
CPen penBlack(PS_SOLID,2,RGB(0x00,0x00,0xff));
CPen *oldpen=NULL;
for(int i=0;i<64;i++)
{
if((i>=head)&&((i-head)<64))
{
oldpen=pDC->SelectObject(&penRed);
}
else
{
oldpen=pDC->SelectObject(&penBlack);
}
if(i==0)
{
if(pL[i]==0)
{
pDC->MoveTo(x,y+15);
pDC->LineTo(x+(i+1)*12,y+15);
}
else
{
pDC->MoveTo(x,y);
pDC->LineTo(x+(i+1)*12,y);
}
}
else
{
if(pL[i]==0)
{
if(pL[i-1]==0)
{
pDC->LineTo(x+(i+1)*12,y+15);
}
else
{
pDC->LineTo(x+i*12,y+15);
pDC->LineTo(x+(i+1)*12,y+15);
}
}
else
{
if(pL[i-1]==0)
{
pDC->LineTo(x+i*12,y);
pDC->LineTo(x+(i+1)*12,y);
}
else
{
pDC->LineTo(x+(i+1)*12,y);
}
}
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CDEMOView
IMPLEMENT_DYNCREATE(CDEMOView, CFormView)
BEGIN_MESSAGE_MAP(CDEMOView, CFormView)
//{{AFX_MSG_MAP(CDEMOView)
ON_BN_CLICKED(IDC_PN0LEFT, OnPn0left)
ON_BN_CLICKED(IDC_PN0RIGHT, OnPn0right)
ON_BN_CLICKED(IDC_PN1LEFT, OnPn1left)
ON_BN_CLICKED(IDC_PN1RIGHT, OnPn1right)
ON_BN_CLICKED(IDC_PN2LEFT, OnPn2left)
ON_BN_CLICKED(IDC_PN2RIGHT, OnPn2right)
ON_BN_CLICKED(IDC_PN3LEFT, OnPn3left)
ON_BN_CLICKED(IDC_PN3RIGHT, OnPn3right)
ON_BN_CLICKED(IDC_NEWNOISE, OnNewnoise)
ON_BN_CLICKED(IDC_ADDPN0, OnAddpn0)
ON_BN_CLICKED(IDC_ADDPN1, OnAddpn1)
ON_BN_CLICKED(IDC_ADDPN2, OnAddpn2)
ON_BN_CLICKED(IDC_ADDPN3, OnAddpn3)
ON_BN_CLICKED(IDC_NOISE, OnNoise)
ON_BN_CLICKED(IDC_ORXOR, OnOrxor)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDEMOView construction/destruction
CDEMOView::CDEMOView()
: CFormView(CDEMOView::IDD)
{
//{{AFX_DATA_INIT(CDEMOView)
m_addpn0 = FALSE;
m_addpn1 = FALSE;
m_addpn2 = FALSE;
m_addpn3 = FALSE;
m_addnoise = TRUE;
m_xor = FALSE;
//}}AFX_DATA_INIT
// TODO: add construction code here
for(int i=0;i<64;i++)
Noise[i]=0;
}
CDEMOView::~CDEMOView()
{
}
void CDEMOView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDEMOView)
DDX_Check(pDX, IDC_ADDPN0, m_addpn0);
DDX_Check(pDX, IDC_ADDPN1, m_addpn1);
DDX_Check(pDX, IDC_ADDPN2, m_addpn2);
DDX_Check(pDX, IDC_ADDPN3, m_addpn3);
DDX_Check(pDX, IDC_NOISE, m_addnoise);
DDX_Check(pDX, IDC_ORXOR, m_xor);
//}}AFX_DATA_MAP
}
BOOL CDEMOView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CDEMOView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CDEMOView printing
BOOL CDEMOView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDEMOView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDEMOView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CDEMOView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CDEMOView diagnostics
#ifdef _DEBUG
void CDEMOView::AssertValid() const
{
CFormView::AssertValid();
}
void CDEMOView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CDEMODoc* CDEMOView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDEMODoc)));
return (CDEMODoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDEMOView message handlers
void CDEMOView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
unsigned char N[64];
pDC->SetBkMode(TRANSPARENT);//设置文本透明
for(int i=0;i<64;i++)
{
if(i>=B0)
if((i-B0)<64)
N[i]=PN0[i-B0];
else
N[i]=0;
else
N[i]=0;
}
DrawWave(B0,140,30,N,pDC);
///////////////////////////////////////
for(i=0;i<64;i++)
{
if(i>=B1)
if((i-B1)<64)
N[i]=PN1[i-B1];
else
N[i]=0;
else
N[i]=0;
}
DrawWave(B1,140,60,N,pDC);
///////////////////////////////////////
for(i=0;i<64;i++)
{
if(i>=B2)
if((i-B2)<64)
N[i]=PN2[i-B2];
else
N[i]=0;
else
N[i]=0;
}
DrawWave(B2,140,90,N,pDC);
///////////////////////////////////////
for(i=0;i<64;i++)
{
if(i>=B3)
if((i-B3)<64)
N[i]=PN3[i-B3];
else
N[i]=0;
else
N[i]=0;
}
DrawWave(B3,140,120,N,pDC);
///////////////////////////////////////
DrawWave(0,140,220,Noise,pDC);
///////////////////////////////////////
UpdateData(true);
for(i=0;i<64;i++)
{
N[i]=0;
if(m_addpn0)
if(i>=B0)
if((i-B0)<64)
N[i]|=PN0[i-B0];
if(m_addpn1)
if(i>=B1)
if((i-B1)<64)
N[i]|=PN1[i-B1];
if(m_addpn2)
if(i>=B2)
if((i-B2)<64)
N[i]|=PN2[i-B2];
if(m_addpn3)
if(i>=B3)
if((i-B3)<64)
N[i]|=PN3[i-B3];
}
DrawWave(0,140,150,N,pDC);
for(i=0;i<64;i++)
{
if(m_addnoise)
{
if(m_xor)
{
if(Noise[i]==1)
N[i]=0;
}
else
{
if(Noise[i]==1)
N[i]=1;
}
}
}
DrawWave(0,140,290,N,pDC);
////////////////////////////////////////////////////////////////////////
CString ts;
ts.Format("相关度 结果");
pDC->TextOut(100,420,ts);
int temp=DeCode(N,PN0);
temp-=3;
if(temp<0)
temp=0;
temp*=20;
ts.Format("PN0=%%%d",temp);
pDC->TextOut(100,450,ts);
if(temp>50)
pDC->FillSolidRect(180,445,20,20,RGB(0xff,0,0));
else
pDC->FillSolidRect(180,445,20,20,RGB(0xaa,0xaa,0xaa));
////////////////////////////////////////////////////////////////////////
temp=DeCode(N,PN1);
temp-=3;
if(temp<0)
temp=0;
temp*=20;
ts.Format("PN1=%%%d",temp);
pDC->TextOut(100,480,ts);
if(temp>50)
pDC->FillSolidRect(180,475,20,20,RGB(0xff,0,0));
else
pDC->FillSolidRect(180,475,20,20,RGB(0xaa,0xaa,0xaa));
////////////////////////////////////////////////////////////////////////
temp=DeCode(N,PN2);
temp-=3;
if(temp<0)
temp=0;
temp*=20;
ts.Format("PN2=%%%d",temp);
pDC->TextOut(100,510,ts);
if(temp>50)
pDC->FillSolidRect(180,505,20,20,RGB(0xff,0,0));
else
pDC->FillSolidRect(180,505,20,20,RGB(0xaa,0xaa,0xaa));
////////////////////////////////////////////////////////////////////////
temp=DeCode(N,PN3);
temp-=3;
if(temp<0)
temp=0;
temp*=20;
ts.Format("PN3=%%%d",temp);
pDC->TextOut(100,540,ts);
if(temp>50)
pDC->FillSolidRect(180,535,20,20,RGB(0xff,0,0));
else
pDC->FillSolidRect(180,535,20,20,RGB(0xaa,0xaa,0xaa));
////////////////////////////////////////////////////////////////////////
CView::OnDraw(pDC);
}
void CDEMOView::OnPn0left()
{
// TODO: Add your control notification handler code here
B0--;
Invalidate();
}
void CDEMOView::OnPn0right()
{
// TODO: Add your control notification handler code here
B0++;
Invalidate();
}
void CDEMOView::OnPn1left()
{
// TODO: Add your control notification handler code here
B1--;
Invalidate();
}
void CDEMOView::OnPn1right()
{
// TODO: Add your control notification handler code here
B1++;
Invalidate();
}
void CDEMOView::OnPn2left()
{
// TODO: Add your control notification handler code here
B2--;
Invalidate();
}
void CDEMOView::OnPn2right()
{
// TODO: Add your control notification handler code here
B2++;
Invalidate();
}
void CDEMOView::OnPn3left()
{
// TODO: Add your control notification handler code here
B3--;
Invalidate();
}
void CDEMOView::OnPn3right()
{
// TODO: Add your control notification handler code here
B3++;
Invalidate();
}
void CDEMOView::OnNewnoise()
{
// TODO: Add your control notification handler code here
int flag;
do{
flag=0;
for(int i=0;i<64;i++)
{
if(rand()>3276)
Noise[i]=0;
else
{
Noise[i]=1;
flag++;
}
}
}while((flag<2)||(flag>6));
Invalidate();
}
void CDEMOView::OnAddpn0()
{
// TODO: Add your control notification handler code here
Invalidate();
}
void CDEMOView::OnAddpn1()
{
// TODO: Add your control notification handler code here
Invalidate();
}
void CDEMOView::OnAddpn2()
{
// TODO: Add your control notification handler code here
Invalidate();
}
void CDEMOView::OnAddpn3()
{
// TODO: Add your control notification handler code here
Invalidate();
}
void CDEMOView::OnNoise()
{
// TODO: Add your control notification handler code here
Invalidate();
}
void CDEMOView::OnOrxor()
{
// TODO: Add your control notification handler code here
Invalidate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -