GuiMDITabbed.cpp
上传用户:wlkj888
上传日期:2022-08-01
资源大小:806k
文件大小:4k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. /****************************************************************************
  2.  * *  
  3.  * GuiToolKit   *
  4.  *  (MFC extension) *  
  5.  * Created by Francisco Campos G. www.beyondata.com fcampos@beyondata.com *
  6.  *--------------------------------------------------------------------------*    
  7.  * *
  8.  * This program is free software;so you are free to use it any of your *
  9.  * applications (Freeware, Shareware, Commercial),but leave this header *
  10.  * intact. *
  11.  * *
  12.  * These files are provided "as is" without warranty of any kind. *
  13.  * *
  14.  *        GuiToolKit is forever FREE CODE !!!!! *
  15.  * *
  16.  *--------------------------------------------------------------------------*
  17.  * Created by: Francisco Campos G. *
  18.  * Bug Fixes and improvements : (Add your name) *
  19.  * -Francisco Campos *
  20.  * *
  21.  ****************************************************************************/
  22. #include "stdafx.h"
  23. #include "Guimditabbed.h"
  24. #include "GuiMDIFrame.h"
  25. #include "MenuBar.h"
  26. BEGIN_MESSAGE_MAP(CGuiMDITabbed, CGuiTabbed)
  27.   ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
  28.   ON_WM_TIMER()
  29. END_MESSAGE_MAP()
  30. LRESULT CGuiMDITabbed::OnSizeParent(WPARAM, LPARAM lParam)
  31. {
  32. AFX_SIZEPARENTPARAMS* pParams = (AFX_SIZEPARENTPARAMS*)lParam;
  33.     CRect rc=pParams->rect;
  34. CFrameWnd* pParent=(CFrameWnd*)AfxGetMainWnd();
  35. if (pParent->IsKindOf(RUNTIME_CLASS(CFrameWnd)) == NULL) return 0;
  36. CGuiMDIFrame* p= (CGuiMDIFrame*)pParent;
  37. ASSERT_VALID(p);
  38. CMenuBar *m=p->GetMenuBar();
  39. if (!m->GetSafeHwnd()) 
  40. {
  41. KillTimer(1);
  42. return 0;
  43. }
  44. if (rc.top ==0 ) 
  45. {
  46. SetTimer(1,100,NULL);
  47. }
  48. if (GetCount() > 0 && m->IsWindowVisible())
  49. {
  50. pParams->rect.top += 24;
  51. pParams->rect.left+=2;
  52. pParams->rect.right-=1;
  53. pParams->rect.bottom-=1;
  54. ShowWindow(SW_SHOW);
  55. }
  56. else
  57. {
  58. ShowWindow(SW_HIDE);
  59. }
  60.    MoveWindow(rc.left, rc.top , rc.Width(), rc.Height(), true);
  61.    CClientDC dc(this);
  62.    GetClientRect(rc);
  63.    dc.Draw3dRect(rc,GuiDrawLayer::GetRGBColorShadow(GuiDrawLayer::m_Style),GuiDrawLayer::GetRGBColorShadow(GuiDrawLayer::m_Style));
  64.    
  65.    return 0;
  66. }
  67. void CGuiMDITabbed::OnTimer(UINT nIDEvent) 
  68. {
  69. UpdateWindows();
  70. CFrameWnd* pParent = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd());
  71. CGuiMDIFrame* p= (CGuiMDIFrame*)pParent;
  72. ASSERT_VALID(p);
  73. KillTimer(1);
  74. CMenuBar *m=p->GetMenuBar();
  75. if (GetCount() > 0 && m->IsWindowVisible())
  76. {
  77. if(IsWindowVisible()==FALSE)
  78. pParent->SendMessage(WM_SIZE);
  79. }
  80. if (!m->GetSafeHwnd()) 
  81. {
  82. KillTimer(1);
  83. return;
  84. }
  85. if (!m->IsWindowVisible())
  86. {
  87. CRect rc;
  88. ShowWindow(SW_HIDE);
  89. p->RecalcLayout();
  90. }
  91. if(m->IsFloating())
  92. p->RecalcLayout();
  93. }
  94. CGuiMDITabbed::CGuiMDITabbed(void)
  95. {
  96. pParentWindow = NULL;
  97. hMenu=0;
  98. }
  99. CGuiMDITabbed::~CGuiMDITabbed(void)
  100. {
  101. }
  102. void CGuiMDITabbed::OnScrollClose()
  103. {
  104. CWnd* pWnd=GetNumWnd(GetCurtab());
  105. if (pWnd==NULL)
  106. {
  107. return;
  108. }
  109. pWnd->SendMessage(WM_CLOSE);
  110. UpdateWindows();
  111. if (GetCurtab()== 0)
  112. GetParentFrame()->RecalcLayout();
  113. }
  114. void CGuiMDITabbed::UpdateWindows()
  115. {
  116. CFrameWnd* pParent = STATIC_DOWNCAST(CFrameWnd, AfxGetMainWnd());
  117. SetTimer(1,200,NULL);
  118. CWnd* pWnd=CWnd::FromHandle(::GetTopWindow(GetParentFrame()->GetSafeHwnd()));
  119. char ClassName[32];
  120. while (pWnd != NULL)
  121. {
  122. ::GetClassName(pWnd->GetSafeHwnd(),ClassName,32);
  123. CString szClassName=ClassName;
  124. if(szClassName=="MDIClient")
  125. break;
  126. pWnd=pWnd->GetNextWindow();
  127. }
  128. ASSERT(::IsWindow(pWnd->GetSafeHwnd()));
  129. //primero adicionar los nuevos
  130. CWnd* pChild= CWnd::FromHandle(::GetTopWindow(pWnd->GetSafeHwnd()));
  131. while(pChild != NULL)
  132. {
  133. CString m_Caption;
  134. pChild->GetWindowText(m_Caption);
  135. if (!m_Caption.IsEmpty()) 
  136. {
  137. if (!FindItem(pChild->GetSafeHwnd()))
  138. {
  139. Addtab(pChild,m_Caption,-1);
  140. SetTabMenu(hMenu);
  141. }
  142. else
  143. UpdateCaption(pChild,m_Caption);
  144. }
  145. pChild= CWnd::FromHandle(::GetNextWindow(pChild->GetSafeHwnd(), GW_HWNDNEXT));
  146. }
  147. //---eliminar las ventanas borradas
  148. int nNumtabs=GetCount();
  149. for (int i=0; i< nNumtabs; i++)
  150. {
  151. CWnd* pWnd=GetNumWnd(i);
  152. if (!::IsWindow(HWND(pWnd->GetSafeHwnd())))
  153. {
  154. DeleteTab(i);
  155. UpdateWindow();
  156. break;
  157. }
  158. }
  159. SetTimer(1,100,NULL);
  160. }