📄 matrixdlg.cpp
字号:
// MatrixDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Matrix.h"
#include "MatrixDlg.h"
#include "math.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()
/////////////////////////////////////////////////////////////////////////////
// CMatrixDlg dialog
CMatrixDlg::CMatrixDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMatrixDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMatrixDlg)
m_a11 = 0.0f;
m_a21 = 0.0f;
m_a23 = 0.0f;
m_a12 = 0.0f;
m_a13 = 0.0f;
m_a22 = 0.0f;
m_a31 = 0.0f;
m_a32 = 0.0f;
m_a33 = 0.0f;
m_b11 = 0.0f;
m_b12 = 0.0f;
m_b13 = 0.0f;
m_val = 0.0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMatrixDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMatrixDlg)
DDX_Control(pDX, IDC_EDIT14, m_result);
DDX_Control(pDX, IDC_LIST1, m_strList);
DDX_Text(pDX, IDC_EDIT1, m_a11);
DDX_Text(pDX, IDC_EDIT4, m_a21);
DDX_Text(pDX, IDC_EDIT6, m_a23);
DDX_Text(pDX, IDC_EDIT2, m_a12);
DDX_Text(pDX, IDC_EDIT3, m_a13);
DDX_Text(pDX, IDC_EDIT5, m_a22);
DDX_Text(pDX, IDC_EDIT7, m_a31);
DDX_Text(pDX, IDC_EDIT8, m_a32);
DDX_Text(pDX, IDC_EDIT9, m_a33);
DDX_Text(pDX, IDC_EDIT10, m_b11);
DDX_Text(pDX, IDC_EDIT11, m_b12);
DDX_Text(pDX, IDC_EDIT12, m_b13);
DDX_Text(pDX, IDC_EDIT13, m_val);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMatrixDlg, CDialog)
//{{AFX_MSG_MAP(CMatrixDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMatrixDlg message handlers
BOOL CMatrixDlg::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 CMatrixDlg::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 CMatrixDlg::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 CMatrixDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMatrixDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_strList.AddString("k x1[k] x2[k] x3[k]");
m_strList.AddString("0 0.000000 0.000000 0.000000");
float *x1=new float [1000];
float *x2=new float [1000];
float *x3=new float [1000];
int k=0;
x1[0]=x2[0]=x3[0]=0;
while(TRUE)
{
float sum1,sum2,sum3;
sum1=-(m_a12*x2[k]+m_a13*x3[k]);
sum2=-(m_a21*x1[k]+m_a23*x3[k]);
sum3=-(m_a31*x1[k]+m_a32*x2[k]);
k++;
x1[k]=(sum1+m_b11)/m_a11;
x2[k]=(sum2+m_b12)/m_a22;
x3[k]=(sum3+m_b13)/m_a33;
float sub1,sub2,sub3;
sub1=fabs(x1[k]-x1[k-1]);
sub2=fabs(x2[k]-x2[k-1]);
sub3=fabs(x3[k]-x3[k-1]);
float temp=sub1;
if(temp<sub2)temp=sub2;
if(temp<sub3)temp=sub3;
CString str,str1,str2,str3;
str.Format("%d",k);
str1.Format(" %f",x1[k]);
str2.Format(" %f",x2[k]);
str3.Format(" %f",x3[k]);
m_strList.AddString(str+str1+str2+str3);
CString data;
data="x1="+str1;
data+="\r\n";
data+="x2="+str2;
data+="\r\n";
data+="x3="+str3;
if(temp<=m_val)
{
m_result.SetWindowText(data);
return;
}
}
}
void CMatrixDlg::OnButton3()
{
// TODO: Add your control notification handler code here
OnOK();
}
void CMatrixDlg::OnButton2()
{
// TODO: Add your control notification handler code here
m_strList.ResetContent();
m_result.SetWindowText(" ");
}
float CMatrixDlg::Max(float x, float y, float z)
{
float temp=x;
if(temp<y)temp=y;
if(temp<z)temp=z;
return temp;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -