📄 fengshudlg.cpp
字号:
// FengShuDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FengShu.h"
#include "FengShuDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CFengShuDlg dialog
CFengShuDlg::CFengShuDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFengShuDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFengShuDlg)
m_xx = 0;
m_ax = 0;
m_ay = 0;
m_bx = 0;
m_by = 0;
m_mm = 0;
m_nn = 0;
m_yy = 0;
m_zz = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFengShuDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFengShuDlg)
DDX_Text(pDX, IDC_XX, m_xx);
DDX_Text(pDX, IDC_AX, m_ax);
DDX_Text(pDX, IDC_AY, m_ay);
DDX_Text(pDX, IDC_BX, m_bx);
DDX_Text(pDX, IDC_BY, m_by);
DDX_Text(pDX, IDC_MM, m_mm);
DDX_Text(pDX, IDC_NN, m_nn);
DDX_Text(pDX, IDC_YY, m_yy);
DDX_Text(pDX, IDC_ZZ, m_zz);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFengShuDlg, CDialog)
//{{AFX_MSG_MAP(CFengShuDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_SUB, OnSub)
ON_BN_CLICKED(IDC_MUL, OnMul)
ON_BN_CLICKED(IDC_DIV, OnDiv)
ON_BN_CLICKED(IDCANCEL2, OnClear)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFengShuDlg message handlers
BOOL CFengShuDlg::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 CFengShuDlg::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 CFengShuDlg::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 CFengShuDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFengShuDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(TRUE);
switch (flag)
{
case 1: //加法运算
tempa=m_bx*m_by; //通分
tempb=m_ax*m_by+m_bx*m_ay;
//分子分母进行约分,若有进位,记录下来
if (tempa>tempb) //分母大于分子
{tempc=tempa;
tempd=tempb;
for (i=1;i<=tempd;i++)
{
if ((tempc%i==0)&&(tempd%i==0))
{
tempc=tempc/i;
tempd=tempd/i;
i=1;
}
}
tempe=0; //进位为0
tempa=tempc;
tempb=tempd;
}
else
{
if(tempa<tempb) //分母小于分子
{tempc=tempb;
tempd=tempa;
for (i=1;i<=tempd;i++)
{
if ((tempc%i==0)&&(tempd%i==0))
{
tempc=tempc/i;
tempd=tempd/i;
i=1;
}
}
tempe=tempc/tempd; //进位为分子除以分母的商
tempc=tempc%tempd;
tempa=tempd;
tempb=tempc;
}
if(tempa==tempb) //分母等于分子
{
tempe=1;
tempb=0;
}
}
//得出分母和分子的结果
m_zz=m_xx+m_yy+tempe;
m_mm=tempb;
m_nn=tempa;
break;
case 2: //减法运算
tempa=m_bx*m_by; //通分
while (m_ax*m_by<m_bx*m_ay) //分数部分减不够的,从整数部分借一再减,若还减不够,再借,,,
{
m_xx=m_xx-1;
m_ax=1*m_bx+m_ax;
}
tempb=m_ax*m_by-m_bx*m_ay;
//分子分母进行约分,若有进位,记录下来
if (tempa>tempb) //分母大于分子
{tempc=tempa;
tempd=tempb;
for (i=1;i<=tempd;i++)
{
if ((tempc%i==0)&&(tempd%i==0))
{
tempc=tempc/i;
tempd=tempd/i;
i=1;
}
}
tempe=0; //进位为0
tempa=tempc;
tempb=tempd;
}
else
{
if(tempa<tempb) //分母小于分子
{tempc=tempb;
tempd=tempa;
for (i=1;i<=tempd;i++)
{
if ((tempc%i==0)&&(tempd%i==0))
{
tempc=tempc/i;
tempd=tempd/i;
i=1;
}
}
tempe=tempc/tempd; //进位为分子除以分母的商
tempc=tempc%tempd;
tempa=tempd;
tempb=tempc;
}
if(tempa==tempb) //分母等于分子
{
tempe=1;
tempb=0;
}
}
//得出分母和分子的结果
m_zz=m_xx-m_yy+tempe;
m_mm=tempb;
m_nn=tempa;
break;
case 3:
tempa=m_bx*m_by;
m_ax=m_xx*m_bx+m_ax;
m_ay=m_yy*m_by+m_ay;
m_xx=0;
m_yy=0;
tempb=m_ax*m_ay;
//分子分母进行约分,若有进位,记录下来
if (tempa>tempb) //分母大于分子
{tempc=tempa;
tempd=tempb;
for (i=1;i<=tempd;i++)
{
if ((tempc%i==0)&&(tempd%i==0))
{
tempc=tempc/i;
tempd=tempd/i;
i=1;
}
}
tempe=0; //进位为0
tempa=tempc;
tempb=tempd;
}
else
{
if(tempa<tempb) //分母小于分子
{tempc=tempb;
tempd=tempa;
for (i=1;i<=tempd;i++)
{
if ((tempc%i==0)&&(tempd%i==0))
{
tempc=tempc/i;
tempd=tempd/i;
i=1;
}
}
tempe=tempc/tempd; //进位为分子除以分母的商
tempc=tempc%tempd;
tempa=tempd;
tempb=tempc;
}
if(tempa==tempb) //分母等于分子
{
tempe=1;
tempb=0;
}
}
//得出分母和分子的结果
m_zz=tempe;
m_mm=tempb;
m_nn=tempa;
break;
case 4:
m_ax=m_xx*m_bx+m_ax;
m_ay=m_yy*m_by+m_ay;
tempa=m_bx*m_ay;
tempb=m_ax*m_by;
//分子分母进行约分,若有进位,记录下来
if (tempa>tempb) //分母大于分子
{tempc=tempa;
tempd=tempb;
for (i=1;i<=tempd;i++)
{
if ((tempc%i==0)&&(tempd%i==0))
{
tempc=tempc/i;
tempd=tempd/i;
i=1;
}
}
tempe=0; //进位为0
tempa=tempc;
tempb=tempd;
}
else
{
if(tempa<tempb) //分母小于分子
{tempc=tempb;
tempd=tempa;
for (i=1;i<=tempd;i++)
{
if ((tempc%i==0)&&(tempd%i==0))
{
tempc=tempc/i;
tempd=tempd/i;
i=1;
}
}
tempe=tempc/tempd; //进位为分子除以分母的商
tempc=tempc%tempd;
tempa=tempd;
tempb=tempc;
}
if(tempa==tempb) //分母等于分子
{
tempe=1;
tempb=0;
}
}
//得出分母和分子的结果
m_zz=tempe;
m_mm=tempb;
m_nn=tempa;
break;
}
UpdateData(FALSE);
}
void CFengShuDlg::OnAdd()
{
// TODO: Add your control notification handler code here
flag=1;
}
void CFengShuDlg::OnSub()
{
// TODO: Add your control notification handler code here
flag=2;
}
void CFengShuDlg::OnMul()
{
// TODO: Add your control notification handler code here
flag=3;
}
void CFengShuDlg::OnDiv()
{
// TODO: Add your control notification handler code here
flag=4;
}
void CFengShuDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CFengShuDlg::OnClear()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_xx=0;
m_ax=0;
m_bx=0;
m_yy=0;
m_ay=0;
m_by=0;
m_zz=0;
m_mm=0;
m_nn=0;
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -