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

工具条

开发平台:

Visual C++

  1. // SDIMenuFrameWnd.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. - Converted to CNSDIMenuFrameWnd from CMDIMenuFrameWnd
  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 "NGenericDockBar.h"
  18. #include "NMiniDockFrameWnd.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CNSDIMenuFrameWnd
  26. CNSDIMenuFrameWnd::CNSDIMenuFrameWnd()
  27. {
  28. }
  29. CNSDIMenuFrameWnd::~CNSDIMenuFrameWnd()
  30. {
  31. }
  32. IMPLEMENT_DYNAMIC(CNSDIMenuFrameWnd, CFrameWnd)
  33. BEGIN_MESSAGE_MAP(CNSDIMenuFrameWnd, CFrameWnd)
  34. //{{AFX_MSG_MAP(CNSDIMenuFrameWnd)
  35. ON_WM_CREATE()
  36. ON_WM_MENUCHAR()
  37. ON_WM_ACTIVATE()
  38. //}}AFX_MSG_MAP
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CNSDIMenuFrameWnd message handlers
  42. int CNSDIMenuFrameWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  43. {
  44. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  45. return -1;
  46. m_hDefaultMenu=*GetMenu();
  47. SetMenu(NULL);
  48. if(!m_wndMenu.Create(this) ||
  49.    !m_wndMenu.SetMenu(m_hDefaultMenu))
  50. {
  51. TRACE0("CNSDIMenuFrameWnd: Failed to create menun");
  52. return -1;
  53. }
  54. m_wndMenu.EnableDocking(CBRS_ALIGN_ANY);
  55. EnableDocking(CBRS_ALIGN_ANY);
  56. DockControlBar(&m_wndMenu);
  57. return 0;
  58. }
  59. LRESULT CNSDIMenuFrameWnd::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu) 
  60. {
  61. for(int n=0; n<CNGenericToolBar::m_ToolbarList.GetSize(); n++)
  62. {
  63. if(CNGenericToolBar::m_ToolbarList[n]->TranslateMenuChar(nChar))
  64. return MAKELPARAM(MNC_EXECUTE,-1); // Handled by toolbar
  65. }
  66. return CFrameWnd::OnMenuChar(nChar, nFlags, pMenu);
  67. }
  68. void CNSDIMenuFrameWnd::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 
  69. {
  70. if(nState==WA_INACTIVE && pWndOther && pWndOther->IsKindOf(RUNTIME_CLASS(CNGenericPopup)))
  71. return; // Dump the message
  72. CFrameWnd::OnActivate(nState, pWndOther, bMinimized);
  73. }
  74. // dock bars will be created in the order specified by dwDockBarMap
  75. // this also controls which gets priority during layout
  76. // this order can be changed by calling EnableDocking repetitively
  77. // with the exact order of priority
  78. void CNSDIMenuFrameWnd::EnableDocking(DWORD dwDockStyle)
  79. {
  80. // must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
  81. ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
  82. m_pFloatingFrameClass = RUNTIME_CLASS(CNMiniDockFrameWnd);
  83. for (int i = 0; i < 4; i++)
  84. {
  85. if (dwDockBarMap[i][1] & dwDockStyle & CBRS_ALIGN_ANY)
  86. {
  87. CDockBar* pDock = (CDockBar*)GetControlBar(dwDockBarMap[i][0]);
  88. if (pDock == NULL)
  89. {
  90. pDock = new CNGenericDockBar;
  91. if (!pDock->Create(this,
  92. WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_CHILD|WS_VISIBLE |
  93. dwDockBarMap[i][1], dwDockBarMap[i][0]))
  94. {
  95. AfxThrowResourceException();
  96. }
  97. }
  98. }
  99. }
  100. BOOL CNSDIMenuFrameWnd::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle,
  101. CWnd* pParentWnd, CCreateContext* pContext)
  102. {
  103. if (!CFrameWnd::LoadFrame(nIDResource, dwDefaultStyle,
  104.   pParentWnd, pContext))
  105. return FALSE;
  106. // save menu to use when no active MDI child window is present
  107. ASSERT(m_hWnd != NULL);
  108. m_hMenuDefault = ::GetMenu(m_hWnd);
  109. // This fixes a *nasty* MFC bug
  110. // Someone at MS forgot that this would compile differently in release...
  111. #ifdef _DEBUG
  112. if (m_hMenuDefault == NULL)
  113. TRACE0("Warning: CFrameWnd without a default menu.n");
  114. #endif
  115. return TRUE;
  116. }