MenuXPAppView.cpp
上传用户:lejushen
上传日期:2007-01-10
资源大小:183k
文件大小:5k
源码类别:

菜单

开发平台:

Visual C++

  1. // MenuXPAppView.cpp : implementation of the CMenuXPAppView class
  2. //
  3. #include "stdafx.h"
  4. #include "MenuXPApp.h"
  5. #include "MenuXPAppDoc.h"
  6. #include "MenuXPAppView.h"
  7. #include "MenuXP.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CMenuXPAppView
  15. IMPLEMENT_DYNCREATE(CMenuXPAppView, CView)
  16. BEGIN_MESSAGE_MAP(CMenuXPAppView, CView)
  17. //{{AFX_MSG_MAP(CMenuXPAppView)
  18. ON_WM_CONTEXTMENU()
  19. ON_WM_MEASUREITEM()
  20. //}}AFX_MSG_MAP
  21. // Standard printing commands
  22. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  25. END_MESSAGE_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CMenuXPAppView construction/destruction
  28. CMenuXPAppView::CMenuXPAppView()
  29. {
  30. // TODO: add construction code here
  31. }
  32. CMenuXPAppView::~CMenuXPAppView()
  33. {
  34. }
  35. BOOL CMenuXPAppView::PreCreateWindow(CREATESTRUCT& cs)
  36. {
  37. // TODO: Modify the Window class or styles here by modifying
  38. //  the CREATESTRUCT cs
  39. return CView::PreCreateWindow(cs);
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CMenuXPAppView drawing
  43. void CMenuXPAppView::OnDraw(CDC* pDC)
  44. {
  45. CMenuXPAppDoc* pDoc = GetDocument();
  46. ASSERT_VALID(pDoc);
  47. // TODO: add draw code for native data here
  48. }
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CMenuXPAppView printing
  51. BOOL CMenuXPAppView::OnPreparePrinting(CPrintInfo* pInfo)
  52. {
  53. // default preparation
  54. return DoPreparePrinting(pInfo);
  55. }
  56. void CMenuXPAppView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  57. {
  58. // TODO: add extra initialization before printing
  59. }
  60. void CMenuXPAppView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  61. {
  62. // TODO: add cleanup after printing
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CMenuXPAppView diagnostics
  66. #ifdef _DEBUG
  67. void CMenuXPAppView::AssertValid() const
  68. {
  69. CView::AssertValid();
  70. }
  71. void CMenuXPAppView::Dump(CDumpContext& dc) const
  72. {
  73. CView::Dump(dc);
  74. }
  75. CMenuXPAppDoc* CMenuXPAppView::GetDocument() // non-debug version is inline
  76. {
  77. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMenuXPAppDoc)));
  78. return (CMenuXPAppDoc*)m_pDocument;
  79. }
  80. #endif //_DEBUG
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CMenuXPAppView message handlers
  83. void CMenuXPAppView::OnContextMenu(CWnd* pWnd, CPoint point) 
  84. {
  85. CMenuXP *pMenu = new CMenuXP;
  86. pMenu->CreatePopupMenu();
  87. pMenu->SetSelectedBarColor(RGB(0x66, 0x99, 0xff));
  88. // pMenu->SetMenuStyle(CMenuXP::STYLE_XP);
  89. CBitmap bmp;
  90. bmp.LoadBitmap(IDB_BACK);
  91. // pMenu->SetBackBitmap((HBITMAP)bmp.Detach());
  92. pMenu->AddSideBar(new CMenuXPSideBar(24, "MenuXP"));
  93. pMenu->AppendODMenu(0, new CMenuXPText(10, "First Item", AfxGetApp()->LoadIcon(IDI_ICON1)));
  94. pMenu->AppendSeparator();
  95. pMenu->AppendODMenu(MF_CHECKED, new CMenuXPText(11, "Checked Item", AfxGetApp()->LoadIcon(IDI_ICON2)));
  96. pMenu->AppendODMenu(0, new CMenuXPText(12, "Another Item", AfxGetApp()->LoadIcon(IDI_ICON3)));
  97. pMenu->AppendODMenu(0, new CMenuXPText(13, "No Icon"));
  98. pMenu->SetDefaultItem(12);
  99. CMenuXP *pPopup = new CMenuXP;
  100. pPopup->CreatePopupMenu();
  101. pPopup->SetSelectedBarColor(RGB(0x66, 0x99, 0xff));
  102. // pPopup->SetMenuStyle(CMenuXP::STYLE_XP);
  103. pPopup->AddSideBar(new CMenuXPSideBar(24, "Buttons"));
  104. pPopup->SetSideBarStartColor(RGB(125, 230, 192));
  105. pPopup->SetSideBarEndColor(RGB(0, 0, 0));
  106. pPopup->AppendODMenu(0, new CMenuXPButton(21, AfxGetApp()->LoadIcon(IDI_ICON4)));
  107. pPopup->AppendODMenu(0, new CMenuXPButton(22, AfxGetApp()->LoadIcon(IDI_ICON5)));
  108. pPopup->AppendODMenu(0, new CMenuXPButton(23, AfxGetApp()->LoadIcon(IDI_ICON6)));
  109. pPopup->Break();
  110. pPopup->AppendODMenu(MF_CHECKED, new CMenuXPButton(24, AfxGetApp()->LoadIcon(IDI_ICON7)));
  111. pPopup->AppendODMenu(0, new CMenuXPButton(25, AfxGetApp()->LoadIcon(IDI_ICON8)));
  112. pPopup->AppendODMenu(0, new CMenuXPButton(26, AfxGetApp()->LoadIcon(IDI_ICON9)));
  113. pPopup->Break();
  114. pPopup->AppendODMenu(0, new CMenuXPButton(27, AfxGetApp()->LoadIcon(IDI_ICON10)));
  115. pPopup->AppendODMenu(0, new CMenuXPButton(28, AfxGetApp()->LoadIcon(IDI_ICON11)));
  116. pPopup->AppendODMenu(0, new CMenuXPButton(29, AfxGetApp()->LoadIcon(IDI_ICON12)));
  117. pMenu->AppendODPopup(0, pPopup, new CMenuXPText(0, "Popup", AfxGetApp()->LoadIcon(IDI_ICON1)));
  118. pMenu->AppendODMenu(MF_GRAYED, new CMenuXPText(40, "Disabled", AfxGetApp()->LoadIcon(IDI_ICON5)));
  119. pMenu->AppendODMenu(MF_CHECKED, new CMenuXPText(41, "Checked"));
  120. pMenu->TrackPopupMenu(TPM_LEFTBUTTON, point.x, point.y, this);
  121. delete pMenu;
  122. }
  123. void CMenuXPAppView::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
  124. {
  125. // TODO: Add your message handler code here and/or call default
  126. HMENU hMenu = AfxGetThreadState()->m_hTrackingMenu;
  127. CMenu *pMenu = CMenu::FromHandle(hMenu);
  128. pMenu->MeasureItem(lpMeasureItemStruct);
  129. CView::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
  130. }