MyMdi.cpp 5.9 KB

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