LeftForm.cpp
上传用户:qhonly
上传日期:2013-06-10
资源大小:487k
文件大小:12k
源码类别:

界面编程

开发平台:

Visual C++

  1. // LeftForm.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "WebGet.h"
  5. #include "LeftForm.h"
  6. #include "MainFrm.h"
  7. #include "RightForm.h"
  8. #include "RTXmlFile.h"
  9. #include "DownInfoType.h"
  10. #include "RTFolder.h"
  11. #include "AddFileDownTaskDlg.h"
  12. #include "OKMessageDlg.h"
  13. // CLeftForm 对话框
  14. IMPLEMENT_DYNAMIC(CLeftForm, CPropertyPage)
  15. IMPLEMENT_MENUXP(CLeftForm,CPropertyPage)
  16. CLeftForm::CLeftForm()
  17. : CPropertyPage(CLeftForm::IDD)
  18. {
  19. m_FileDownSelectIem = NULL;
  20. }
  21. CLeftForm::~CLeftForm()
  22. {
  23. }
  24. void CLeftForm::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CPropertyPage::DoDataExchange(pDX);
  27. DDX_Control(pDX, IDC_TabTaskMgr, m_TabTaskMgr);
  28. DDX_Control(pDX, IDC_TreeFileDown, m_TreeFileDown);
  29. DDX_Control(pDX, IDC_TreeWebMgr, m_TreeWebMgr);
  30. DDX_Control(pDX, IDC_TreeWebDown, m_TreeWebDown);
  31. }
  32. BEGIN_MESSAGE_MAP(CLeftForm, CPropertyPage)
  33. ON_WM_SIZE()
  34. ON_WM_ERASEBKGND()
  35. ON_NOTIFY(TCN_SELCHANGE, IDC_TabTaskMgr, OnTcnSelchangeTabtaskmgr)
  36. ON_NOTIFY(NM_RCLICK, IDC_TreeFileDown, OnNMRclickTreefiledown)
  37. ON_NOTIFY(NM_RCLICK, IDC_TreeWebDown, OnNMRclickTreewebdown)
  38. ON_MENUXP_MESSAGES()
  39. ON_COMMAND(ID_NewFileDownType, OnNewfiledowntype)
  40. ON_COMMAND(ID_DeleteFileDownType, OnDeletefiledowntype)
  41. ON_WM_CLOSE()
  42. ON_COMMAND(ID_FileDownTypeProperty, OnFiledowntypeproperty)
  43. END_MESSAGE_MAP()
  44. // CLeftForm 消息处理程序
  45. void CLeftForm::OnSize(UINT nType, int cx, int cy)
  46. {
  47. CPropertyPage::OnSize(nType, cx, cy);
  48. if(IsWindow(m_TabTaskMgr.m_hWnd))m_TabTaskMgr.MoveWindow(0,0,cx,cy);
  49. }
  50. BOOL CLeftForm::OnInitDialog()
  51. {
  52. CPropertyPage::OnInitDialog();
  53. //Add Tab Items
  54. m_TabTaskMgr.Add(0,"文件下载",0,&m_TreeFileDown.m_Container);
  55. m_TabTaskMgr.Add(1,"站点下载",1,&m_TreeWebDown.m_Container);
  56. m_TabTaskMgr.Add(2,"站点管理",2,&m_TreeWebMgr.m_Container);
  57. InitFileDown();
  58. InitWebDown();
  59. return TRUE;  
  60. }
  61. BOOL CLeftForm::OnEraseBkgnd(CDC* pDC)
  62. {
  63. return TRUE;
  64. }
  65. void CLeftForm::OnTcnSelchangeTabtaskmgr(NMHDR *pNMHDR, LRESULT *pResult)
  66. {
  67. int sel = TabCtrl_GetCurSel(pNMHDR->hwndFrom);
  68. m_RightForm->m_TabRight.SetCurSel(sel);
  69. CWnd *pParent = GetParent();
  70. pParent->SendMessage(WM_NOTIFY,(WPARAM)IDC_TabTaskMgr,(LPARAM)pNMHDR);
  71. *pResult = 0;
  72. }
  73. void CLeftForm::InitWebDown(void)
  74. {
  75. //获取程序启路径
  76. char AppPath[MAX_PATH];
  77. char TypeFile[MAX_PATH];
  78. ZeroMemory(AppPath,MAX_PATH);
  79. DWORD nLen = GetModuleFileName(NULL,AppPath,MAX_PATH) - 1;
  80. while(nLen >= 0)
  81. {
  82. if(AppPath[nLen] == '\')
  83. {
  84. AppPath[nLen] = NULL;
  85. break;
  86. }
  87. nLen --;
  88. }
  89. //文件下载的任务保存路径信息
  90. HTREEITEM hRoot = m_TreeWebDown.InsertItem("站点下载",0,0);
  91. HTREEITEM hItem = NULL;
  92. DownTypeInfo* pDTI = new DownTypeInfo;
  93. ZeroMemory(pDTI->TypePath,MAX_PATH);
  94. strcpy(pDTI->TypePath,AppPath);
  95. strcat(pDTI->TypePath,"\WebDown");
  96. strcpy(pDTI->SavePath,"C:\WebDown");
  97. pDTI->Type = 0;
  98. pDTI->Layer = 0;
  99. strcpy(pDTI->FileFilter,"*");
  100. ZeroMemory(TypeFile,MAX_PATH);
  101. strcpy(TypeFile,pDTI->TypePath);
  102. CDownInfoType::LoadTypeInfo(TypeFile,pDTI);
  103. m_TreeWebDown.SetItemData(hItem,(DWORD_PTR)pDTI);
  104. //下载中的任务保存路径信息
  105. ZeroMemory(TypeFile,MAX_PATH);
  106. strcpy(TypeFile,AppPath);
  107. strcat(TypeFile,"\WebDown");
  108. strcat(TypeFile,"\UnComplete");
  109. pDTI = new DownTypeInfo;
  110. pDTI->Layer = 1;
  111. strcpy(pDTI->TypePath,TypeFile);
  112. strcpy(pDTI->FileFilter,"*");
  113. strcpy(pDTI->SavePath,"C:\WebDown");
  114. pDTI->Type = TYPE_FILEDOWNING;
  115. CDownInfoType::LoadTypeInfo(TypeFile,pDTI);
  116. hItem = m_TreeWebDown.InsertItem("下载中",1,2,hRoot);
  117. m_TreeWebDown.SetItemData(hItem,(DWORD_PTR)pDTI);
  118. //已下载的任务保存路径信息
  119. ZeroMemory(TypeFile,MAX_PATH);
  120. strcpy(TypeFile,AppPath);
  121. strcat(TypeFile,"\WebDown");
  122. strcat(TypeFile,"\Completed");
  123. pDTI = new DownTypeInfo;
  124. pDTI->Layer = 1;
  125. strcpy(pDTI->TypePath,TypeFile);
  126. strcpy(pDTI->FileFilter,"*");
  127. strcpy(pDTI->SavePath,"C:\WebDown");
  128. pDTI->Type = TYPE_FILEDOWNED | TYPE_EDIT;
  129. CDownInfoType::LoadTypeInfo(TypeFile,pDTI);
  130. hItem = m_TreeWebDown.InsertItem("已下载",1,2,hRoot);
  131. m_TreeWebDown.SetItemData(hItem,(DWORD_PTR)pDTI);
  132. CDownInfoType::LoadTreeTypeInfo(m_TreeWebDown, hItem,TYPE_FILEDOWNED);
  133. //已删除的任务保存路径信息
  134. ZeroMemory(TypeFile,MAX_PATH);
  135. strcpy(TypeFile,AppPath);
  136. strcat(TypeFile,"\WebDown");
  137. strcat(TypeFile,"\Recycled");
  138. pDTI = new DownTypeInfo;
  139. pDTI->Layer = 1;
  140. strcpy(pDTI->TypePath,TypeFile);
  141. strcpy(pDTI->FileFilter,"*");
  142. strcpy(pDTI->SavePath,"C:\WebDown");
  143. pDTI->Type = TYPE_RECYCLED;
  144. CDownInfoType::LoadTypeInfo(TypeFile,pDTI);
  145. hItem = m_TreeWebDown.InsertItem("已删除",3,3,hRoot);
  146. m_TreeWebDown.SetItemData(hItem,(DWORD_PTR)pDTI);
  147. CDownInfoType::LoadTreeTypeInfo(m_TreeWebDown,hItem,TYPE_RECYCLED);
  148. m_TreeWebDown.Expand(hRoot,TVE_EXPAND);
  149. }
  150. void CLeftForm::InitFileDown(void)
  151. {
  152. //获取程序启路径
  153. char AppPath[MAX_PATH];
  154. char TypeFile[MAX_PATH];
  155. ZeroMemory(AppPath,MAX_PATH);
  156. DWORD nLen = GetModuleFileName(NULL,AppPath,MAX_PATH) - 1;
  157. while(nLen >= 0)
  158. {
  159. if(AppPath[nLen] == '\')
  160. {
  161. AppPath[nLen] = NULL;
  162. break;
  163. }
  164. nLen --;
  165. }
  166. //文件下载的任务保存路径信息
  167. HTREEITEM hRoot = m_TreeFileDown.InsertItem("文件下载",0,0);
  168. HTREEITEM hItem = NULL;
  169. DownTypeInfo* pDTI = new DownTypeInfo;
  170. ZeroMemory(pDTI->TypePath,MAX_PATH);
  171. strcpy(pDTI->TypePath,AppPath);
  172. strcat(pDTI->TypePath,"\FileDown");
  173. strcpy(pDTI->SavePath,"C:\Download");
  174. pDTI->Type = 0;
  175. pDTI->Layer = 0;
  176. strcpy(pDTI->FileFilter,"*");
  177. ZeroMemory(TypeFile,MAX_PATH);
  178. strcpy(TypeFile,pDTI->TypePath);
  179. CDownInfoType::LoadTypeInfo(TypeFile,pDTI);
  180. m_TreeFileDown.SetItemData(hRoot,(DWORD_PTR)pDTI);
  181. //下载中的任务保存路径信息
  182. ZeroMemory(TypeFile,MAX_PATH);
  183. strcpy(TypeFile,AppPath);
  184. strcat(TypeFile,"\FileDown");
  185. strcat(TypeFile,"\UnComplete");
  186. pDTI = new DownTypeInfo;
  187. pDTI->Layer = 1;
  188. strcpy(pDTI->TypePath,TypeFile);
  189. strcpy(pDTI->FileFilter,"*");
  190. strcpy(pDTI->SavePath,"C:\Download");
  191. pDTI->Type = TYPE_FILEDOWNING;
  192. CDownInfoType::LoadTypeInfo(TypeFile,pDTI);
  193. hItem = m_TreeFileDown.InsertItem("下载中",1,2,hRoot);
  194. m_TreeFileDown.SetItemData(hItem,(DWORD_PTR)pDTI);
  195. m_FileDownUnCompleteItem = hItem;
  196. //已下载的任务保存路径信息
  197. ZeroMemory(TypeFile,MAX_PATH);
  198. strcpy(TypeFile,AppPath);
  199. strcat(TypeFile,"\FileDown");
  200. strcat(TypeFile,"\Completed");
  201. pDTI = new DownTypeInfo;
  202. pDTI->Layer = 1;
  203. strcpy(pDTI->TypePath,TypeFile);
  204. strcpy(pDTI->FileFilter,"*");
  205. strcpy(pDTI->SavePath,"C:\Download");
  206. pDTI->Type = TYPE_FILEDOWNED | TYPE_EDIT | TYPE_ADD;
  207. CDownInfoType::LoadTypeInfo(TypeFile,pDTI);
  208. hItem = m_TreeFileDown.InsertItem("已下载",1,2,hRoot);
  209. m_TreeFileDown.SetItemData(hItem,(DWORD_PTR)pDTI);
  210. m_FileDownCompleteItem = hItem;
  211. CDownInfoType::LoadTreeTypeInfo(m_TreeFileDown,hItem);
  212. //已删除的任务保存路径信息
  213. ZeroMemory(TypeFile,MAX_PATH);
  214. strcpy(TypeFile,AppPath);
  215. strcat(TypeFile,"\FileDown");
  216. strcat(TypeFile,"\Recycled");
  217. pDTI = new DownTypeInfo;
  218. pDTI->Layer = 1;
  219. strcpy(pDTI->TypePath,TypeFile);
  220. strcpy(pDTI->FileFilter,"*");
  221. strcpy(pDTI->SavePath,"C:\Download");
  222. pDTI->Type = TYPE_RECYCLED;
  223. CDownInfoType::LoadTypeInfo(TypeFile,pDTI);
  224. hItem = m_TreeFileDown.InsertItem("已删除",3,3,hRoot);
  225. m_TreeFileDown.SetItemData(hItem,(DWORD_PTR)pDTI);
  226. m_FileDownRecycledItem = hItem;
  227. CDownInfoType::LoadTreeTypeInfo(m_TreeFileDown,hItem,TYPE_RECYCLED);
  228. m_TreeFileDown.Expand(hRoot,TVE_EXPAND);
  229. }
  230. void CLeftForm::OnNMRclickTreefiledown(NMHDR *pNMHDR, LRESULT *pResult)
  231. {
  232. CPoint point;
  233. GetCursorPos(&point);
  234. CPoint pt(point);
  235. m_TreeFileDown.ScreenToClient(&pt);
  236. HTREEITEM hItem = m_TreeFileDown.HitTest(pt);
  237. CMenu menu;
  238. menu.LoadMenu(IDR_MenuFileDown);
  239. CMenu* PopMenu = menu.GetSubMenu(0);
  240. m_FileDownSelectIem = hItem;
  241. if(hItem != NULL)
  242. {
  243. DownTypeInfo* pType = (DownTypeInfo *)m_TreeFileDown.GetItemData(hItem);
  244. if(pType != NULL)
  245. {
  246. if((pType->Type & TYPE_ADD) != TYPE_ADD)
  247. {
  248. PopMenu->EnableMenuItem(ID_NewFileDownType,MF_DISABLED|MF_BYCOMMAND|MF_GRAYED);
  249. }
  250. if((pType->Type & TYPE_EDIT) != TYPE_EDIT)
  251. {
  252. PopMenu->EnableMenuItem(ID_FileDownTypeProperty,MF_DISABLED|MF_BYCOMMAND|MF_GRAYED);
  253. }
  254. if((pType->Type & TYPE_DELETE) != TYPE_DELETE)
  255. {
  256.                 PopMenu->EnableMenuItem(ID_DeleteFileDownType,MF_DISABLED|MF_BYCOMMAND|MF_GRAYED);
  257. PopMenu->EnableMenuItem(ID_MoveFileDownType,MF_DISABLED|MF_BYCOMMAND|MF_GRAYED);
  258. }
  259. }
  260. else
  261. {
  262. }
  263. }
  264. else
  265. {
  266. PopMenu->EnableMenuItem(ID_NewFileDownType,MF_DISABLED|MF_BYCOMMAND|MF_GRAYED);
  267. PopMenu->EnableMenuItem(ID_MoveFileDownType,MF_DISABLED|MF_BYCOMMAND|MF_GRAYED);
  268. PopMenu->EnableMenuItem(ID_DeleteFileDownType,MF_DISABLED|MF_BYCOMMAND|MF_GRAYED);
  269. PopMenu->EnableMenuItem(ID_FileDownTypeProperty,MF_DISABLED|MF_BYCOMMAND|MF_GRAYED);
  270. }
  271. CRTMenu::SetXPLookNFeel(this,PopMenu->GetSafeHmenu(),TRUE);
  272. PopMenu->TrackPopupMenu(TPM_TOPALIGN|TPM_LEFTALIGN,point.x,point.y,this);
  273. *pResult = 0;
  274. }
  275. void CLeftForm::OnNMRclickTreewebdown(NMHDR *pNMHDR, LRESULT *pResult)
  276. {
  277. // TODO: 在此添加控件通知处理程序代码
  278. *pResult = 0;
  279. }
  280. void CLeftForm::OnNewfiledowntype()
  281. {
  282. if(m_FileDownSelectIem == NULL)return;
  283. DownTypeInfo *pInfo = (DownTypeInfo *)m_TreeFileDown.GetItemData(m_FileDownSelectIem);
  284. if(pInfo == NULL)return;
  285. CAddFileDownTaskDlg dlgAdd(this);
  286. CString strTypeName = m_TreeFileDown.GetItemText(m_FileDownSelectIem);
  287. dlgAdd.m_ParentTypeName = strTypeName;
  288. dlgAdd.m_SavePath = pInfo->SavePath;
  289. if(dlgAdd.DoModal() == IDOK)
  290. {
  291. DownTypeInfo* pNewTypeInfo = new DownTypeInfo;
  292. strcpy(pNewTypeInfo->FileFilter,dlgAdd.m_FileFilter);
  293. strcpy(pNewTypeInfo->SavePath,dlgAdd.m_SavePath);
  294. pNewTypeInfo->Layer = pInfo->Layer + 1;
  295. pNewTypeInfo->Type = TYPE_DELETE | TYPE_EDIT | TYPE_FILEDOWNED | TYPE_ADD;
  296. HTREEITEM hItem = m_TreeFileDown.InsertItem(dlgAdd.m_TypeName,1,2,m_FileDownSelectIem);
  297. CString TypeFile = pInfo->TypePath;
  298. TypeFile += "\";
  299. TypeFile += dlgAdd.m_TypeName;
  300. strcpy(pNewTypeInfo->TypePath,TypeFile);
  301. CDownInfoType::LoadTypeInfo(TypeFile,pNewTypeInfo);
  302. m_TreeFileDown.SetItemData(hItem,(DWORD_PTR)pNewTypeInfo);
  303. m_TreeFileDown.RedrawWindow();
  304. }
  305. m_FileDownSelectIem = NULL;
  306. m_TreeFileDown.SetFocus();
  307. }
  308. void CLeftForm::OnDeletefiledowntype()
  309. {
  310. if(m_FileDownSelectIem == NULL)return;
  311. BOOL bDelete = FALSE;
  312. UINT type = CDownInfoType::GetDownInfoType(m_TreeFileDown,m_FileDownSelectIem);
  313. if((type & TYPE_RECYCLED) == TYPE_RECYCLED)bDelete = TRUE;
  314. SHORT lshit = GetKeyState(VK_LSHIFT);
  315. SHORT rshit = GetKeyState(VK_RSHIFT);
  316. //用户按下SHIT键进行删除
  317. if(lshit < 0 || rshit < 0)
  318. {
  319. bDelete = TRUE;
  320. }
  321. if(bDelete)
  322. {
  323. MessageBox("真的要删除些分类及分类下的任务文件吗?","确认",MB_YESNO);
  324. CDownInfoType::DeleteTreeTypeInfo(m_TreeFileDown,m_FileDownSelectIem);
  325. }
  326. else
  327. {
  328. CDownInfoType::MoveTreeTypeInfoTo(m_TreeFileDown,m_FileDownSelectIem,m_FileDownRecycledItem,TYPE_RECYCLED);
  329. }
  330. m_TreeFileDown.SetFocus();
  331. }
  332. void CLeftForm::OnClose()
  333. {
  334. CDownInfoType::ClearTreeTypeInfoData(m_TreeFileDown);
  335. CDownInfoType::ClearTreeTypeInfoData(m_TreeWebDown);
  336. CPropertyPage::OnClose();
  337. }
  338. void CLeftForm::OnFiledowntypeproperty()
  339. {
  340. if(m_FileDownSelectIem == NULL)return;
  341. DownTypeInfo *pInfo = (DownTypeInfo *)m_TreeFileDown.GetItemData(m_FileDownSelectIem);
  342. if(pInfo == NULL)return;
  343. CAddFileDownTaskDlg dlgSave(this,TRUE);
  344. CString strTypeName = m_TreeFileDown.GetItemText(m_FileDownSelectIem);
  345. CString strParentTypeName = m_TreeFileDown.GetItemText( m_TreeFileDown.GetParentItem(m_FileDownSelectIem));
  346. dlgSave.m_ParentTypeName = strParentTypeName;
  347. dlgSave.m_SavePath = pInfo->SavePath;
  348. dlgSave.m_TypeName = strTypeName;
  349. if(IDOK == dlgSave.DoModal())
  350. {
  351. char OldPath[MAX_PATH];
  352. CDownInfoType::GetTreeTypePath(m_TreeFileDown,m_FileDownSelectIem,OldPath);
  353. if(CRTFolder::ReName(OldPath,dlgSave.m_TypeName))
  354. {
  355. strcpy(pInfo->SavePath,dlgSave.m_SavePath);
  356. m_TreeFileDown.SetItemText(m_FileDownSelectIem,dlgSave.m_TypeName);
  357. if(!CDownInfoType::SaveTypeInfo(m_TreeFileDown,m_FileDownSelectIem))
  358. {
  359. //Error
  360. }
  361. }
  362. }
  363. }