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

📄 exmisdlg.cpp

📁 内容包括从VC++的基本范例到项目开发的许多典型的例子。是VC++初学者不可多得的好资料
💻 CPP
字号:
// ExMISDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ExMIS.h"
#include "ExMISDlg.h"

//添加的
#include "LoginDlg.h"
#include "DataDlg.h"
#include "CourseDlg.h"
#include "ScoreDlg.h"
#include "CollegeDlg.h"
#include "UserDlg.h"
#include "ReportDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

//状态栏,字符串
static UINT indicators[] =
{
	IDS_STATUS_DATA,		//添加的自定义自符串
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CAPS,
	ID_INDICATOR_NUM,
	ID_INDICATOR_SCRL,
	IDS_STATUS_SPACE,				//加空格
};

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

/////////////////////////////////////////////////////////////////////////////
// CExMISDlg dialog

CExMISDlg::CExMISDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CExMISDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CExMISDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CExMISDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CExMISDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CExMISDlg, CDialog)
	//{{AFX_MSG_MAP(CExMISDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_MENUITEM_CAL, OnMenuitemCal)
	ON_COMMAND(ID_MENUITEM_HELP, OnMenuitemHelp)
	ON_COMMAND(ID_MENUITEM_NOTEPAD, OnMenuitemNotepad)
	ON_COMMAND(ID_MENUITEM_QUIT, OnMenuitemQuit)
	ON_COMMAND(ID_MENUITEM_RELOGIN, OnMenuitemRelogin)
	ON_COMMAND(ID_MENUITEM_STAT, OnMenuitemStat)
	ON_COMMAND(ID_MENUITEM_USER, OnMenuitemUser)
	ON_COMMAND(ID_MENUITEM_STUDENT, OnMenuitemStudent)
	ON_COMMAND(ID_MENUITEM_SCORE, OnMenuitemScore)
	ON_COMMAND(ID_MENUITEM_COURSE, OnMenuitemCourse)
	ON_COMMAND(ID_MENUITEM_COLLEGE, OnMenuitemCollege)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CExMISDlg message handlers

BOOL CExMISDlg::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
	//添加3: 工具栏
	TBBUTTON button[11];
	int i=0,nStringLength;
	CString string;
	TCHAR * pString;
	
	m_ImageList.Create(42,42,ILC_COLOR32|ILC_MASK,0,0);	//创建图像列表框,32色,48X48象素	

	m_ToolBar.EnableAutomation();
	m_ToolBar.Create(WS_CHILD|WS_VISIBLE,CRect(0,0,0,0),this,IDR_TOOLBAR);
	//向IMAGELIST对象添加资源图标
	
	for(i=IDI_ICON1;i<=IDI_ICON11;i++)
	{		
		m_ImageList.Add(::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(i)));		
	}	
	m_ToolBar.SetImageList(&m_ImageList);	

	//如果此处循环错误则不能正常显示文字
	for(i=0;i<11;i++)
	{
		button[i].dwData=0;
		button[i].fsState=TBSTATE_ENABLED;
		button[i].fsStyle=TBSTYLE_BUTTON;
		button[i].iBitmap=i;
		string.LoadString(i+IDS_STRING102);		
		//为第一个字符再加一个'\0',用于向工具栏里加字符串
		nStringLength=string.GetLength()+1;
		pString=string.GetBufferSetLength(nStringLength);
		button[i].iString=m_ToolBar.AddStrings(pString);
		string.ReleaseBuffer();
	}
	//将工具栏的命令ID与菜单绑定
	button[0].idCommand=ID_MENUITEM_RELOGIN;
	button[1].idCommand=ID_MENUITEM_STUDENT;
	button[2].idCommand=ID_MENUITEM_COLLEGE;
	button[3].idCommand=ID_MENUITEM_COURSE;
	button[4].idCommand=ID_MENUITEM_SCORE;
	button[5].idCommand=ID_MENUITEM_STAT;
	button[6].idCommand=ID_MENUITEM_USER;
	button[7].idCommand=ID_MENUITEM_NOTEPAD;
	button[8].idCommand=ID_MENUITEM_CAL;
	button[9].idCommand=ID_MENUITEM_HELP;
	button[10].idCommand=ID_MENUITEM_QUIT;

	m_ToolBar.AddButtons(11,button);

	button[0].fsStyle=TBSTYLE_SEP;
	//添加分隔条,应该从后向前添加,这样不用考虑添加后对序号的影响
	m_ToolBar.InsertButton(9,&button[0]);
	m_ToolBar.InsertButton(7,&button[0]);
	m_ToolBar.InsertButton(6,&button[0]);
	m_ToolBar.InsertButton(4,&button[0]);
	m_ToolBar.InsertButton(1,&button[0]);

	m_ToolBar.AutoSize;
	m_ToolBar.SetStyle(TBSTYLE_FLAT|CCS_TOP);	//更改风格

	//*状态栏
	//获取客户区大小
	CRect rect;
	GetClientRect(rect);

	//定义状态栏
	m_wndStatusBar.Create(this);
	m_wndStatusBar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT));
	//在底部显示状态栏
	m_wndStatusBar.MoveWindow(0,rect.bottom-20,rect.right,20);
	m_wndStatusBar.SetPaneStyle(2,SBPS_STRETCH);

	//调登录对话框
	OnMenuitemRelogin();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

bool CExMISDlg::PowerValidate(int nPower)
{	//权限管理
	if(m_nPower<nPower)
	{
		AfxMessageBox("对不起,您的权限不够,无法执行此项操作!");
		return false;
	}
	return true;
}

void CExMISDlg::OnMenuitemRelogin() 
{	//打开登录窗口
	m_nPower=0;
	CLoginDlg dlg;
	dlg.DoModal();
	//将登录时选择的数据库类型和权限传到主窗体
	m_pRS.m_strDBType=dlg.m_pRS.m_strDBType;
	m_nPower=dlg.m_nPower;
}

void CExMISDlg::OnMenuitemStudent() 
{	//学生管理,二级以上权限可进
	if(PowerValidate(2)){
		//打开数据管理窗口
		CDataDlg dlg;
		//将数据库类型传到数据管理窗体
		dlg.m_pRS.m_strDBType=m_pRS.m_strDBType;
		dlg.DoModal();
	}
}

void CExMISDlg::OnMenuitemCollege() 
{	//院系管理,三级以上权限可进
	if(PowerValidate(3)){
		CCollegeDlg dlg;
		//将使用的数据库类型传给学院管理子窗体
		dlg.m_pRS.m_strDBType=m_pRS.m_strDBType;
		dlg.DoModal();
	}
}

void CExMISDlg::OnMenuitemCourse() 
{	//课程管理,三级以上权限可进
	if(PowerValidate(3)){
		CCourseDlg	dlg;
		dlg.m_pRS.m_strDBType=m_pRS.m_strDBType;
		dlg.DoModal();
	}
}

void CExMISDlg::OnMenuitemScore() 
{	//分数管理,二级以上权限可进
	if(PowerValidate(2)){
		CScoreDlg	dlg;
		dlg.m_pRS.m_strDBType=m_pRS.m_strDBType;
		dlg.DoModal();
	}
}

void CExMISDlg::OnMenuitemCal() 
{	//调计算器
	WinExec("calc.exe",SW_SHOW);
}

void CExMISDlg::OnMenuitemNotepad() 
{	//调记事本
	WinExec("notepad.exe",SW_SHOW);
}

void CExMISDlg::OnMenuitemStat() 
{	//成绩统计,一级以上权限可进
	if(PowerValidate(1)){
		CReportDlg	dlg;
		dlg.m_pRS.m_strDBType=m_pRS.m_strDBType;
		dlg.DoModal();
	}
}

void CExMISDlg::OnMenuitemUser() 
{	//用户管理,三级以上权限可进
	if(PowerValidate(3)){
		CUserDlg dlg;
		//将使用的数据库类型传给用户管理子窗体
		dlg.m_pRS.m_strDBType=m_pRS.m_strDBType;
		dlg.DoModal();
	}
}

void CExMISDlg::OnMenuitemHelp() 
{	//调帮助文档
	AfxMessageBox("help");
}

void CExMISDlg::OnMenuitemQuit() 
{	//返回一个OK结束模态,即终止程序
	CDialog::OnOK();
}

⌨️ 快捷键说明

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