📄 wenddlg.cpp
字号:
// WendDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DeformAdj.h"
#include "WendDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CString directory;
extern CString projname;
/////////////////////////////////////////////////////////////////////////////
// CWendDlg dialog
CWendDlg::CWendDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWendDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWendDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CWendDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWendDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
DDX_GridControl(pDX,IDC_WEND_GRID,m_Grid);
}
BEGIN_MESSAGE_MAP(CWendDlg, CDialog)
//{{AFX_MSG_MAP(CWendDlg)
ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
ON_BN_CLICKED(IDC_DELETE_BUTTON, OnDeleteButton)
ON_BN_CLICKED(IDC_PRINT_BUTTON, OnPrintButton)
ON_BN_CLICKED(IDC_SAVE_BUTTON, OnSaveButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWendDlg message handlers
BOOL CWendDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
modiflag = true;
char ptitle[3][15]=
{
_T("序号"),_T("观测时间"),_T("温度(°)"),
};
CString fname;
long m_times;
int m_id=0;
int j=1;
double m_t;
fname = directory + "wend.tme" ;
FILE *fp;
fp=fopen(fname,"r");
if (fp == NULL)
{
AfxMessageBox("无法找到已知数据文件,数据读入失败!");
OnCancel();
return false;
}
while(!feof(fp))
{
fscanf(fp,"%d %d %lf\n",&m_id,&m_times,&m_t);
j=j+1;
}
m_nRows = j;
m_nCols = 3;
if (m_id == 0)
{
m_nRows = 1;
}
m_Grid.SetRowCount(m_nRows);
m_Grid.SetColumnCount(m_nCols);
for (j=1;j<m_nRows;j++)
m_Grid.SetRowHeight(j,17);
m_Grid.SetFixedColumnCount(1);
m_Grid.SetFixedRowCount(1);
m_Grid.SetEditable(true);
m_Grid.SetTextBkColor(RGB(0xFF,0xFF,0xE0));
m_Grid.SetColumnWidth(0,40);
m_Grid.SetColumnWidth(1,60);
m_Grid.SetColumnWidth(2,70);
for (int col=0;col<m_nCols;col++)
{
GV_ITEM item;
item.mask=GVIF_TEXT|GVIF_FORMAT;
item.nFormat=DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|ES_CENTER;
item.row=0;
item.col=col;
item.szText.Format(_T("%s"),ptitle[col]);
m_Grid.SetItem(&item);
}
fseek(fp,0L,SEEK_SET);
int i=1;
while(!feof(fp))
{
GV_ITEM item;
item.mask=GVIF_TEXT|GVIF_FORMAT;
item.nFormat=DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|ES_CENTER;
fscanf(fp,"%d %d %lf\n",&m_id,&m_times,&m_t);
item.row=i;
item.col=0;
item.szText.Format(_T("%d"),m_id);
m_Grid.SetItem(&item);
item.col=1;
item.szText.Format(_T("%d"),m_times);
m_Grid.SetItem(&item);
item.col=2;
item.szText.Format(_T("%.4lf"),m_t);
m_Grid.SetItem(&item);
i=i+1;
}
fclose(fp);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CWendDlg::OnAddButton()
{
// TODO: Add your control notification handler code here
CString heading;
heading.Format(_T("%d"),m_nRows);
m_Grid.InsertRow(heading,-1);
m_Grid.SetRowHeight(m_nRows,17);
m_Grid.Invalidate();
m_nRows=m_nRows+1;
m_Grid.SetFocusCell(m_nRows-1,1);
m_Grid.SetScrollPos32(1,17*m_nRows);
m_Grid.Invalidate();
modiflag = false;
}
void CWendDlg::OnDeleteButton()
{
// TODO: Add your control notification handler code here
int row = m_Grid.GetFocusCell().row;
if (row >= 0)
{
m_Grid.DeleteRow(row);
m_nRows = m_nRows - 1;
for (int i=1;i<m_nRows;i++)
{
GV_ITEM item;
item.mask=GVIF_TEXT|GVIF_FORMAT;
item.nFormat=DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS|ES_CENTER;
item.row = i;
item.col=0;
item.szText.Format(_T("%d"),i);
m_Grid.SetItem(&item);
}
m_Grid.Invalidate();
}
else
{
AfxMessageBox("请选择要删除的行!");
return;
}
modiflag = false;
}
void CWendDlg::OnPrintButton()
{
// TODO: Add your control notification handler code here
m_Grid.Print();
}
void CWendDlg::OnSaveButton()
{
// TODO: Add your control notification handler code here
CString fname,fnewname,text;
int m_id;
long m_times;
double m_t;
fname = directory + "wend.tme" ;
FILE *fp;
fp=fopen(fname,"w");
if (fp == NULL)
{
AfxMessageBox("无法找到已知数据文件,数据写入失败!");
return;
}
for (int row = 1; row < m_Grid.GetRowCount(); row++)
{
text = m_Grid.GetItemText(row,0);
if (text == "")
{
AfxMessageBox("请在单元格中输入数据!");
fclose(fp);
return;
}
m_id = atoi(text);
text = m_Grid.GetItemText(row,1);
if (text == "")
{
AfxMessageBox("请在单元格中输入数据!");
fclose(fp);
return;
}
m_times = atol(text);
text = m_Grid.GetItemText(row,2);
if (text == "")
{
AfxMessageBox("请在单元格中输入数据!");
fclose(fp);
return;
}
m_t = atof(text);
fprintf(fp,"%d %d %lf\n",m_id,m_times,m_t);
}
fclose(fp);
modiflag = true;
}
void CWendDlg::OnCancel()
{
// TODO: Add extra cleanup here
if ( modiflag == false )
{
int retuvalu = AfxMessageBox("你需要保存数据吗?",MB_OK|MB_OKCANCEL);
if (retuvalu == IDOK )
{
OnSaveButton();
}
}
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -