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

📄 windowsxpmenuview.cpp

📁 c++系统开发实例精粹内附的80例源代码 环境:windows2000,c++6.0
💻 CPP
字号:
// WindowsXPMenuView.cpp : implementation of the CWindowsXPMenuView class
//

#include "stdafx.h"
#include "WindowsXPMenuApp.h"

#include "WindowsXPMenuDoc.h"
#include "WindowsXPMenuView.h"

#include "MenuXP.h"

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

/////////////////////////////////////////////////////////////////////////////
// CWindowsXPMenuView

IMPLEMENT_DYNCREATE(CWindowsXPMenuView, CView)

BEGIN_MESSAGE_MAP(CWindowsXPMenuView, CView)
	//{{AFX_MSG_MAP(CWindowsXPMenuView)
	ON_WM_CONTEXTMENU()
	ON_WM_MEASUREITEM()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWindowsXPMenuView construction/destruction

CWindowsXPMenuView::CWindowsXPMenuView()
{
	// TODO: add construction code here

}

CWindowsXPMenuView::~CWindowsXPMenuView()
{
}

BOOL CWindowsXPMenuView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CWindowsXPMenuView drawing

void CWindowsXPMenuView::OnDraw(CDC* pDC)
{
	CWindowsXPMenuDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CWindowsXPMenuView printing

BOOL CWindowsXPMenuView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CWindowsXPMenuView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CWindowsXPMenuView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CWindowsXPMenuView diagnostics

#ifdef _DEBUG
void CWindowsXPMenuView::AssertValid() const
{
	CView::AssertValid();
}

void CWindowsXPMenuView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CWindowsXPMenuDoc* CWindowsXPMenuView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWindowsXPMenuDoc)));
	return (CWindowsXPMenuDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CWindowsXPMenuView message handlers
// WM_CONTEXTMENU消息处理函数,当鼠标右键单击窗口区域时产生此消息
void CWindowsXPMenuView::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	// 创建CMenuXP对象
	CMenuXP	*pMenu = new CMenuXP;
	//  创建弹出式菜单
	pMenu->CreatePopupMenu();
	// 设置菜单背景色
	pMenu->SetBackColor(RGB(0xff, 0xff, 0x00));
	// 设置菜单被选中项填充色
	pMenu->SetSelectedItemColor(RGB(0x77, 0xBB, 0xFF));
	// 以Windows XP风格绘制菜单
	pMenu->SetMenuStyle(CMenuXP::STYLE_XP);

	// 加载背景贴图
	CBitmap	bmp;
	bmp.LoadBitmap(IDB_BACK);
	pMenu->SetBackBitmap((HBITMAP)bmp.Detach());

	// 添加主菜单标题栏
	pMenu->AddSideBar(new CMenuXPSideBar(24, "Windows XP Menu"));
	// 添加主菜单项
	pMenu->AppendODMenu(0, new CMenuXPText(10, "First Item", AfxGetApp()->LoadIcon(IDI_ICON1)));
	pMenu->AppendSeparator();
	pMenu->AppendODMenu(MF_CHECKED, new CMenuXPText(11, "Checked Item", AfxGetApp()->LoadIcon(IDI_ICON2)));
	pMenu->AppendODMenu(0, new CMenuXPText(12, "Another Item", AfxGetApp()->LoadIcon(IDI_ICON3)));
	pMenu->AppendODMenu(0, new CMenuXPText(13, "No Icon"));

	// 创建弹出式子菜单
	CMenuXP *pPopup = new CMenuXP;
	pPopup->CreatePopupMenu();

	pPopup->SetBackColor(RGB(0xf2, 0xf2, 0xf2));
	pPopup->SetSelectedItemColor(RGB(0x66, 0x99, 0xff));
	pPopup->SetMenuStyle(CMenuXP::STYLE_XP);

	// 为弹出子菜单添加标题栏
	pPopup->AddSideBar(new CMenuXPSideBar(24, "Buttons"));
	// 设置标题栏梯度绘制的起始和终止颜色
	pPopup->SetSideBarStartColor(RGB(125, 230, 192));
	pPopup->SetSideBarEndColor(RGB(0, 0, 0));
	// 添加子菜单项
	pPopup->AppendODMenu(0, new CMenuXPButton(21, AfxGetApp()->LoadIcon(IDI_ICON4)));
	pPopup->AppendODMenu(0, new CMenuXPButton(22, AfxGetApp()->LoadIcon(IDI_ICON5)));
	pPopup->AppendODMenu(0, new CMenuXPButton(23, AfxGetApp()->LoadIcon(IDI_ICON6)));
	pPopup->Break();
	pPopup->AppendODMenu(0, new CMenuXPButton(24, AfxGetApp()->LoadIcon(IDI_ICON7)));
	pPopup->AppendODMenu(0, new CMenuXPButton(25, AfxGetApp()->LoadIcon(IDI_ICON8)));
	pPopup->AppendODMenu(0, new CMenuXPButton(26, AfxGetApp()->LoadIcon(IDI_ICON9)));
	pPopup->Break();
	pPopup->AppendODMenu(0, new CMenuXPButton(27, AfxGetApp()->LoadIcon(IDI_ICON10)));
	pPopup->AppendODMenu(0, new CMenuXPButton(28, AfxGetApp()->LoadIcon(IDI_ICON11)));
	pPopup->AppendODMenu(0, new CMenuXPButton(29, AfxGetApp()->LoadIcon(IDI_ICON12)));

	// 将子菜单项加入到主菜单中
	pMenu->AppendODPopup(0, pPopup, new CMenuXPText(0, "Popup", AfxGetApp()->LoadIcon(IDI_ICON1)));

	pMenu->AppendODMenu(MF_GRAYED, new CMenuXPText(40, "Disabled", AfxGetApp()->LoadIcon(IDI_ICON5)));
	pMenu->AppendODMenu(MF_CHECKED, new CMenuXPText(41, "Checked"));

	pMenu->TrackPopupMenu(TPM_LEFTBUTTON, point.x, point.y, this);
    // 释放资源
	delete pMenu;
}

void CWindowsXPMenuView::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
{
	// TODO: Add your message handler code here and/or call default
	HMENU hMenu = AfxGetThreadState()->m_hTrackingMenu;
	CMenu	*pMenu = CMenu::FromHandle(hMenu);
	pMenu->MeasureItem(lpMeasureItemStruct);
	
	CView::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}

⌨️ 快捷键说明

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