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

📄 mainfrm.cpp

📁 一个学生信息管理系统,使用了多中数值算法,有HASH查找,归并排序,堆排序,快速排序,界面也不错
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "StudInfoManager.h"
#include "StudInfoManagerDoc.h"
#include "math.h"
#include "HelpDlg.h"

#include "MainFrm.h"
#include "Splash.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_WM_CLOSE()
	ON_WM_SYSCOMMAND()
	ON_COMMAND(IDM_EXIT, OnExit)
	ON_COMMAND(IDM_HELP, OnHelp)
	ON_COMMAND(IDM_MAIN, OnMain)
	ON_COMMAND(IDM_WORKSPACEBAR, OnWorkspacebar)
	ON_COMMAND(IDM_OUTPUTBAR, OnOutputbar)
	ON_COMMAND(IDM_STOP, OnStop)
	ON_COMMAND(IDM_FILTER, OnFilter)
	ON_COMMAND(IDM_DELETE_ITEM, OnDeleteItem)
	ON_COMMAND(IDM_CLEAR_LIST, OnClearList)
	ON_COMMAND(IDM_SEARCH, OnSearch)
	ON_COMMAND(IDM_DETECT, OnDetect)
	ON_COMMAND(IDM_SYSSET, OnSysset)
	ON_COMMAND(IDM_PWDSET, OnPwdset)
	ON_COMMAND(IDM_HIDE, OnHide)
	//}}AFX_MSG_MAP
    ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
	ON_MESSAGE(WM_HOTKEY,OnHotKey)
END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	m_nCurOutputViewID=0;
	m_pCSearchStatisticsView=0;
	m_pStudInfoManagerView=0;
	m_pStudInfoManagerDoc=0;
	m_strSnfData=
		"------------------------------------------------------------------欢迎使用学生信息管理系统!-----------------------------------------------------------------\r\n\r\n使用说明:\r\n\r\n     适用操作系统:98/2K/XP/NT;\r\n\r\n     更多帮助,请按F1;\r\n\r\n     版权所有:陶善文。请尊重本人劳动成果,切勿反汇编本软件,否则,后果自负!欢迎自由传播本软件。";
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	//创建工具栏
	//-----------------------------------------------------------------------------
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	// TODO: Remove this if you don't want tool tips
	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

	//给工具栏加上文字
	m_wndToolBar.SetButtonText(0,"打开");
	m_wndToolBar.SetButtonText(2,"开始");
	m_wndToolBar.SetButtonText(4,"停止");
	m_wndToolBar.SetButtonText(6,"过滤");
	m_wndToolBar.SetButtonText(7,"删除");
	m_wndToolBar.SetButtonText(8,"清空");
	m_wndToolBar.SetButtonText(9,"搜索");
	m_wndToolBar.SetButtonText(11,"检测");
	m_wndToolBar.SetButtonText(13,"设置");
	m_wndToolBar.SetButtonText(15,"设密");
	m_wndToolBar.SetButtonText(17,"关于");
	m_wndToolBar.SetButtonText(19,"隐藏");
	m_wndToolBar.SetButtonText(20,"离开");
	m_wndToolBar.SetSizes(CSize(42,51),CSize(32,32));
	//-----------------------------------------------------------------------------



	//创建状态栏
	//-----------------------------------------------------------------------------
	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}


	//隐藏状态栏上的进度条
	m_wndStatusBar.SetViewProgress(false);

	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);

	//安装定时器,显示状态栏时间
	SetTimer(ID_DISPTIME,1000,NULL);

	m_wndStatusBar.SetPaneText(0,"就绪",TRUE);

	m_wndStatusBar.SetPaneText(1,"当前信息:10条",TRUE);
	m_wndStatusBar.SetPaneInfo(1,1,m_wndStatusBar.GetPaneStyle(1),150);

	m_wndStatusBar.SetPaneInfo(3,1,m_wndStatusBar.GetPaneStyle(3),50);
	CTime time;
    time=CTime::GetCurrentTime();           //得到当前时间
    CString s=time.Format("%H:%M:%S");      //转换时间格式
    m_wndStatusBar.SetPaneText(3,s,TRUE);   //显示时钟
	//-----------------------------------------------------------------------------


	//创建工作空间栏
    //------------------------------------------------------------------------------
	if( !m_wndWorkSpaceBar.Create(this, ID_VIEW_WORKSPACE,
		_T("工作空间"), CSize(140,200), CBRS_LEFT ))
	{
		TRACE0("Failed to create dialog bar m_wndWorkSpaceBar\n");
		return -1;		// fail to create
	}
	
	// Define the image list to use with the tab control
	m_wndWorkSpaceBar.EnableDockingOnSizeBar( CBRS_ALIGN_ANY );
	EnableDockingSizeBar(CBRS_ALIGN_ANY);
	DockSizeBar(&m_wndWorkSpaceBar );
    //-----------------------------------------------------------------------------


	//创建输出结果栏
	//---------------------------------------------------------------------
	if(!m_wndOutputBar.Create(this, ID_VIEW_OUTPUT,_T("输出"), CSize(310,160), CBRS_BOTTOM))
	{
		TRACE0("Failed to create mybar\n");
		return -1;      // fail to create
	}

	m_wndOutputBar.SetBarStyle(m_wndOutputBar.GetBarStyle() |
            CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC | CBRS_BOTTOM);

	m_wndOutputBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDockingSizeBar(CBRS_ALIGN_ANY);
	DockSizeBar(&m_wndOutputBar);

	//显示输出信息
	m_wndOutputBar.SetEditText(0,m_strSnfData);
    //-----------------------------------------------------------------------------


//	CSizingControlBar::GlobalLoadState(_T("BarState"));
//	LoadBarState(_T("Bar State"));

	//------------添加托盘到任务栏-------------------
	NOTIFYICONDATA tnd;
	tnd.cbSize=sizeof(NOTIFYICONDATA);
	tnd.hWnd=this->m_hWnd;
	tnd.uID=IDR_MAINFRAME;
	tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
 	tnd.uCallbackMessage=WM_ICON_NOTIFY;
	tnd.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	strcpy(tnd.szTip,"☆★学生信息管理系统★☆");
	Shell_NotifyIcon(NIM_ADD,&tnd);

	m_bShow=true;
	//-----------------------------------------------

	//注册热键
	RegisterHotKey(m_hWnd,0xB4EE,MOD_CONTROL | MOD_ALT | MOD_SHIFT,VK_F10);

	// CG: The following line was added by the Splash Screen component.	CSplashWnd::ShowSplashScreen(this);

	m_pCSearchStatisticsView=new CSearchStatisticsView;
	m_pCSearchStatisticsView->Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,rectDefault,this,AFX_IDW_PANE_FIRST+1);

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::ChangeView(int nID)
{
	if(!m_pStudInfoManagerDoc)
		m_pStudInfoManagerDoc=(CStudInfoManagerDoc*)GetActiveDocument();
	CView* pView=GetActiveView();

	switch(nID)
	{
	case 0:
		if(pView->IsKindOf(RUNTIME_CLASS(CStudInfoManagerView)))
		{
			m_pStudInfoManagerView=(CStudInfoManagerView*)pView;
			return;
		}

		m_pStudInfoManagerDoc->AddView(m_pStudInfoManagerView);

		m_pStudInfoManagerView->ShowWindow(true);
		m_pCSearchStatisticsView->ShowWindow(false);

		m_pStudInfoManagerView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
		m_pCSearchStatisticsView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
		
		this->SetActiveView(m_pStudInfoManagerView);
		m_pStudInfoManagerDoc->RemoveView(m_pCSearchStatisticsView);

		break;

	case 1:		
		if(pView->IsKindOf(RUNTIME_CLASS(CStudInfoManagerView)))
			m_pStudInfoManagerView=(CStudInfoManagerView*)pView;
		else
			return;

		m_pStudInfoManagerDoc->AddView(m_pCSearchStatisticsView);
		
		m_pCSearchStatisticsView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
		m_pStudInfoManagerView->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
		
		m_pCSearchStatisticsView->ShowWindow(true);
		m_pStudInfoManagerView->ShowWindow(false);
		
		this->SetActiveView(m_pCSearchStatisticsView);
		m_pStudInfoManagerDoc->RemoveView(m_pStudInfoManagerView);

		//统计
		m_pCSearchStatisticsView->StatisticsBoyGirlCount();
		m_pCSearchStatisticsView->StatisticsPersonAverageMark();
		m_pCSearchStatisticsView->StatisticsGradeAverageAge();
		m_pCSearchStatisticsView->StatisticsCourseAverageMark();
		break;

	default:
		break;
	}

	RecalcLayout();
}

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
//	CSizingControlBar::GlobalSaveState(_T("BarState"));
	int ans=MessageBox("你真的要退出吗?","退出系统",MB_ICONQUESTION | MB_YESNO);
	if(ans==IDYES)
	{
		SaveBarState(_T("Bar State"));

		//注销热键
		UnregisterHotKey(m_hWnd,0XB4EE);
		//动画消失
		AnimateWindow(GetSafeHwnd(),2000,AW_CENTER|AW_HIDE);
		//保存可变栏状态
//		m_wndStatusBar.StopRun();
//		this->OnStop();

		CFrameWnd::OnClose();
	}
	else
		return;
}

void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
	if(nID==SC_MINIMIZE)
	{
		CFrameWnd::OnSysCommand(nID, lParam);
		m_bShow=false;
		AfxGetMainWnd()->ShowWindow(SW_HIDE);//隐藏窗口
	}
	else
		if(nID==SC_CLOSE)
			PostMessage(WM_SYSCOMMAND,SC_MINIMIZE,NULL);
		else 
			if(nID==SC_RESTORE)
			{
				AfxGetMainWnd()->ShowWindow(SW_SHOW);//显示窗口
				CFrameWnd::OnSysCommand(nID, lParam);
				m_bShow=true;
			}
			else
				CFrameWnd::OnSysCommand(nID, lParam);
}

void CMainFrame::OnExit() 
{
	// TODO: Add your command handler code here
	OnClose();
}

UINT CMainFrame::Char2UINT(char* pStr)
{
	UINT uiRet=0;
	UINT uiLen=strlen(pStr);
	UINT i;

	for(i=0;i<uiLen;i++)
		uiRet+=((int)pStr[i]-48)*pow(10,uiLen-i-1);

	return uiRet;
}

StudInfo* CMainFrame::GetStudInfo(File* pFile)
{
	FILE* fp;
	int i;
	StudInfo pStudInfo[10];

	fp=fopen(pFile,"r");
	for(i=0;i<10;i++)
		fread(&pStudInfo[i],sizeof(StudInfo),1,fp);

	fclose(fp);

	return pStudInfo;
}

LRESULT CMainFrame::OnTrayNotification(WPARAM wParam, LPARAM lParam)
{
	UINT uMouseMsg;//鼠标动作

	uMouseMsg=(UINT)lParam;
	if(uMouseMsg==WM_LBUTTONDOWN)//如果是单击左键
	{
		if(m_bShow)
		{
				PostMessage(WM_SYSCOMMAND,SC_MINIMIZE,NULL);
		}
		else
		{
				PostMessage(WM_SYSCOMMAND,SC_RESTORE,NULL);
		}
	}
	if(uMouseMsg==WM_RBUTTONDOWN)//如果是单击右键
	{
		AfxGetMainWnd()->SetForegroundWindow();//弹出Popup菜单
		CMenu menu;
		menu.LoadMenu(IDR_MENU_TRAY);
		CMenu* pPopup=menu.GetSubMenu(0);
		CPoint Point;
		GetCursorPos(&Point);
		pPopup->TrackPopupMenu(TPM_LEFTALIGN,
			Point.x,Point.y,AfxGetMainWnd(),NULL );
		AfxGetMainWnd()->PostMessage(WM_NULL, 0, 0); 
	}

	return 1;
}

void CMainFrame::ChangeOutputView(int nID)
{
	if(nID==m_nCurOutputViewID)
		return;

	this->m_wndOutputBar.SelectTabView(nID);
	m_nCurOutputViewID=nID;
}
void CMainFrame::OnHelp() 
{
	// TODO: Add your command handler code here
	CHelpDlg dlg;
	dlg.DoModal();
}

void CMainFrame::OnMain() 
{
	// TODO: Add your command handler code here
	this->ShowWindow(SW_RESTORE);
}

LRESULT CMainFrame::OnHotKey(WPARAM wParam,LPARAM lParam)
{
	if(wParam==0XB4EE)
	{
		this->ShowWindow(SW_RESTORE);
		this->SetForegroundWindow();
	}
    return 1;
}

void CMainFrame::OnWorkspacebar() 
{
	// TODO: Add your command handler code here
	m_wndWorkSpaceBar.ShowWindow(!m_wndWorkSpaceBar.IsWindowVisible());
	RecalcLayout();
}

void CMainFrame::OnOutputbar() 
{
	// TODO: Add your command handler code here
	m_wndOutputBar.ShowWindow(!m_wndOutputBar.IsWindowVisible());
	RecalcLayout();
}

void CMainFrame::OnStop() 
{
	// TODO: Add your command handler code here
	
}

void CMainFrame::OnFilter() 
{
	// TODO: Add your command handler code here
	
}

void CMainFrame::OnDeleteItem() 
{
	// TODO: Add your command handler code here
	
}

void CMainFrame::OnClearList() 
{
	// TODO: Add your command handler code here
	
}

void CMainFrame::OnSearch() 
{
	// TODO: Add your command handler code here
	ChangeView(1);
	m_wndOutputBar.SelectTabView(1);
	m_pCSearchStatisticsView->m_comboSchCtt.SetFocus();
}

void CMainFrame::OnDetect() 
{
	// TODO: Add your command handler code here
	
}

void CMainFrame::OnSysset() 
{
	// TODO: Add your command handler code here
	
}

void CMainFrame::OnPwdset() 
{
	// TODO: Add your command handler code here
	
}

void CMainFrame::OnHide() 
{
	// TODO: Add your command handler code here
	ShowWindow(SW_HIDE);
}

⌨️ 快捷键说明

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