NGenericPopup.cpp
上传用户:libwxy
上传日期:2007-01-02
资源大小:200k
文件大小:2k
源码类别:

工具条

开发平台:

Visual C++

  1. // NGenericPopup.cpp : implementation file
  2. //
  3. /*
  4. Copyright (C) 1998 Tony Hoyle (tmh@netfusion.co.uk)
  5. This program is free software; you can redistribute it and/or modify it under the terms
  6. of the GNU General Public License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  9. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License along with this program;
  12. if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  13. */
  14. #include "stdafx.h"
  15. #include "NGenericPopup.h"
  16. #include "NGenericToolBar.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. /////////////////////////////////////////////////////////////////////////////
  23. // CNGenericPopup
  24. CNGenericPopup::CNGenericPopup()
  25. {
  26. m_pMenu=new CMenu;
  27. m_bIsAttached = FALSE;
  28. }
  29. CNGenericPopup::~CNGenericPopup()
  30. {
  31. m_pMenu->m_hMenu=NULL;
  32. delete m_pMenu;
  33. }
  34. IMPLEMENT_DYNAMIC(CNGenericPopup, CWnd)
  35. BEGIN_MESSAGE_MAP(CNGenericPopup, CWnd)
  36. //{{AFX_MSG_MAP(CNGenericPopup)
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CNGenericPopup message handlers
  41. BOOL CNGenericPopup::ShowMenu(/*int nOrient, */BOOL bFromKey, /*CNGenericToolBar* pToolbar, */int x, int y, CWnd* pParent, HMENU hMenu)
  42. {
  43. ASSERT(hMenu);
  44. HideMenu();
  45. m_pMenu->m_hMenu=hMenu;
  46. m_pParent=pParent;
  47. if ((FALSE == m_bIsAttached) && (TRUE == m_cSubMenu.Attach (m_pMenu->m_hMenu)))
  48. {
  49. m_cSubMenu.TrackPopupMenu (TPM_LEFTALIGN , x , y , m_pParent , NULL);
  50. m_pParent->SendMessage(WM_ENTERMENULOOP,FALSE);
  51. m_bIsAttached = TRUE;
  52. }
  53. if(bFromKey)
  54. {
  55. m_pParent->SendMessage (WM_MENUSELECT , 0 , (LPARAM)hMenu);
  56. }
  57. return TRUE;
  58. }
  59. BOOL CNGenericPopup::HideMenu()
  60. {
  61. if (m_bIsAttached == TRUE)
  62. {
  63. m_cSubMenu.Detach ();
  64. m_pParent->SendMessage(WM_EXITMENULOOP,(WPARAM)FALSE,0);
  65. m_bIsAttached = FALSE;
  66. }
  67. return TRUE;
  68. }