MyMdi.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // MyMdi.cpp: implementation of the CMyMdi class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "YLGL.h"
  6. #include "MyMdi.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. BOOL CMyMdi::m_bExitCode = true;
  16. void *CMyMdi::m_pMyMdi = NULL;
  17. extern BOOL g_bShowBar;
  18. CMyMdi::CMyMdi()
  19. {
  20. }
  21. CMyMdi::~CMyMdi()
  22. {
  23. }
  24. ////////////////////////////////////////////////////
  25. //pName 窗口名称
  26. //pNewViewClass 窗口RUNTIME_CLASS名称
  27. //nIcon 窗口图标ID
  28. //pParentWnd 父窗口指针
  29. //返回:
  30. // 0 表示窗口已经存在
  31. // 1 打开窗口成功
  32. // -1 分配内存失败
  33. // -2 创建窗口失败
  34. /////////////////////////////////////////////////////
  35. int CMyMdi::Append(char *pName, CRuntimeClass* pNewViewClass,UINT nIcon,CWnd* pParentWnd,UINT nID)
  36. {
  37. CChildFrame *pView = (CChildFrame*)GetView(pName);
  38. if (pView) //已存在
  39. {
  40. pView->MDIActivate();
  41. return 1;
  42. }
  43. g_bShowBar=0;
  44. MainClose();
  45. #ifdef NEW_SKIN
  46. g_pMainWnd->m_wndClient.ShowCtrls (0);
  47. if(g_pMainWnd2)
  48. {
  49. g_pMainWnd2->ShowBar (0);
  50. }
  51. #endif
  52. g_bShowBar=1;
  53. pView=new CChildFrame;
  54. if (pView == NULL) return -1;
  55. tabMyMdi *pNewMdi =new tabMyMdi;
  56. if (pNewMdi == NULL)
  57. {
  58. delete pView;
  59. return -1;
  60. }
  61. CCreateContext context;
  62. context.m_pNewViewClass=pNewViewClass;
  63. //创建
  64. if(!pView->LoadFrame(nIcon,WS_CHILDWINDOW,pParentWnd,&context))
  65. return -2;
  66. pNewMdi->pSubView = NULL;
  67. pNewMdi->pView = (CWnd *)pView;
  68. memcpy(pNewMdi->szName, pName, 64);
  69. pNewMdi->pNext = (tabMyMdi*)m_pMyMdi;
  70. m_pMyMdi = (void*)pNewMdi;
  71. pView->InitialUpdateFrame(NULL,true); //真正创建
  72. // pNewMdi->pSubView = pView->GetDlgItem(nID);
  73. return 0;
  74. }
  75. /////////////////////////////////////////////
  76. //pName 窗口名称
  77. //返回窗口的索引
  78. int CMyMdi::GetIndex(char *pName)
  79. /////////////////////////////////////////////
  80. {
  81. if(m_pMyMdi == NULL) return -1;
  82. tabMyMdi *pCur = (tabMyMdi*)m_pMyMdi;
  83. int i = 0;
  84. while(pCur)
  85. {
  86. if(strcmp(pName, pCur->szName) == 0)
  87. return i;
  88. pCur = pCur->pNext;
  89. i++;
  90. }
  91. return -1;
  92. }
  93. ///////////////////////////////////////////////////
  94. //pView 窗口指针
  95. //返回窗口名称
  96. char *CMyMdi::GetName(CWnd *pView)
  97. ///////////////////////////////////////////////////
  98. {
  99. /* for (int i = 0; i < m_caView.GetSize(); i++)
  100. {
  101. if (m_caView.GetAt(i) == pView) //有发现
  102. return m_caName.GetAt(i);
  103. }
  104. return _T("");
  105. */
  106. if(m_pMyMdi == NULL) return NULL;
  107. tabMyMdi *pCur = (tabMyMdi*)m_pMyMdi;
  108. while(pCur)
  109. {
  110. if(pView == pCur->pView)
  111. return pCur->szName;
  112. pCur = pCur->pNext;
  113. }
  114. return NULL;
  115. }
  116. ///////////////////////////////////////////////////
  117. //pView 窗口指针
  118. //返回窗口名称
  119. CWnd *CMyMdi::GetView(char *pName)
  120. ///////////////////////////////////////////////////
  121. {
  122. if(m_pMyMdi == NULL) return NULL;
  123. tabMyMdi *pCur = (tabMyMdi*)m_pMyMdi;
  124. while(pCur)
  125. {
  126. if(strcmp(pName, pCur->szName)==0)
  127. return pCur->pView;
  128. pCur = pCur->pNext;
  129. }
  130. return NULL;
  131. }
  132. ///////////////////////////////////////////////////
  133. //pView 窗口指针
  134. //返回子窗口指针
  135. CWnd *CMyMdi::GetSubView(CWnd *pView)
  136. ///////////////////////////////////////////////////
  137. {
  138. if(m_pMyMdi == NULL) return NULL;
  139. tabMyMdi *pCur = (tabMyMdi*)m_pMyMdi;
  140. while(pCur)
  141. {
  142. if(pView == pCur->pView)
  143. return pCur->pSubView;
  144. pCur = pCur->pNext;
  145. }
  146. return NULL;
  147. }
  148. ///////////////////////////////////////////////////
  149. //设置子窗口指针
  150. //pView 窗口指针
  151. //子窗口指针
  152. BOOL CMyMdi::SetSubView(CWnd *pView, CWnd *pDlg)
  153. ///////////////////////////////////////////////////
  154. {
  155. if(m_pMyMdi == NULL) return false;
  156. tabMyMdi *pCur = (tabMyMdi*)m_pMyMdi;
  157. while(pCur)
  158. {
  159. if(pView == pCur->pView)
  160. {
  161. pCur->pSubView = pDlg;
  162. return true;
  163. }
  164. pCur = pCur->pNext;
  165. }
  166. return false;
  167. }
  168. ////////////////////////////////////////////////////
  169. //pView 窗口指针
  170. //删除子窗口
  171. BOOL CMyMdi::Delete(CWnd *pView)
  172. ////////////////////////////////////////////////////
  173. {
  174. if(m_pMyMdi == NULL) return false;
  175. tabMyMdi *pCur = (tabMyMdi*)m_pMyMdi;
  176. tabMyMdi *pBefore = NULL;
  177. while(pCur)
  178. {
  179. if(pView == pCur->pView)
  180. {
  181. if(pBefore == NULL) //首个
  182. {
  183. m_pMyMdi = (void*)((tabMyMdi*)m_pMyMdi)->pNext;
  184. }
  185. else
  186. {
  187. pBefore->pNext = pCur->pNext;
  188. }
  189. delete pCur;
  190. return true;
  191. }
  192. pBefore = pCur;
  193. pCur = pCur->pNext;
  194. }
  195. return FALSE;
  196. }
  197. //////////////////////////////////////////
  198. //pName 窗口名称
  199. //删除窗口登记
  200. BOOL CMyMdi::Delete(char *pName)
  201. //////////////////////////////////////////
  202. {
  203. if(m_pMyMdi == NULL) return false;
  204. tabMyMdi *pCur = (tabMyMdi*)m_pMyMdi;
  205. tabMyMdi *pBefore = NULL;
  206. while(pCur)
  207. {
  208. if(strcmp(pName,pCur->szName)==0)
  209. {
  210. if(pBefore == NULL) //首个
  211. {
  212. m_pMyMdi = (void*)((tabMyMdi*)m_pMyMdi)->pNext;
  213. }
  214. else
  215. {
  216. pBefore->pNext = pCur->pNext;
  217. }
  218. delete pCur;
  219. }
  220. pBefore = pCur;
  221. pCur = pCur->pNext;
  222. return true;
  223. }
  224. return FALSE;
  225. }
  226. //////////////////////////////////////////
  227. //pName 窗口名称
  228. //删除窗口登记
  229. int CMyMdi::GetCount()
  230. //////////////////////////////////////////
  231. {
  232. if(m_pMyMdi == NULL) return -1;
  233. tabMyMdi *pCur = (tabMyMdi*)m_pMyMdi;
  234. int i = 0;
  235. while(pCur)
  236. {
  237. pCur = pCur->pNext;
  238. i++;
  239. }
  240. return i;
  241. // return m_caName.GetSize();
  242. }
  243. BOOL CMyMdi::MainClose(BOOL bMsg)
  244. {
  245. m_bExitCode = true;
  246. if(m_pMyMdi == NULL)return true;
  247. tabMyMdi *pCur = (tabMyMdi*)m_pMyMdi;
  248. CWnd *pView;
  249. while(pCur)
  250. {
  251. pView = pCur->pView;
  252. pCur = pCur->pNext; if(pView)
  253. pView->SendMessage(WM_CLOSE, 0, 0);
  254. if (GetExitCode()==false) return false;
  255. }
  256. return true;
  257. }
  258. BOOL CMyMdi::ChildClose(CWnd *pView)
  259. {
  260. m_bExitCode = true;
  261. CWnd *pSubView = GetSubView(pView);
  262. if (pSubView)
  263. pSubView->SendMessage(WM_CLOSE, 0,0);
  264. if(GetExitCode())
  265. {
  266. Delete(pView);
  267. return true;
  268. }
  269. return false;
  270. }
  271. void CMyMdi::DeleteAll()
  272. {
  273. if(m_pMyMdi == NULL) return ;
  274. tabMyMdi *pCur = (tabMyMdi*)m_pMyMdi;
  275. tabMyMdi *pBefore;
  276. while(pCur)
  277. {
  278. pBefore = pCur;
  279. pCur = pBefore->pNext;
  280. delete pBefore;
  281. }
  282. }
  283. void CMyMdi::CloseAll()
  284. {
  285. MainClose();
  286. }