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

📄 mainfrm.cpp

📁 Visual C++高级编程及其项目应用开发(含源代码)
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

#include "stdafx.h"
#include "clientMain.h"

#include "MainFrm.h"

#include <string>

using namespace std;

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

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

IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_UPDATE_COMMAND_UI(ID_VIEW_COOL_BAR, OnUpdateViewCoolBar)
	ON_COMMAND(ID_VIEW_COOL_BAR, OnViewCoolBar)
	
	//自己手动添加的消息映射
	ON_NOTIFY(TVN_SELCHANGED, ID_Tree_View, OnTreeClick)
	//}}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 (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	//用来设置背景颜色,子类化新建的多文档窗体
	if (!m_wndNewClient.SubclassWindow(m_hWndMDIClient))
       {
         TRACE("Failed to subclass MDI client window\n");
         return -1;      // fail to create
       }

	
	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
	}

	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
	}

	if (!m_wndCoolBar.Create(_T("命令导航栏"), this, 123))
    {
        TRACE0("Failed to create mybar\n");
        return -1;      // fail to create
	}
	
	//创建树状控件
	if (!m_wndTree.Create(WS_CHILD|WS_VISIBLE|
		TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT,
		CRect(0, 0, 0, 0), &m_wndCoolBar, ID_Tree_View))
	{
		TRACE0("Failed to create instant bar child\n");
		return -1;
	}
	m_wndTree.ModifyStyleEx(0, WS_EX_CLIENTEDGE);

	m_imgList.Create(IDB_BMP_TREE, 16, 1, RGB(0,255,0));
	m_imgList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
	m_imgList.Add(AfxGetApp()->LoadIcon(IDI_ICON2));

	m_wndTree.SetImageList(&m_imgList, TVSIL_NORMAL);

	//为树状控件添加条目
	HTREEITEM hti = m_wndTree.InsertItem(_T("个人说明"));
	HTREEITEM htiChild; // child item
	
	m_wndTree.InsertItem(_T("友情链接"));
	htiChild = m_wndTree.InsertItem(_T("兴趣爱好"), 0, 1, hti, TVI_LAST);
	htiChild = m_wndTree.InsertItem(_T("个人特长"), 0, 1, hti, TVI_LAST);

	
	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	
	m_wndCoolBar.SetBarStyle(m_wndCoolBar.GetBarStyle() |
        CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);

	EnableDocking(CBRS_ALIGN_ANY);
	
	m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    m_wndCoolBar.EnableDocking(CBRS_ALIGN_ANY);

	//改变停靠风格,
	#ifdef _SCB_REPLACE_MINIFRAME
	m_pFloatingFrameClass = RUNTIME_CLASS(CSCBMiniDockFrameWnd); 
	#endif

	DockControlBar(&m_wndToolBar);
    DockControlBar(&m_wndCoolBar, AFX_IDW_DOCKBAR_LEFT);

	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CMDIFrameWnd::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
{
	CMDIFrameWnd::AssertValid();
}

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

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

//下面这两段函数,用来控制命令导航栏的显示
void CMainFrame::OnUpdateViewCoolBar(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable();
	pCmdUI->SetCheck(m_wndCoolBar.IsVisible());
}

void CMainFrame::OnViewCoolBar() 
{
	// TODO: Add your command handler code here
	ShowControlBar(&m_wndCoolBar, !m_wndCoolBar.IsVisible(), FALSE);
}

BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CMDIFrameWnd::PreTranslateMessage(pMsg);
}

void CMainFrame::OnTreeClick(NMHDR* pNMHDR, LRESULT* pResult)
{
	HTREEITEM trvItem = m_wndTree.GetSelectedItem();
	string strTrvText;

	strTrvText = m_wndTree.GetItemText(trvItem);
	if (trvItem==NULL)
	{
		return;
	}
	else
	{
		if (m_wndTree.GetParentItem(trvItem) != NULL)
		{
			AfxMessageBox(strTrvText.c_str());
		}
	}
	*pResult = 0;
}

⌨️ 快捷键说明

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