⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bai1dlg.cpp

📁 first simple MCF exercise
💻 CPP
字号:
// Bai1Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "Bai1.h"
#include "Bai1Dlg.h"
#include "dataSV.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()

/////////////////////////////////////////////////////////////////////////////
// CBai1Dlg dialog

CBai1Dlg::CBai1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBai1Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBai1Dlg)
	m_mssv = _T("");
	m_hoten = _T("");
	m_sel = -1;
	m_khoa = _T("");
	m_vmonkhac = _T("");
	m_chitiet = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CBai1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBai1Dlg)
	DDX_Control(pDX, IDC_LIST_DSSV, m_listdssv);
	DDX_Control(pDX, IDC_EDIT_MONKHAC, m_cmonkhac);
	DDX_Control(pDX, IDC_CHECK_MONKHAC, m_monkhac);
	DDX_Control(pDX, IDC_CHECK_LTHDT, m_lthdt);
	DDX_Control(pDX, IDC_CHECK_DOHOA, m_dohoa);
	DDX_Control(pDX, IDC_CHECK_CTDL, m_ctdl);
	DDX_Control(pDX, IDC_CHECK_CSDL, m_csdl);
	DDX_Text(pDX, IDC_EDIT_MSSV, m_mssv);
	DDX_Text(pDX, IDC_EDIT_HOTEN, m_hoten);
	DDX_Radio(pDX, IDC_RADIO_NAM, m_sel);
	DDX_CBString(pDX, IDC_COMBO_KHOA, m_khoa);
	DDX_Text(pDX, IDC_EDIT_MONKHAC, m_vmonkhac);
	DDX_Text(pDX, IDC_STATIC_CHITIET, m_chitiet);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBai1Dlg, CDialog)
	//{{AFX_MSG_MAP(CBai1Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_THOAT, OnButtonThoat)
	ON_BN_CLICKED(IDC_CHECK_MONKHAC, OnCheckMonkhac)
	ON_BN_CLICKED(IDC_BUTTON_THEM, OnButtonThem)
	ON_LBN_SELCHANGE(IDC_LIST_DSSV, OnSelchangeListDssv)
	ON_BN_CLICKED(IDC_BUTTON_SVMOI, OnButtonSvmoi)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBai1Dlg message handlers

BOOL CBai1Dlg::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
	m_sel = 0;
	m_khoa = "2005";
	UpdateData(FALSE);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CBai1Dlg::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 CBai1Dlg::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 CBai1Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CBai1Dlg::OnButtonThoat() 
{
	
	// TODO: Add your control notification handler code here
	if( MessageBox("Ban Muon Thoat ?","Exit Dialog",MB_YESNO + MB_ICONQUESTION) == IDYES )
	{
		OnOK();
	}
	
}

void CBai1Dlg::OnCheckMonkhac() 
{
	// TODO: Add your control notification handler code here
	if(m_monkhac.GetCheck() == 1)
		m_cmonkhac.EnableWindow(TRUE);
	else 
		m_cmonkhac.EnableWindow(FALSE);
	
}

void CBai1Dlg::OnButtonThem() 
{

	CString m_str,m_strmonthich;
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);

	CdataSV * m_data;
	POSITION pos;
	for(int i = 0 ; i < m_arraySV.GetCount() ; i++)
	{
		pos = m_arraySV.FindIndex(i);
		m_data = (CdataSV * ) m_arraySV.GetAt(pos);
		if ( m_data->MSSV == m_mssv ) 
		{
			MessageBox("MSSV nay da co roi xin vui long kiem tra lai","MSSV Trung",MB_OK + MB_ICONEXCLAMATION);
			return;
		}
	}


	m_str.Format("%s - %s ",m_mssv,m_hoten);
	m_listdssv.AddString(m_str);

	CString strbuff;
	strbuff = m_strmonthich;
	if (m_csdl.GetCheck() == 1) m_strmonthich.Format(" %s \n \t %s ",strbuff,"Co So Du Lieu");
	strbuff = m_strmonthich;
	if (m_ctdl.GetCheck() == 1) m_strmonthich.Format(" %s \n \t %s ",strbuff,"Cau Truc Du Lieu");
	strbuff = m_strmonthich;
	if (m_lthdt.GetCheck() == 1) m_strmonthich.Format(" %s \n \t %s ",strbuff,"Lap Trinh Huong Doi Tuong");
	strbuff = m_strmonthich;
	if (m_dohoa.GetCheck() == 1) m_strmonthich.Format(" %s \n \t %s ",strbuff,"Do Hoa");
	strbuff = m_strmonthich;
	if (m_monkhac.GetCheck() == 1) m_strmonthich.Format(" %s \n \t %s ",strbuff,m_vmonkhac);
	
	m_arraySV.AddTail(new CdataSV(m_mssv,m_hoten,m_sel,m_khoa,m_strmonthich));
	UpdateData(FALSE);	
}

void CBai1Dlg::OnSelchangeListDssv() 
{
	// TODO: Add your control notification handler code here
	int a = m_listdssv.GetCurSel();
	POSITION pos = m_arraySV.FindIndex(a);
	CdataSV * m_data = (CdataSV * ) m_arraySV.GetAt(pos);
	
	CString m_str;
	CString phai = (m_data->Phai == 0)?"Nam":"Nu";

	m_str.Format(" MSSV : %s \n Ho Ten: %s \n Phai: %s \n Khoa: %s \n Mon Hoc Ua Thich: %s \n", 
					m_data->MSSV, m_data->HoTen,phai,m_data->Khoa,m_data->MonThich);
	m_chitiet = m_str;
	UpdateData(FALSE);
}

void CBai1Dlg::OnButtonSvmoi() 
{
	// TODO: Add your control notification handler code here
	m_mssv = "";
	m_hoten = "";
	m_sel = 0;
	m_khoa = "2005";
	m_vmonkhac = "";
	m_csdl.SetCheck(0);
	m_ctdl.SetCheck(0);
	m_lthdt.SetCheck(0);
	m_dohoa.SetCheck(0);
	m_monkhac.SetCheck(0);
	CBai1Dlg::OnCheckMonkhac();

	UpdateData(FALSE);
	
}

void CBai1Dlg::OnButtonExit() 
{
	// TODO: Add your control notification handler code here
	
}

void CBai1Dlg::OnChangeEdit() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -