home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SRC / WINMENU.CP_ / WINMENU.CP
Encoding:
Text File  |  1993-02-08  |  2.5 KB  |  115 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 and/or WinHelp documentation provided with the library. 
  8. // See these sources for detailed information regarding the 
  9. // Microsoft Foundation Classes product. 
  10.  
  11.  
  12. #include "stdafx.h"
  13. #include "winhand_.h"
  14.  
  15. #ifdef AFX_CORE1_SEG
  16. #pragma code_seg(AFX_CORE1_SEG)
  17. #endif
  18.  
  19. #ifdef _DEBUG
  20. #undef THIS_FILE
  21. static char BASED_CODE THIS_FILE[] = __FILE__;
  22. #endif
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // Map from HMENU to CMenu *
  26.  
  27. #ifndef _AFXDLL
  28. static CHandleMap NEAR _afxMapHMENU(RUNTIME_CLASS(CMenu));
  29. #else
  30. #define _afxMapHMENU (*_AfxGetAppData()->appMapHMENU)
  31. #endif
  32.  
  33. void PASCAL CMenu::DeleteTempMap()
  34. {
  35.     _afxMapHMENU.DeleteTemp();
  36. }
  37.  
  38. CMenu* PASCAL CMenu::FromHandle(HMENU hMenu)
  39. {
  40.     CMenu* pMenu = (CMenu*)_afxMapHMENU.FromHandle(hMenu);
  41.     ASSERT(pMenu == NULL || pMenu->m_hMenu == hMenu);
  42.     return pMenu;
  43. }
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CMenu
  47.  
  48. IMPLEMENT_DYNCREATE(CMenu, CObject)
  49.  
  50. #ifdef _DEBUG
  51. void CMenu::AssertValid() const
  52. {
  53.     CObject::AssertValid();
  54.     if (afxData.bWin31)
  55.     {
  56.         ASSERT(m_hMenu == NULL || ::IsMenu(m_hMenu));
  57.     }
  58. }
  59.  
  60. void CMenu::Dump(CDumpContext& dc) const
  61. {
  62.     CObject::Dump(dc);
  63.     AFX_DUMP1(dc, "\nm_hMenu = ", (UINT)m_hMenu);
  64. }
  65. #endif
  66.  
  67. BOOL
  68. CMenu::Attach(HMENU hMenu)
  69. {
  70.     ASSERT(m_hMenu == NULL);        // only attach once, detach on destroy
  71.     if (hMenu == NULL)
  72.         return FALSE;
  73.     _afxMapHMENU.SetPermanent(m_hMenu = hMenu, this);
  74.     return TRUE;
  75. }
  76.  
  77. HMENU
  78. CMenu::Detach()
  79. {
  80.     HMENU hMenu;
  81.     if ((hMenu = m_hMenu) != NULL)
  82.         _afxMapHMENU.RemoveHandle(m_hMenu);
  83.     m_hMenu = NULL;
  84.     return hMenu;
  85. }
  86.  
  87. CMenu::~CMenu()
  88. {
  89.     DestroyMenu();
  90. }
  91.  
  92. BOOL
  93. CMenu::DestroyMenu()
  94. {
  95.     if (m_hMenu == NULL)
  96.         return FALSE;
  97.     return ::DestroyMenu(Detach());
  98. }
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // Self-drawing menu items
  102.  
  103. void CMenu::DrawItem(LPDRAWITEMSTRUCT /* lpDrawItemStruct */)
  104. {
  105.     // default drawing does nothing
  106. }
  107.  
  108. void CMenu::MeasureItem(LPMEASUREITEMSTRUCT /* lpMeasureItemStruct */)
  109. {
  110.     // default drawing does nothing
  111. }
  112.  
  113.  
  114. /////////////////////////////////////////////////////////////////////////////
  115.