📄 hdb3dlg.cpp
字号:
// HDB3Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "HDB3.h"
#include "HDB3Dlg.h"
//#include <afxcoll.h>
#include <afxtempl.h>
#include <IOSTREAM.H>
unsigned int num_b=0,k=0;
#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()
/////////////////////////////////////////////////////////////////////////////
// CHDB3Dlg dialog
CHDB3Dlg::CHDB3Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CHDB3Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHDB3Dlg)
m_edit = _T("");
m_out = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CHDB3Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHDB3Dlg)
DDX_Control(pDX, IDOK, m_ok);
DDX_Text(pDX, IDC_EDIT, m_edit);
DDX_Text(pDX, IDC_OUT, m_out);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHDB3Dlg, CDialog)
//{{AFX_MSG_MAP(CHDB3Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHDB3Dlg message handlers
BOOL CHDB3Dlg::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);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
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 CHDB3Dlg::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 CHDB3Dlg::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();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CHDB3Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CHDB3Dlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
unsigned int uLength = 0;
if( (uLength = m_edit.GetLength()) == 0 )
{
MessageBox( _T("Please Input.") , _T("Error") , MB_OK|MB_ICONINFORMATION );
return;
}
CUIntArray uArray;
CArray<int,int> outArray;
uArray.SetSize( uLength );
outArray.SetSize(uLength );
char cTemp;
for (unsigned int a=0; a<uLength ;a++)
{
cTemp = m_edit.GetAt( a );
uArray[a] = atoi( &cTemp );
}
unsigned int first1=0;
/*
if (uArray[0]==0)
{
MessageBox( "Sorry,首位不能为0!" , _T("Warning") , MB_OK );
}
outArray[0] = 1;
*/
if (uArray[0]==0)
{
if (uLength>1 && uArray[0]==0 && uArray[1]==1)
{
outArray[0]=0;outArray[1]=1;first1=2;
}
else if(uLength>2 && uArray[0]==0 && uArray[1]==0 && uArray[2]==1)
{
outArray[0]=0;outArray[1]=0;outArray[2]=1;first1=3;
}
else if(uLength>3 && uArray[0]==0 && uArray[1]==0 && uArray[2]==0 && uArray[3]==1)
{
outArray[0]=0;outArray[1]=0;outArray[2]=0;outArray[3]=1;first1=4;
}
else if(uLength>3 && uArray[0]==0 && uArray[1]==0 && uArray[2]==0 && uArray[3]==0)
{
outArray[0]=1;outArray[1]=0;outArray[2]=0;outArray[3]=1;k=1;first1=4;
}
}
else
{
outArray[0]=1;first1=1;
}
unsigned int flag0=0;
for (unsigned int i=first1; i<uLength ;i++)
{
if (uArray[i]==1)
{
for(unsigned int i3=1;outArray[i-i3]==0;i3++);
if (outArray[i-i3]==1)
{
outArray[i]=-1;
}
else
{
outArray[i]=1;
}
flag0=0;
num_b++;
}
else
{
flag0++;
if (flag0==4)
{
if (num_b %2 != 0 || k==0)
{
outArray[i]=outArray[i-4];
}
else
{
outArray[i-3]=-outArray[i-4];
outArray[i]=outArray[i-3];
}
flag0=0;
num_b=0;
k++;
}
else
{
outArray[i]=0;
}
}
}
k=0;
CString outStr;
for( int i2=0 ; i2 < outArray.GetSize() ; i2++ )
{
if( outArray[i2] == 1 )
outStr+=_T("+1");
else if( outArray[i2] == 0 )
outStr+=_T("0");
else
outStr+=_T("-1");
}
// MessageBox( outStr , _T("Info") , MB_OK );
m_out=outStr;
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -