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

工具条

开发平台:

Visual C++

  1. // MDIMenuFrameWnd.cpp : implementation file
  2. //
  3. /*
  4. Copyright (C) 1998 Tony Hoyle (tmh@netfusion.co.uk)
  5. Copyright (C) 1998 George H. Stahl (GStahl@VipMail.Com)
  6. -added m_pFloatingFrameClass = RUNTIME_CLASS(CNMiniDockFrameWnd);
  7.  This program is free software; you can redistribute it and/or modify it under the terms
  8. of the GNU General Public License as published by the Free Software Foundation; either
  9. version 2 of the License, or (at your option) any later version.
  10. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  11. without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. See the GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License along with this program;
  14. if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include "stdafx.h"
  17. #include "NMDIMenuFrameWnd.h"
  18. #include "NGenericToolBar.h"
  19. #include "NGenericDockBar.h"
  20. #include "NMiniDockFrameWnd.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CNMDIMenuFrameWnd
  28. CNMDIMenuFrameWnd::CNMDIMenuFrameWnd()
  29. {
  30. }
  31. CNMDIMenuFrameWnd::~CNMDIMenuFrameWnd()
  32. {
  33. }
  34. IMPLEMENT_DYNAMIC(CNMDIMenuFrameWnd, CMDIFrameWnd)
  35. BEGIN_MESSAGE_MAP(CNMDIMenuFrameWnd, CMDIFrameWnd)
  36. //{{AFX_MSG_MAP(CNMDIMenuFrameWnd)
  37. ON_WM_CREATE()
  38. ON_WM_MENUCHAR()
  39. ON_WM_ACTIVATE()
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CNMDIMenuFrameWnd message handlers
  44. int CNMDIMenuFrameWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  45. {
  46. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  47. return -1;
  48. m_hDefaultMenu=*GetMenu();
  49. SetMenu(NULL);
  50. if(!m_wndMenu.Create(this) ||
  51.    !m_wndMenu.SetMenu(m_hDefaultMenu))
  52. {
  53. TRACE0("CNMDIMenuFrameWnd: Failed to create menun");
  54. return -1;
  55. }
  56. m_wndMenu.EnableDocking(CBRS_ALIGN_ANY);
  57. EnableDocking(CBRS_ALIGN_ANY);
  58. DockControlBar(&m_wndMenu);
  59. return 0;
  60. }
  61. BOOL CNMDIMenuFrameWnd::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
  62. {
  63. if(!CMDIFrameWnd::OnCreateClient(lpcs, pContext)) return FALSE;
  64. m_wndMenu.SubclassMDIClient(m_hWndMDIClient);
  65. return TRUE;
  66. }
  67. LRESULT CNMDIMenuFrameWnd::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu) 
  68. {
  69. for(int n=0; n<CNGenericToolBar::m_ToolbarList.GetSize(); n++)
  70. {
  71. if(CNGenericToolBar::m_ToolbarList[n]->TranslateMenuChar(nChar))
  72. return MAKELPARAM(MNC_EXECUTE,-1); // Handled by toolbar
  73. }
  74. return CMDIFrameWnd::OnMenuChar(nChar, nFlags, pMenu);
  75. }
  76. void CNMDIMenuFrameWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 
  77. {
  78. if(nState==WA_INACTIVE && pWndOther && pWndOther->IsKindOf(RUNTIME_CLASS(CNGenericPopup)))
  79. return; // Dump the message
  80. CMDIFrameWnd::OnActivate(nState, pWndOther, bMinimized);
  81. }
  82. // dock bars will be created in the order specified by dwDockBarMap
  83. // this also controls which gets priority during layout
  84. // this order can be changed by calling EnableDocking repetitively
  85. // with the exact order of priority
  86. void CNMDIMenuFrameWnd::EnableDocking(DWORD dwDockStyle)
  87. {
  88. // must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
  89. ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
  90. m_pFloatingFrameClass = RUNTIME_CLASS(CNMiniDockFrameWnd);
  91. for (int i = 0; i < 4; i++)
  92. {
  93. if (dwDockBarMap[i][1] & dwDockStyle & CBRS_ALIGN_ANY)
  94. {
  95. CDockBar* pDock = (CDockBar*)GetControlBar(dwDockBarMap[i][0]);
  96. if (pDock == NULL)
  97. {
  98. pDock = new CNGenericDockBar;
  99. if (!pDock->Create(this,
  100. WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_CHILD|WS_VISIBLE |
  101. dwDockBarMap[i][1], dwDockBarMap[i][0]))
  102. {
  103. AfxThrowResourceException();
  104. }
  105. }
  106. }
  107. }
  108. BOOL CNMDIMenuFrameWnd::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
  109. CWnd* pParentWnd, CCreateContext* pContext)
  110. {
  111. if (!CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle,
  112.   pParentWnd, pContext))
  113. return FALSE;
  114. // save menu to use when no active MDI child window is present
  115. ASSERT(m_hWnd != NULL);
  116. m_hMenuDefault = ::GetMenu(m_hWnd);
  117. // This fixes a *nasty* MFC bug
  118. // Someone at MS forgot that this would compile differently in release...
  119. #ifdef _DEBUG
  120. if (m_hMenuDefault == NULL)
  121. TRACE0("Warning: CMDIFrameWnd without a default menu.n");
  122. #endif
  123. return TRUE;
  124. }