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

📄 eddlg.cpp

📁 文件用于mfc的设计编写
💻 CPP
字号:
// edDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ed.h"
#include "edDlg.h"
#include "Student.h"
#include "WelDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CStudent stu[10];
int i=0;
CString name;

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CEdDlg dialog

CEdDlg::CEdDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CEdDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEdDlg)
	m_sex = -1;
	m_ch1 = FALSE;
	m_ch2 = FALSE;
	m_ch3 = FALSE;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CEdDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEdDlg)
	DDX_Control(pDX, IDC_LISTSHOW, m_listshow);
	DDX_Radio(pDX, IDC_RADIO1, m_sex);
	DDX_Check(pDX, IDC_CHECK1, m_ch1);
	DDX_Check(pDX, IDC_CHECK2, m_ch2);
	DDX_Check(pDX, IDC_CHECK3, m_ch3);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CEdDlg, CDialog)
	//{{AFX_MSG_MAP(CEdDlg)
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTONADD, OnButtonadd)
	ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
	ON_COMMAND(ID_ADD, OnAdd)
	ON_COMMAND(ID_WEL, OnWel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEdDlg message handlers

BOOL CEdDlg::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







	if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
{
	TRACE0("Failed to Create Dialog Toolbar\n");
	EndDialog(IDCANCEL);
}
//	SetIcon(m_hIcon, TRUE);			// Set big icon
//	SetIcon(m_hIcon, FALSE);		// Set small icon
//设置工具栏
	CRect	rcClientOld; // Old Client Rect
	CRect	rcClientNew; // New Client Rect with Tollbar Added
	GetClientRect(rcClientOld); // Retrive the Old Client WindowSize
// Called to reposition and resize control bars in the client area of a window
// The reposQuery FLAG does not really traw the Toolbar.  It only does the calculations.
// And puts the new ClientRect values in rcClientNew so we can do the rest of the Math.
	RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0,reposQuery,rcClientNew);

// All of the Child Windows (Controls) now need to be moved so the Tollbar does not cover them up.
// Offest to move all child controls after adding Tollbar
	CPoint ptOffset(rcClientNew.left-rcClientOld.left,
		rcClientNew.top-rcClientOld.top);

	CRect	rcChild;
	CWnd*	pwndChild = GetWindow(GW_CHILD);  //Handle to the Dialog Controls
	while(pwndChild) // Cycle through all child controls
	{
		pwndChild->GetWindowRect(rcChild); //  Get the child control RECT
		ScreenToClient(rcChild); 
		rcChild.OffsetRect(ptOffset); // Changes the Child Rect by the values of the claculated offset
		pwndChild->MoveWindow(rcChild,FALSE); // Move the Child Control
		pwndChild = pwndChild->GetNextWindow();
	}

	CRect	rcWindow;
	GetWindowRect(rcWindow); // Get the RECT of the Dialog
	rcWindow.right += rcClientOld.Width() - rcClientNew.Width(); // Increase width to new Client Width
	rcWindow.bottom += rcClientOld.Height() - rcClientNew.Height(); // Increase height to new Client Height
	MoveWindow(rcWindow,FALSE); // Redraw Window

// Now we REALLY Redraw the Toolbar
	RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);











	
	// TODO: Add extra initialization here
/*	((CComboBox*)GetDlgItem(IDC_COMBO1))->AddString("宣传委员");
	((CComboBox*)GetDlgItem(IDC_COMBO1))->SetCurSel(0);
	m_sex=0;
	m_ch1=TRUE;
	m_ch2=TRUE;

	UpdateData(FALSE);*/

//	GetMenu()->EnableMenuItem(0,MF_BYPOSITION | MF_DISABLED | MF_GRAYED   );

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

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

void CEdDlg::OnButtonadd() 
{
	// TODO: Add your control notification handler code here
	CString strname,strnum,strscore,str,str1;
	GetDlgItem(IDC_NAME)->GetWindowText(strname);
	GetDlgItem(IDC_NUM)->GetWindowText(strnum);
	GetDlgItem(IDC_SCORE)->GetWindowText(strscore);

	str=strname+","+strnum+","+strscore;
	UpdateData();
	if(m_sex==0)
		str+=",男";
	else
		str+=",女";
	if(m_ch1)
	{
		str+=",foot";
	}
	if(m_ch2)
	{
		str+=",bass";
	}
	if(m_ch3)
	{
		str+=",voll";
	}

	int index;
	index=((CComboBox*)GetDlgItem(IDC_COMBO1))->GetCurSel();
	((CComboBox*)GetDlgItem(IDC_COMBO1))->GetLBText(index,str1);
	str+=","+str1;
	m_listshow.AddString(str);

	stu[i]=CStudent(strnum,strname,(float)atof(strscore));
	i++;

	GetMenu()->GetSubMenu(0)->CheckMenuItem(0,MF_BYPOSITION | MF_CHECKED  );

	m_wndToolBar.GetToolBarCtrl().EnableButton(ID_ADD,FALSE);
	


}



void CEdDlg::OnButtonDelete() 
{
	// TODO: Add your control notification handler code here
	CString fnum;
	GetDlgItem(IDC_NUM)->GetWindowText(fnum);
/*	for(int j=0;j<i;j++)
		if(stu[j].m_num==fnum)
		{
			if(IDYES==MessageBox("是否删除?","删除",MB_ICONQUESTION |MB_YESNO))
			{
				for(int k=j;k<i-1;k++)
					stu[k]=stu[k+1];
				i--;
				m_listshow.DeleteString(j);

			}
				return;
		}

		if(j==i)MessageBox("无此人");*/

	int cursel=m_listshow.GetCurSel();
	if(cursel==-1)
	{
		MessageBox("没有选中");
		return;
	}
	else
	{
			if(IDYES==MessageBox("是否删除?","删除",MB_ICONQUESTION |MB_YESNO))
			{
				for(int k=cursel;k<i-1;k++)
					stu[k]=stu[k+1];
				i--;
				m_listshow.DeleteString(cursel);

			}
				return;

	}


	
}

void CEdDlg::OnAdd() 
{
	// TODO: Add your command handler code here
	OnButtonadd();
}

void CEdDlg::OnWel() 
{
	// TODO: Add your command handler code here

	GetDlgItem(IDC_NAME)->GetWindowText(name);
	CWelDlg weldlg;
	weldlg.DoModal();
	
}

⌨️ 快捷键说明

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