📄 statdlg.cpp
字号:
// statDlg.cpp : implementation file
//
#include "stdafx.h"
#include "stat.h"
#include "statDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CStatDlg dialog
CStatDlg::CStatDlg(CWnd* pParent /*=NULL*/)
: CDialog(CStatDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CStatDlg)
m_display1 = _T("");
m_display2 = _T("");
m_where1 = 0;
m_where2 = 0;
m_where3 = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CStatDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStatDlg)
DDX_Control(pDX, IDC_CHECK70, m_check70);
DDX_Control(pDX, IDC_CHECK69, m_check69);
DDX_Control(pDX, IDC_CHECK68, m_check68);
DDX_Control(pDX, IDC_CHECK67, m_check67);
DDX_Control(pDX, IDC_CHECK66, m_check66);
DDX_Control(pDX, IDC_CHECK65, m_check65);
DDX_Control(pDX, IDC_CHECK64, m_check64);
DDX_Control(pDX, IDC_CHECK63, m_check63);
DDX_Control(pDX, IDC_CHECK62, m_check62);
DDX_Control(pDX, IDC_CHECK61, m_check61);
DDX_Control(pDX, IDC_CHECK60, m_check60);
DDX_Control(pDX, IDC_CHECK59, m_check59);
DDX_Control(pDX, IDC_CHECK58, m_check58);
DDX_Control(pDX, IDC_CHECK57, m_check57);
DDX_Control(pDX, IDC_CHECK56, m_check56);
DDX_Control(pDX, IDC_CHECK55, m_check55);
DDX_Control(pDX, IDC_CHECK54, m_check54);
DDX_Control(pDX, IDC_CHECK53, m_check53);
DDX_Control(pDX, IDC_CHECK52, m_check52);
DDX_Control(pDX, IDC_CHECK51, m_check51);
DDX_Control(pDX, IDC_CHECK50, m_check50);
DDX_Control(pDX, IDC_CHECK49, m_check49);
DDX_Control(pDX, IDC_CHECK48, m_check48);
DDX_Control(pDX, IDC_CHECK47, m_check47);
DDX_Control(pDX, IDC_CHECK46, m_check46);
DDX_Control(pDX, IDC_CHECK45, m_check45);
DDX_Control(pDX, IDC_CHECK44, m_check44);
DDX_Control(pDX, IDC_CHECK43, m_check43);
DDX_Control(pDX, IDC_CHECK42, m_check42);
DDX_Control(pDX, IDC_CHECK41, m_check41);
DDX_Control(pDX, IDC_CHECK40, m_check40);
DDX_Control(pDX, IDC_CHECK39, m_check39);
DDX_Control(pDX, IDC_CHECK38, m_check38);
DDX_Control(pDX, IDC_CHECK37, m_check37);
DDX_Control(pDX, IDC_CHECK36, m_check36);
DDX_Control(pDX, IDC_CHECK35, m_check35);
DDX_Control(pDX, IDC_CHECK34, m_check34);
DDX_Control(pDX, IDC_CHECK33, m_check33);
DDX_Control(pDX, IDC_CHECK32, m_check32);
DDX_Control(pDX, IDC_CHECK31, m_check31);
DDX_Control(pDX, IDC_CHECK30, m_check30);
DDX_Control(pDX, IDC_CHECK29, m_check29);
DDX_Control(pDX, IDC_CHECK28, m_check28);
DDX_Control(pDX, IDC_CHECK27, m_check27);
DDX_Control(pDX, IDC_CHECK26, m_check26);
DDX_Control(pDX, IDC_CHECK25, m_check25);
DDX_Control(pDX, IDC_CHECK24, m_check24);
DDX_Control(pDX, IDC_CHECK23, m_check23);
DDX_Control(pDX, IDC_CHECK22, m_check22);
DDX_Control(pDX, IDC_CHECK21, m_check21);
DDX_Control(pDX, IDC_CHECK20, m_check20);
DDX_Control(pDX, IDC_CHECK19, m_check19);
DDX_Control(pDX, IDC_CHECK18, m_check18);
DDX_Control(pDX, IDC_CHECK17, m_check17);
DDX_Control(pDX, IDC_CHECK16, m_check16);
DDX_Control(pDX, IDC_CHECK15, m_check15);
DDX_Control(pDX, IDC_CHECK14, m_check14);
DDX_Control(pDX, IDC_CHECK13, m_check13);
DDX_Control(pDX, IDC_CHECK12, m_check12);
DDX_Control(pDX, IDC_CHECK11, m_check11);
DDX_Control(pDX, IDC_CHECK10, m_check10);
DDX_Control(pDX, IDC_CHECK9, m_check9);
DDX_Control(pDX, IDC_CHECK8, m_check8);
DDX_Control(pDX, IDC_CHECK7, m_check7);
DDX_Control(pDX, IDC_CHECK6, m_check6);
DDX_Control(pDX, IDC_CHECK5, m_check5);
DDX_Control(pDX, IDC_CHECK4, m_check4);
DDX_Control(pDX, IDC_CHECK3, m_check3);
DDX_Control(pDX, IDC_CHECK2, m_check2);
DDX_Control(pDX, IDC_CHECK1, m_check1);
DDX_Text(pDX, IDC_display1, m_display1);
DDX_Text(pDX, IDC_display2, m_display2);
DDX_Text(pDX, IDC_where1, m_where1);
DDX_Text(pDX, IDC_where2, m_where2);
DDX_Text(pDX, IDC_where3, m_where3);
// DDX_Control(pDX, IDC_SKIN1, m_pSkin);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStatDlg, CDialog)
//{{AFX_MSG_MAP(CStatDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDOK2, OnOk2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStatDlg message handlers
BOOL CStatDlg::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
//dlg.DoModal();
return TRUE; // return TRUE unless you set the focus to a control
}
void CStatDlg::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 CStatDlg::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 CStatDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CStatDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData();
//if(m_where1==0&&m_where3==0)
if(m_where1==0||m_where3==0)
{
AfxMessageBox("每组合计不能为0");
return;
}
if(m_where2==0)
{
AfxMessageBox("每组偶数占有个数不能为0");
return;
}
fp=fopen("king.txt","w+");
m_ret=fprintf(fp, "%s\n","***************************排列组合**********************");
if(m_ret<0)
{
AfxMessageBox("文件写入出错");
}
group1();
group2();
group3();
group4();
group5();
group6();
group7();
m_out.Empty();
count();
fclose(fp);
/*
CString strFilter =
"Circle files(*.txt)|*,txt|All files(*.*)|*.*||";
CFileDialog dlg(false,NULL,"king.txt",
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,strFilter);
if(dlg.DoModal()==IDOK)
{
CFile file;
file.Remove(dlg.GetFileName());
file.Open(dlg.GetPathName(),CFile::modeCreate|CFile::modeWrite);
m_out.Format("%s","ok");
m_out=m_out+_T("\r\n");
m_out=m_out+_T("lvhb@singlee.com.cn");
m_out=m_out+_T("\r\n");
m_out=m_out+_T("lvhb@singlee.com.cn");
group1();
group2();
group3();
group4();
group5();
group6();
group7();
count();
file.Write(m_out,m_out.GetLength());
file.Close();
}
*/
}
void CStatDlg::group1()
{
int i=0;
if(m_check1.GetCheck()==1)
num1[i++]=0;
if(m_check2.GetCheck()==1)
num1[i++]=1;
if(m_check3.GetCheck()==1)
num1[i++]=2;
if(m_check4.GetCheck()==1)
num1[i++]=3;
if(m_check5.GetCheck()==1)
num1[i++]=4;
if(m_check6.GetCheck()==1)
num1[i++]=5;
if(m_check7.GetCheck()==1)
num1[i++]=6;
if(m_check8.GetCheck()==1)
num1[i++]=7;
if(m_check9.GetCheck()==1)
num1[i++]=8;
if(m_check10.GetCheck()==1)
num1[i++]=9;
num_1=i;
}
void CStatDlg::group2()
{
int i=0;
if(m_check11.GetCheck()==1)
num2[i]=0;
if(m_check12.GetCheck()==1)
num2[i++]=1;
if(m_check13.GetCheck()==1)
num2[i++]=2;
if(m_check14.GetCheck()==1)
num2[i++]=3;
if(m_check15.GetCheck()==1)
num2[i++]=4;
if(m_check16.GetCheck()==1)
num2[i++]=5;
if(m_check17.GetCheck()==1)
num2[i++]=6;
if(m_check18.GetCheck()==1)
num2[i++]=7;
if(m_check19.GetCheck()==1)
num2[i++]=8;
if(m_check20.GetCheck()==1)
num2[i++]=9;
num_2=i;
}
void CStatDlg::group3()
{
int i=0;
if(m_check21.GetCheck()==1)
num3[i]=0;
if(m_check22.GetCheck()==1)
num3[i++]=1;
if(m_check23.GetCheck()==1)
num3[i++]=2;
if(m_check24.GetCheck()==1)
num3[i++]=3;
if(m_check25.GetCheck()==1)
num3[i++]=4;
if(m_check26.GetCheck()==1)
num3[i++]=5;
if(m_check27.GetCheck()==1)
num3[i++]=6;
if(m_check28.GetCheck()==1)
num3[i++]=7;
if(m_check29.GetCheck()==1)
num3[i++]=8;
if(m_check30.GetCheck()==1)
num3[i++]=9;
num_3=i;
}
void CStatDlg::group4()
{
int i=0;
if(m_check31.GetCheck()==1)
num4[i]=0;
if(m_check32.GetCheck()==1)
num4[i++]=1;
if(m_check33.GetCheck()==1)
num4[i++]=2;
if(m_check34.GetCheck()==1)
num4[i++]=3;
if(m_check35.GetCheck()==1)
num4[i++]=4;
if(m_check36.GetCheck()==1)
num4[i++]=5;
if(m_check37.GetCheck()==1)
num4[i++]=6;
if(m_check38.GetCheck()==1)
num4[i++]=7;
if(m_check39.GetCheck()==1)
num4[i++]=8;
if(m_check40.GetCheck()==1)
num4[i++]=9;
num_4=i;
}
void CStatDlg::group5()
{
int i=0;
if(m_check41.GetCheck()==1)
num5[i]=0;
if(m_check42.GetCheck()==1)
num5[i++]=1;
if(m_check43.GetCheck()==1)
num5[i++]=2;
if(m_check44.GetCheck()==1)
num5[i++]=3;
if(m_check45.GetCheck()==1)
num5[i++]=4;
if(m_check46.GetCheck()==1)
num5[i++]=5;
if(m_check47.GetCheck()==1)
num5[i++]=6;
if(m_check48.GetCheck()==1)
num5[i++]=7;
if(m_check49.GetCheck()==1)
num5[i++]=8;
if(m_check50.GetCheck()==1)
num5[i++]=9;
num_5=i;
}
void CStatDlg::group6()
{
int i=0;
if(m_check51.GetCheck()==1)
num6[i]=0;
if(m_check52.GetCheck()==1)
num6[i++]=1;
if(m_check53.GetCheck()==1)
num6[i++]=2;
if(m_check54.GetCheck()==1)
num6[i++]=3;
if(m_check55.GetCheck()==1)
num6[i++]=4;
if(m_check56.GetCheck()==1)
num6[i++]=5;
if(m_check57.GetCheck()==1)
num6[i++]=6;
if(m_check58.GetCheck()==1)
num6[i++]=7;
if(m_check59.GetCheck()==1)
num6[i++]=8;
if(m_check60.GetCheck()==1)
num6[i++]=9;
num_6=i;
}
void CStatDlg::group7()
{
int i=0;
if(m_check61.GetCheck()==1)
num7[i]=0;
if(m_check62.GetCheck()==1)
num7[i++]=1;
if(m_check63.GetCheck()==1)
num7[i++]=2;
if(m_check64.GetCheck()==1)
num7[i++]=3;
if(m_check65.GetCheck()==1)
num7[i++]=4;
if(m_check66.GetCheck()==1)
num7[i++]=5;
if(m_check67.GetCheck()==1)
num7[i++]=6;
if(m_check68.GetCheck()==1)
num7[i++]=7;
if(m_check69.GetCheck()==1)
num7[i++]=8;
if(m_check70.GetCheck()==1)
num7[i++]=9;
num_7=i;
}
void CStatDlg::display(CString in)
{
m_display1=in;
UpdateData(FALSE);
}
void CStatDlg::count()
{
m_display1.Empty();
m_display2.Empty();
UpdateData(FALSE);
UpdateData();
int total=0;
int i1=0;
int i2=0;
int i3=0;
int i4=0;
int i5=0;
int i6=0;
int i7=0;
if (num_1>0&&num_2>0&&num_3>0&&num_4>0&&num_5>0&&num_6>0&&num_7>0)
{
for(i1=0;i1<num_1;i1++)
{
for(i2=0;i2<num_2;i2++)
{
for(i3=0;i3<num_3;i3++)
{
for(i4=0;i4<num_4;i4++)
{
for(i5=0;i5<num_5;i5++)
{
for(i6=0;i6<num_6;i6++)
{
for(i7=0;i7<num_7;i7++)
{
if (((num1[i1]+num2[i2]+num3[i3]+num4[i4]+num5[i5]+num6[i6]+num7[i7])>=m_where1)&&((num1[i1]+num2[i2]+num3[i3]+num4[i4]+num5[i5]+num6[i6]+num7[i7])<=m_where3))
{
int w=0;
if(num1[i1]%2==0)
{
w++;
}
if(num2[i2]%2==0)
{
w++;
}
if(num3[i3]%2==0)
{
w++;
}
if(num4[i4]%2==0)
{
w++;
}
if(num5[i5]%2==0)
{
w++;
}
if(num6[i6]%2==0)
{
w++;
}
if(num7[i7]%2==0)
{
w++;
}
if(w==m_where2)
{
total++;
m_out.Format(" %d %d %d %d %d %d %d",num1[i1],num2[i2],num3[i3],num4[i4],num5[i5],num6[i6],num7[i7]);
save(m_out);
diaplaytotal(total);
display(m_out);
m_displaytotal.Empty();
}
else
{
continue;
}
}
else
{
continue;
}
}
}
}
}
}
}
}
AfxMessageBox("计算完毕");
}
else
{
AfxMessageBox("输入条件不够7组");
return;
}
}
void CStatDlg::diaplaytotal(int in)
{
m_displaytotal.Format("%d",in);
m_display2=m_displaytotal;
UpdateData(FALSE);
}
void CStatDlg::save(CString in)
{
m_ret=fprintf(fp, "%s\n",in);
if(m_ret<0)
{
AfxMessageBox("文件写入出错");
}
}
void CStatDlg::OnOk2()
{
ShellExecute(this->m_hWnd,"open","king.txt","","",SW_SHOW );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -