📄 学分绩点计算dlg.cpp
字号:
// 学分绩点计算Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "学分绩点计算.h"
#include "学分绩点计算Dlg.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()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
m_num=1;
m_allscore=0.0;
m_aver=0.0;
m_jidian=0.0;
m_min=0.0;
m_max=0.0;
m_score = _T("");
m_timenow = _T("");
num=0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_COMBO1, m_xuefencb);
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Control(pDX, IDC_LIST2, m_show);
DDX_Text(pDX, IDC_STATIC_num, m_num);
DDV_MinMaxInt(pDX, m_num, 1, 200);
DDX_Text(pDX, IDC_EDIT_allscore, m_allscore);
DDX_Text(pDX, IDC_EDIT_aver, m_aver);
DDX_Text(pDX, IDC_EDIT_jidian, m_jidian);
DDX_Text(pDX, IDC_EDIT_min, m_min);
DDX_Text(pDX, IDC_EDIT4_max, m_max);
DDX_Text(pDX, IDC_EDIT2, m_score);
DDV_MaxChars(pDX, m_score, 3);
DDX_Text(pDX, IDC_STATIC_TIME, m_timenow);
DDV_MaxChars(pDX, m_timenow, 50);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON5, OnButton4)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_NOTIFY(NM_CLICK, IDC_LIST, OnClickList)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::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
for(int i=0;i<200;i++)
{
char temp[10];
itoa(i+1,temp,10);
m_kms[i]="第"+CString(temp)+CString(" 科未知科目名称");
}
DWORD dwStyle = m_list.GetStyle();
dwStyle |= LVS_EX_GRIDLINES | LVS_SHOWSELALWAYS | LVS_LIST;
dwStyle &= LVS_EX_TRACKSELECT;
m_list.SetExtendedStyle(dwStyle);
m_list.SetBkColor(RGB(240,247,233));
m_list.SetTextBkColor(RGB(240,247,233));
// m_list.SetTextColor(RGB(255,0,0));
// HDC hdc;
// m_list.SetBkColor(RGB(200,150,100));
// m_list.SetBackColor(RGB(255,0,0));
m_list.InsertColumn(0,"课程名称",LVCFMT_CENTER,120);
m_list.InsertColumn(1,"该科成绩",LVCFMT_CENTER,100);
m_list.InsertColumn(2,"该科学分",LVCFMT_CENTER,95);
SetTimer(1,1000,NULL);
/* int nItem;
for(i=0;i<200;i++)
{
nItem=m_list.InsertItem(i,_T(m_kms[i]));
}*/
GetWindowRect(&m_rcWindow);
GetClientRect(&m_rcClient);
m_nTitleWideth=(m_rcWindow.bottom-m_rcWindow.top)-(m_rcClient.bottom-m_rcClient.top);
SetWindowPos(&wndTop,0,0,374,420+m_nTitleWideth,SWP_NOMOVE);
GetDlgItem(IDC_BUTTON7)->EnableWindow(0);
GetDlgItem(IDC_BUTTON6)->EnableWindow(0);
GetDlgItem(IDC_EDIT2)->SetFocus();
//this->SetBCColor(RGB(255,0,0));
m_xuefencb.ResetContent();
/* for(int mmm=0;mmm<20;mmm++)
{
CString temp;
temp.Format("%ld",double(mmm/2.0));
m_xuefencb.InsertString(mmm,temp);
}*/
m_xuefencb.InsertString(0,_T("0.0"));
m_xuefencb.InsertString(1,_T("0.5"));
m_xuefencb.InsertString(2,_T("1.0"));
m_xuefencb.InsertString(3,_T("1.5"));
m_xuefencb.InsertString(4,_T("2.0"));
m_xuefencb.InsertString(5,_T("2.5"));
m_xuefencb.InsertString(6,_T("3.0"));
m_xuefencb.InsertString(7,_T("3.5"));
m_xuefencb.InsertString(8,_T("4.0"));
m_xuefencb.InsertString(9,_T("5.5"));
m_xuefencb.InsertString(10,_T("5.0"));
m_xuefencb.InsertString(11,_T("5.5"));
m_xuefencb.InsertString(12,_T("6.0"));
m_xuefencb.InsertString(13,_T("6.5"));
m_xuefencb.InsertString(14,_T("7.0"));
m_xuefencb.InsertString(15,_T("7.5"));
m_xuefencb.InsertString(16,_T("8.0"));
m_xuefencb.InsertString(17,_T("8.5"));
m_xuefencb.InsertString(18,_T("9.0"));
m_xuefencb.InsertString(19,_T("9.5"));
m_xuefencb.InsertString(20,_T("10.0"));
m_xuefencb.InsertString(21,_T("10.5"));
m_xuefencb.InsertString(22,_T("11.0"));
m_xuefencb.InsertString(23,_T("11.5"));
m_xuefencb.SetCurSel(0);
return false; // return TRUE unless you set the focus to a control
}
void CMyDlg::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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::OnButton1() //输入按钮
{
// TODO: Add your control notification handler code here
++num; //科目加
/* if(m_sc[num-1] !=0 || m_xf[num-1] !=0)
{
--num;
}*/
UpdateData(true);
int nn=m_xuefencb.GetCurSel();
switch(nn)
{
case 0:
{
m_xuefen=_T("0.0"); break;
}
case 1:
{
m_xuefen=_T("0.5"); break;
}
case 2:
{
m_xuefen=_T("1.0"); break;
}
case 3:
{
m_xuefen=_T("1.5"); break;
}
case 4:
{
m_xuefen=_T("2.0"); break;
}
case 5:
{
m_xuefen=_T("2.5"); break;
}
case 6:
{
m_xuefen=_T("3.0"); break;
}
case 7:
{
m_xuefen=_T("3.5"); break;
}
case 8:
{
m_xuefen=_T("4"); break;
}
case 9:
{
m_xuefen=_T("4.5"); break;
}
case 10:
{
m_xuefen=_T("5.0"); break;
}
case 11:
{
m_xuefen=_T("5.5"); break;
}
case 12:
{
m_xuefen=_T("6.0"); break;
}
case 13:
{
m_xuefen=_T("6.5"); break;
}
case 14:
{
m_xuefen=_T("7.0"); break;
}
case 15:
{
m_xuefen=_T("7.5"); break;
}
case 16:
{
m_xuefen=_T("8.0"); break;
}
case 17:
{
m_xuefen=_T("8.5"); break;
}
case 18:
{
m_xuefen=_T("9.0"); break;
}
case 19:
{
m_xuefen=_T("9.5"); break;
}
case 20:
{
m_xuefen=_T("10.0"); break;
}
case 21:
{
m_xuefen=_T("10.5"); break;
}
case 22:
{
m_xuefen=_T("11.0"); break;
}
case 23:
{
m_xuefen=_T("11.5"); break;
}
default:
{
GetDlgItem(IDC_COMBO1)->GetWindowText(m_xuefen);
//m_xuefen=0.0;
break;
}
}
if(!atof(m_score) && !atof(m_xuefen)) //如果同时为0
{
if(MessageBox("请确认成绩和学分是否都为0 ?","提示",MB_OKCANCEL|MB_ICONQUESTION)==1)
{
m_sc[num-1] = atof(m_score);
m_cjs[num-1]= "0";
m_xf[num-1] = atof(m_xuefen);
m_xfs[num-1]= "0";
Sshow();
m_score = _T("");
m_xuefen = _T("");
m_num=num;
UpdateData(false);
GetDlgItem(IDC_BUTTON6)->EnableWindow(true);
GetDlgItem(IDC_EDIT2)->SetFocus();
return;
}
else
{
--num;
m_score = _T("");
m_xuefen = _T("");
m_num=num+1;
UpdateData(false);
GetDlgItem(IDC_BUTTON6)->EnableWindow(true);
GetDlgItem(IDC_EDIT2)->SetFocus();
return;
}
}
else //输入不合要求
{
if(atof(m_score) > 100 || atof(m_score) < 0)
{
--num;
m_score = _T("");
UpdateData(false);
MessageBox(" 成绩输入超出范围 请重新输入 \n\n(优:90 良:80 中:75 及格 65) \n\n (范围从 0 ~ 100)","提示",MB_ICONERROR);
GetDlgItem(IDC_EDIT2)->SetFocus();
}
else if(atof(m_xuefen) < 0 || atof(m_xuefen) > 20)
{
--num;
SetDlgItemText(IDC_COMBO1,_T(""));
UpdateData(false);
MessageBox("学分输入超出范围 重新输入 \n\n (范围从 0 ~ 20)","提示",MB_ICONERROR);
GetDlgItem(IDC_COMBO1)->SetFocus();
return;
}
else
{
m_sc[num-1] = atof(m_score);
m_cjs[num-1]= m_score;
if(m_score=="")
{
m_sc[num-1]=0.0;
m_cjs[num-1]= "0";
}
m_xf[num-1] = atof(m_xuefen);
m_xfs[num-1]= m_xuefen;
if(m_xuefen=="")
{
m_xf[num-1]=0.0;
m_xfs[num-1]= "0";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -