home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK10 / MFC / SRC / WINMENU.CP$ / winmenu
Encoding:
Text File  |  1992-03-17  |  2.6 KB  |  128 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library. 
  2. // Copyright (C) 1992 Microsoft Corporation 
  3. // All rights reserved. 
  4. //  
  5. // This source code is only intended as a supplement to the 
  6. // Microsoft Foundation Classes Reference and Microsoft 
  7. // QuickHelp documentation provided with the library. 
  8. // See these sources for detailed information regarding the 
  9. // Microsoft Foundation Classes product. 
  10.  
  11.  
  12. #include "afxwin.h"
  13. #pragma hdrstop
  14.  
  15. #include "winhand_.h"
  16.  
  17. #ifdef AFX_CORE_SEG
  18. #pragma code_seg(AFX_CORE_SEG)
  19. #endif
  20.  
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char BASED_CODE THIS_FILE[] = __FILE__;
  24. #define new DEBUG_NEW
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // Map from HMENU to CMenu *
  29.  
  30. class NEAR CMenuHandleMap : public CHandleMap
  31. {
  32. public:
  33.     CObject* NewTempObject(HANDLE h)
  34.                 {
  35.                     // don't add in permanent
  36.                     CMenu* p = new CMenu();
  37.                     p->m_hMenu = (HMENU)h;     // set after constructed
  38.                     return p;
  39.                 }
  40.     void DeleteTempObject(CObject* ob)
  41.                 {
  42.                     ASSERT(ob->IsKindOf(RUNTIME_CLASS(CMenu)));
  43.                     ((CMenu*)ob)->m_hMenu = NULL;   // clear before destructed
  44.                     delete ob;
  45.                 }
  46. };
  47. static CMenuHandleMap NEAR hMenuMap;
  48.  
  49. // Map from HMENU to CMenu*
  50. CMenu*
  51. CMenu::FromHandle(HMENU hMenu)
  52. {
  53.     return (CMenu*)hMenuMap.FromHandle(hMenu);
  54. }
  55.  
  56. void
  57. CMenu::DeleteTempMap()
  58. {
  59.     hMenuMap.DeleteTemp();
  60. }
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CMenu
  64.  
  65. IMPLEMENT_DYNAMIC(CMenu, CObject)
  66.  
  67. #ifdef _DEBUG
  68. void CMenu::AssertValid() const
  69. {
  70.     CObject::AssertValid();
  71. }
  72.  
  73. void CMenu::Dump(CDumpContext& dc) const
  74. {
  75.     CObject::Dump(dc);
  76.     dc << "m_hMenu = " << (void NEAR*)m_hMenu;
  77. }
  78. #endif
  79.  
  80. BOOL
  81. CMenu::Attach(HMENU hMenu)
  82. {
  83.     ASSERT(m_hMenu == NULL);        // only attach once, detach on destroy
  84.     if (hMenu == NULL)
  85.         return FALSE;
  86.     hMenuMap.SetPermanent(m_hMenu = hMenu, this);
  87.     return TRUE;
  88. }
  89.  
  90. HMENU
  91. CMenu::Detach()
  92. {
  93.     HMENU hMenu;
  94.     if ((hMenu = m_hMenu) != NULL)
  95.         hMenuMap.RemovePermanent(m_hMenu);
  96.     m_hMenu = NULL;
  97.     return hMenu;
  98. }
  99.  
  100. CMenu::~CMenu()
  101. {
  102.     DestroyMenu();
  103. }
  104.  
  105. BOOL
  106. CMenu::DestroyMenu()
  107. {
  108.     if (m_hMenu == NULL)
  109.         return FALSE;
  110.     return ::DestroyMenu(Detach());
  111. }
  112.  
  113. /////////////////////////////////////////////////////////////////////////////
  114. // Self-drawing menu items
  115.  
  116. void CMenu::DrawItem(LPDRAWITEMSTRUCT /* lpDrawItemStruct */)
  117. {
  118.     // default drawing does nothing
  119. }
  120.  
  121. void CMenu::MeasureItem(LPMEASUREITEMSTRUCT /* lpMeasureItemStruct */)
  122. {
  123.     // default drawing does nothing
  124. }
  125.  
  126.  
  127. /////////////////////////////////////////////////////////////////////////////
  128.