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

📄 mainfrm.cpp

📁 visual c++ 实例编程
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "ToolBar.h"

#include "MainFrm.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)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	ON_WM_CREATE()
	ON_COMMAND(IDC_SETMSG, OnSetmsg)
	ON_COMMAND(IDC_USERPASSCHANGE,OnUserpassChange)
	ON_COMMAND(IDC_MSG_RECIEVED,OnMsgRecieved)
	ON_COMMAND(IDC_MSG_SENDED,OnMsgSended)
	ON_COMMAND(IDC_TELBOOK,   OnTelBook)
	ON_COMMAND(IDC_SYSLOCKED, OnLocSys)
	ON_COMMAND(IDC_SYSSTATE, OnSysState)
	ON_COMMAND(IDC_GETALLSIM,OnGetAllSimMsg)
	ON_COMMAND(IDC_REFRESH, OnRefreshSel)
	ON_COMMAND(IDC_REFRESHALL, OnRefreshAll)
	ON_COMMAND(IDC_MSG_DELETED, OnMsgDeleted)
	ON_COMMAND(IDC_WRITEMSG,OnWriteMsg)
	ON_COMMAND(IDC_SCHOOL_REPORT_CARD, OnSchoolReportCard)
	//}}AFX_MSG_MAP

	//}}AFX_MSG_MAP 
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
	
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
		//创建扩展工具栏
	if (!this->CreateExToolBar())
		return -1;

	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
	}

	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
/*	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);*/

	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


BOOL CMainFrame::CreateExToolBar()
{
	CImageList img;
	CString str;
	
	if(!m_wndReBar.Create(this))
	{
		return -1;
	}
	
	if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
	{
		return -1;      
	}
	
	//下面的代码是设置按钮的宽度和长度
	m_wndToolBar.GetToolBarCtrl().SetButtonWidth(40, 80);
	//下面的代码是设置"热"的位图
	img.Create(22, 22, ILC_COLOR8|ILC_MASK,2,2);
	img.SetBkColor(::GetSysColor(COLOR_BTNFACE));
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_GETBUTTON));//0收信
    img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_WRITEMSGBTN));//1写信
	
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_TELBOOK));//2电话本
    img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_RECIEVBOX));//3收信    
    img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_SENDBOX));//4发信
    img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_DELETEED)); //5废信     
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_REFRESH));   //6刷新    
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_REFRESHALL));  //7全部刷新    
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_CHANGEPASS));  //8口令
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_LOCKSYS));   //9锁定系统
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_SETSYS));   //10设置
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_EXIT));   //11退出
	img.Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));//关于
	img.Add(AfxGetApp()->LoadIcon(IDI_COM_CONTROL));//系统状态
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_SRC));//班级管理
	m_wndToolBar.GetToolBarCtrl().SetHotImageList(&img);
	img.Detach();	
	
	//下面的代码是设置"冷"的位图
	img.Create(19, 19, ILC_COLOR8|ILC_MASK, 2,2);
	img.SetBkColor(::GetSysColor(COLOR_BTNFACE));
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_GETBUTTON));//0收信
    img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_WRITEMSGBTN));//1写信
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_TELBOOK));//2电话本
    img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_RECIEVBOX));//3收信    
    img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_SENDBOX));//4发信
    img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_DELETEED)); //5废信     
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_REFRESH));   //6刷新    
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_REFRESHALL));  //7全部刷新    
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_CHANGEPASS));  //8口令
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_LOCKSYS));   //9锁定系统
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_SETSYS));   //10设置
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_EXIT));   //11退出
	img.Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));//关于12
	img.Add(AfxGetApp()->LoadIcon(IDI_COM_CONTROL));//系统状态13
	img.Add(AfxGetApp()->LoadIcon(IDI_ICON_MSG_SRC));//班级管理14
	m_wndToolBar.GetToolBarCtrl().SetImageList(&img);
	img.Detach();
	
	//改变属性
	m_wndToolBar.ModifyStyle(0, TBSTYLE_FLAT |CBRS_TOOLTIPS | TBSTYLE_TRANSPARENT|TBBS_CHECKBOX );
	m_wndToolBar.SetButtons(NULL,21);	
	// set up each toolbar button设置文字  
	
	m_wndToolBar.SetButtonInfo(0, IDC_WRITEMSG, TBSTYLE_BUTTON, 1);
	m_wndToolBar.SetButtonText(0, "写信");	
	
	m_wndToolBar.SetButtonInfo(1, IDC_GETALLSIM, TBSTYLE_BUTTON, 0);
	m_wndToolBar.SetButtonText(1, "收信");
	
	m_wndToolBar.SetButtonInfo(2, IDC_MSG_BUTTONSPLI, TBBS_SEPARATOR, 0);
	
	m_wndToolBar.SetButtonInfo(3, IDC_SCHOOL_REPORT_CARD, TBSTYLE_BUTTON, 14);
	m_wndToolBar.SetButtonText(3, "成绩管理");
	
	m_wndToolBar.SetButtonInfo(4, IDC_MSG_BUTTONSPLI, TBBS_SEPARATOR, 0);
	
	m_wndToolBar.SetButtonInfo(5, IDC_TELBOOK, TBSTYLE_BUTTON, 2);
	m_wndToolBar.SetButtonText(5, "电话本");
	
	m_wndToolBar.SetButtonInfo(6, IDC_MSG_RECIEVED, TBSTYLE_BUTTON , 3);
	m_wndToolBar.SetButtonText(6, "收到短信");
	
	m_wndToolBar.SetButtonInfo(7, IDC_MSG_SENDED, TBSTYLE_BUTTON , 4);
	m_wndToolBar.SetButtonText(7, "已发短信");
	
	m_wndToolBar.SetButtonInfo(8, IDC_MSG_DELETED, TBSTYLE_BUTTON, 5);
	m_wndToolBar.SetButtonText(8, "废件箱");
	
	m_wndToolBar.SetButtonInfo(9, IDC_MSG_BUTTONSPLI, TBBS_SEPARATOR, 0);
	
	m_wndToolBar.SetButtonInfo(10, IDC_REFRESH, TBSTYLE_BUTTON , 6);
	m_wndToolBar.SetButtonText(10, "刷新");
	
	m_wndToolBar.SetButtonInfo(11, IDC_REFRESHALL, TBSTYLE_BUTTON , 7);
	m_wndToolBar.SetButtonText(11, "全部刷新");	
	
	m_wndToolBar.SetButtonInfo(12, IDC_MSG_BUTTONSPLI, TBBS_SEPARATOR, 0);
	
	m_wndToolBar.SetButtonInfo(13, IDC_USERPASSCHANGE, TBSTYLE_BUTTON , 8);
	m_wndToolBar.SetButtonText(13, "口令");
	
	m_wndToolBar.SetButtonInfo(14, IDC_SYSLOCKED, TBSTYLE_BUTTON , 9);
	m_wndToolBar.SetButtonText(14, "锁定");
	
	m_wndToolBar.SetButtonInfo(15, IDC_SETMSG, TBSTYLE_BUTTON, 10);
	m_wndToolBar.SetButtonText(15, "设置");
	
	m_wndToolBar.SetButtonInfo(16, IDC_SYSSTATE, TBSTYLE_BUTTON, 13);
	m_wndToolBar.SetButtonText(16, "系统信息");
	
	m_wndToolBar.SetButtonInfo(17, IDC_MSG_BUTTONSPLI, TBBS_SEPARATOR, 0);
	
	m_wndToolBar.SetButtonInfo(18, ID_APP_ABOUT, TBSTYLE_BUTTON, 12);
	m_wndToolBar.SetButtonText(18, "关于");	
	
	m_wndToolBar.SetButtonInfo(19,ID_APP_EXIT,TBSTYLE_BUTTON,11);
	m_wndToolBar.SetButtonText(19,"退出");
	
	m_wndToolBar.SetButtonInfo(20,IDC_MSG_BUTTONSPLI,TBBS_SEPARATOR,11);
	
	CRect rectToolBar;
	//得到按钮的大小
	m_wndToolBar.GetItemRect(0, &rectToolBar);
	//设置按钮的大小
	m_wndToolBar.SetSizes(rectToolBar.Size(), CSize(20,20));
	
	//在Rebar中加入ToolBar
	m_wndReBar.AddBar(&m_wndToolBar);
	
	//改变一些属性
	REBARBANDINFO rbbi;
	rbbi.cbSize = sizeof(rbbi);		//这个是必须填
	rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE|RBBIM_BACKGROUND;
	//工具条的宽度
	rbbi.cxMinChild = rectToolBar.Width();
	//高度
	rbbi.cyMinChild = rectToolBar.Height();
	//下面这行代码是为工具条加入背景位图,请注意上rbbi.fMask中RBBIM_BACKGROUND标志
	rbbi.hbmBack = LoadBitmap(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_TOOLBARBKMAP));
	
	rbbi.cx = rbbi.cxIdeal = rectToolBar.Width() * 10;
	
	m_wndReBar.GetReBarCtrl().SetBandInfo(0, &rbbi);
	return TRUE;
}

void CMainFrame::OnLocSys()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnMsgDeleted()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnGetAllSimMsg()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnHelp()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnMsgRecieved()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnMsgSended()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnRefreshAll()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnRefreshSel()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnSchoolReportCard()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnSysState()
{
	AfxMessageBox("您好");
}
void CMainFrame::OnTelBook()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnWriteMsg()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnUserpassChange()
{
	AfxMessageBox("您好");
}

void CMainFrame::OnSetmsg()
{
	AfxMessageBox("您好");
}

⌨️ 快捷键说明

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