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

📄 kechengshejixueshengxinxidlg.cpp

📁 数据结构课程设计 图形界面 单链表和排序的应用
💻 CPP
字号:
// kechengshejixueshengxinxiDlg.cpp : implementation file
//

#include "stdafx.h"
#include "kechengshejixueshengxinxi.h"
#include "kechengshejixueshengxinxiDlg.h"
#include  "SearchDlg.h"
#include  "DeleteDlg.h"
#include  "CreateDlg.h"

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

#include"xueshengxinxi.h"
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CKechengshejixueshengxinxiDlg dialog

CKechengshejixueshengxinxiDlg::CKechengshejixueshengxinxiDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CKechengshejixueshengxinxiDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CKechengshejixueshengxinxiDlg)
	m_mainstr = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CKechengshejixueshengxinxiDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CKechengshejixueshengxinxiDlg)
	DDX_Text(pDX, IDC_EDIT8, m_mainstr);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CKechengshejixueshengxinxiDlg, CDialog)
	//{{AFX_MSG_MAP(CKechengshejixueshengxinxiDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_CREATE, OnCreate)
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	ON_BN_CLICKED(IDC_INSERT, OnInsert)
	ON_BN_CLICKED(IDC_PRINT, OnPrint)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_COUNT, OnCount)
	ON_BN_CLICKED(IDC_PAIXU, OnPaixu)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CKechengshejixueshengxinxiDlg message handlers

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


	struct student *head; 
void CKechengshejixueshengxinxiDlg::OnCreate() 
{
	// TODO: Add your control notification handler code here


	head=creat();
	char p[200];
	strcpy(p,print(head));

	CString str;
	str.Format("%s ",p);
	m_mainstr=str;
	UpdateData(FALSE);
}

void CKechengshejixueshengxinxiDlg::OnSearch() 
{
	// TODO: Add your control notification handler code here
	long search_num;
	//printf("\ninput the searched number(输入查询学号):");
	//scanf("%ld",&search_num);
	CSearchDlg dlg;
	if(dlg.DoModal()==IDOK)
		search_num=dlg.m_num;
	else return ;
	//printf("要查询的学生信息如下:\n");
	while(search_num!=0)
	{
		head=search(head,search_num);                                   
		//printf("\ninput the searched number(输入查询学号):");
		//scanf("%ld",&search_num);
		if(dlg.DoModal()==IDOK)
		search_num=dlg.m_num;
		else return ;
	}
}

void CKechengshejixueshengxinxiDlg::OnInsert() 
{
	// TODO: Add your control notification handler code here
	//printf("\ninput the inserted record(输入要插入的学生信息,输入数据如:学号 姓名 性别 年龄 分数):");
	struct student *stu; 
	stu=(struct student*)malloc(LEN); 
	//scanf("%ld%s%s%ld%ld",&stu->num,&stu->name,&stu->sex,&stu->age,&stu->score); 
	CCreateDlg dlg;
	if(dlg.DoModal()==IDOK)
	{
		stu->num=dlg.m_num;
		strcpy(stu->name,dlg.m_name);
		stu->score=dlg.m_score;
		strcpy(stu->sex,dlg.m_sex);
		stu->age=dlg.m_age;
	}
	else return ;
	while(stu->num!=0) 
	{  
		head=insert(head,stu); 
		//print(head); 
			OnPrint();
		//printf("input the inserted record(输入要插入的学生信息):"); 
		stu=(struct student*)malloc(LEN);
		if(dlg.DoModal()==IDOK)
		{
			stu->num=dlg.m_num;
			strcpy(stu->name,dlg.m_name);
			stu->score=dlg.m_score;
			strcpy(stu->sex,dlg.m_sex);
			stu->age=dlg.m_age;
		}
		else return ;
	}
	//printf("插入数据后学生链表如下:\n");
	//print(head);	//
	//OnPrint();
}

void CKechengshejixueshengxinxiDlg::OnPrint() 
{
	// TODO: Add your control notification handler code here
	char p[200];
	strcpy(p,print(head));

	CString str;
	str.Format("%s ",p);
	m_mainstr=str;
	UpdateData(FALSE);	
}

void CKechengshejixueshengxinxiDlg::OnDelete() 
{
	// TODO: Add your control notification handler code here
	//printf("\ninput the deleted number(输入删除学号):");
	//scanf("%ld",&del_num);
	long del_num; 
	CDeleteDlg dlg;
	if(dlg.DoModal()==IDOK)
	{
		del_num=dlg.m_num;
	}
	else return ;
	//printf("删除后学生链表如下:\n");
	while(del_num!=0)
	{
		head=del(head,del_num);
		char p[200];
		strcpy(p,print(head));		
		CString str;
		str.Format("删除后学生链表如下:\r\n%s ",p);
		m_mainstr=str;
		UpdateData(FALSE);
		//printf("input the deleted number(输入删除学号):");
		//scanf("%ld",&del_num);
		if(dlg.DoModal()==IDOK)
		{
			del_num=dlg.m_num;
		}
		else return ;
	}	
}

void CKechengshejixueshengxinxiDlg::OnCount() 
{
	// TODO: Add your control notification handler code here
	count(head);
}

void CKechengshejixueshengxinxiDlg::OnPaixu() 
{
	// TODO: Add your control notification handler code here
	struct student *q=paixu(head);
	char p[200];
	strcpy(p,print(q));		
	CString str;
	str.Format("排序后学生链表如下:\r\n%s ",p);
	m_mainstr=str;
	UpdateData(FALSE);
	head=q;
}

void CKechengshejixueshengxinxiDlg::OnSave()  //保存文件
{
	// TODO: Add your control notification handler code here
	int lenth=m_mainstr.GetLength();//获得字符串长度
	char charch[2768];
    CFileException fe;
    BOOL bFileIsOpen = FALSE;
	CFile destFile;
	
	char szFilter[]="ALL Files(*.*)\0*.*\0Test Files(*.txt)\0*.txt\0Test Files(*.dat)\0*.dat\0\0";
	CString m_namee,msg="文件保存在:";
	CFileDialog dlg(false);//显示对话框 
	dlg.m_ofn.lpstrFilter=(LPSTR)szFilter;//初始化对话框
    CString filename=_T("dyp.txt");
	strcpy(dlg.m_ofn.lpstrFile,filename);//保存文件时的默认文件名
	if(dlg.DoModal()==IDOK)
	{
		msg+=dlg.GetPathName();
		m_namee=dlg.GetPathName();
		MessageBox(msg);
	}
	else goto end;
	
	//用从文件保存对话框中得到的文件名在指定位置创建文件
	
    if( !( bFileIsOpen = destFile.Open( m_namee, CFile::modeCreate | 
        CFile::modeWrite | CFile::typeBinary, &fe ) ) )
    {
        TCHAR strCause[256];
        fe.GetErrorMessage( strCause, 255 );
		
		CString strerror1;
		strerror1.Format("保存文件时出现了错误!!详细错误:File name = %s,Cause = %s,m_cause = %d,m_IOsError = %d ",
			fe.m_strFileName, strCause, fe.m_cause, fe.m_lOsError );
		MessageBox(strerror1,"错误",MB_OK);	
		//exit(0);//防止出现错误的,可略去
    }
	
	strcpy(charch,m_mainstr.GetBuffer(0));
	destFile.Write(charch,lenth);
	destFile.Close();
end:;
}
	

⌨️ 快捷键说明

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