MAINFRM.CPP
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:66k
源码类别:

Ftp客户端

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "xiongFtp.h"
  5. #include "XiongFtpView.h"
  6. #include "MainFrm.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMainFrame
  14. BOOL IsFree, m_bConnected;
  15. int nThreadCount;
  16. CFtpInfoView* pFtpInfoView;
  17. CLocFileView* pLocView;
  18. CServFileView* pServView;
  19. HINTERNET hInetSession;
  20. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  21. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  22. ON_COMMAND_EX(CG_ID_VIEW_MYDIALOGBAR, OnBarCheck)
  23. ON_UPDATE_COMMAND_UI(CG_ID_VIEW_MYDIALOGBAR, OnUpdateControlBarMenu)
  24. //{{AFX_MSG_MAP(CMainFrame)
  25. ON_WM_CREATE()
  26. ON_BN_CLICKED(IDC_QUICKCONNECT, OnQuickconnect)
  27. ON_COMMAND(ID_FILE_DISCONNECT, OnFileDisconnect)
  28. ON_UPDATE_COMMAND_UI(ID_FILE_DISCONNECT, OnUpdateFileDisconnect)
  29. ON_COMMAND(IDC_FILE_RECONNECT, OnFileReconnect)
  30. ON_COMMAND(ID_FILE_CONNECT, OnFileConnect)
  31. ON_UPDATE_COMMAND_UI(ID_FILE_CONNECT, OnUpdateFileConnect)
  32. ON_UPDATE_COMMAND_UI(IDC_FILE_RECONNECT, OnUpdateFileReconnect)
  33. ON_COMMAND(ID_FILE_STOP, OnFileStop)
  34. ON_UPDATE_COMMAND_UI(ID_FILE_STOP, OnUpdateFileStop)
  35. ON_UPDATE_COMMAND_UI(ID_FILE_SEND, OnUpdateFileSend)
  36. ON_UPDATE_COMMAND_UI(ID_FILE_FTP_DOWNLOAD, OnUpdateFileFtpDownload)
  37. //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39. static UINT indicators[] =
  40. {
  41. ID_SEPARATOR,           // status line indicator
  42. ID_INDICATOR_CAPS,
  43. ID_INDICATOR_NUM,
  44. ID_INDICATOR_SCRL,
  45. };
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CMainFrame construction/destruction
  48. CMainFrame::CMainFrame()
  49. {
  50. m_bConnected=FALSE;
  51. }
  52. CMainFrame::~CMainFrame()
  53. {
  54. InternetCloseHandle(hInetSession);
  55. }
  56. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  57. {
  58. CImageList imageList;
  59. CBitmap bitmap;
  60. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  61. return -1;
  62. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  63. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  64. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  65. {
  66. TRACE0("Failed to create toolbarn");
  67. return -1;      // fail to create
  68. }
  69. if (!m_wndStatusBar.Create(this) ||
  70. !m_wndStatusBar.SetIndicators(indicators,
  71.   sizeof(indicators)/sizeof(UINT)))
  72. {
  73. TRACE0("Failed to create status barn");
  74. return -1;      // fail to create
  75. }
  76. // TODO: Delete these three lines if you don't want the toolbar to
  77. //  be dockable
  78. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  79. EnableDocking(CBRS_ALIGN_ANY);
  80. DockControlBar(&m_wndToolBar);
  81. // TODO: Add a menu item that will toggle the visibility of the // dialog bar named "My Dialog Bar": //   1. In ResourceView, open the menu resource that is used by //      the CMainFrame class //   2. Select the View submenu //   3. Double-click on the blank item at the bottom of the submenu //   4. Assign the new item an ID: CG_ID_VIEW_MYDIALOGBAR //   5. Assign the item a Caption: My Dialog Bar // TODO: Change the value of CG_ID_VIEW_MYDIALOGBAR to an appropriate value: //   1. Open the file resource.h // CG: The following block was inserted by the 'Dialog Bar' component { // Initialize dialog bar m_wndMyDialogBar if (!m_wndMyDialogBar.Create(this, CG_IDD_MYDIALOGBAR, CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE, CG_ID_VIEW_MYDIALOGBAR)) { TRACE0("Failed to create dialog bar m_wndMyDialogBarn"); return -1; // fail to create } m_wndMyDialogBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndMyDialogBar);
  82. m_wndMyDialogBar.SetDlgItemText(IDC_FTPPORT,"21");
  83. m_wndMyDialogBar.SetDlgItemText(IDC_FTPNAME,"162.105.140.202");
  84. m_wndMyDialogBar.SetDlgItemText(IDC_FTPUSER,"Anonymous");
  85. m_wndMyDialogBar.SetDlgItemText(IDC_FTPPASSWORD,"guest@163.net");
  86. m_wndMyDialogBar.GetDlgItem(IDC_QUICKCONNECT)->ShowWindow(SW_HIDE); }
  87. return 0;
  88. }
  89. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  90. {
  91. if( !CFrameWnd::PreCreateWindow(cs) )
  92. return FALSE;
  93. // TODO: Modify the Window class or styles here by modifying
  94. //  the CREATESTRUCT cs
  95. return TRUE;
  96. }
  97. CString CMainFrame::GetFtpName()
  98. {
  99. CString str;
  100. m_wndMyDialogBar.GetDlgItemText(IDC_FTPNAME,str);
  101. return str;
  102. }
  103. int CMainFrame::GetFtpPort()
  104. {
  105. CString str;
  106. m_wndMyDialogBar.GetDlgItemText(IDC_FTPPORT,str);
  107. int i=atoi(str);
  108. return i;
  109. }
  110. CString CMainFrame::GetFtpUser()
  111. {
  112. CString str;
  113. m_wndMyDialogBar.GetDlgItemText(IDC_FTPUSER,str);
  114. return str;
  115. }
  116. CString CMainFrame::GetFtpPassword()
  117. {
  118. CString str;
  119. m_wndMyDialogBar.GetDlgItemText(IDC_FTPPASSWORD,str);
  120. return str;
  121. }
  122. void CMainFrame::OnQuickconnect() 
  123. {
  124. if(!hInetSession)return;
  125. pServView->OnQuickConnect();
  126. }
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CMainFrame diagnostics
  129. #ifdef _DEBUG
  130. void CMainFrame::AssertValid() const
  131. {
  132. CFrameWnd::AssertValid();
  133. }
  134. void CMainFrame::Dump(CDumpContext& dc) const
  135. {
  136. CFrameWnd::Dump(dc);
  137. }
  138. #endif //_DEBUG
  139. /////////////////////////////////////////////////////////////////////////////
  140. // CMainFrame message handlers
  141. //////////////////////////////////////////////////////////////////////
  142. // CFtpParaClass Class
  143. //////////////////////////////////////////////////////////////////////
  144. //////////////////////////////////////////////////////////////////////
  145. // Construction/Destruction
  146. //////////////////////////////////////////////////////////////////////
  147. CFtpParaClass::CFtpParaClass()
  148. {
  149. HIMAGELIST hImageList;
  150. SHFILEINFO shFi;
  151. hImageList=(HIMAGELIST)SHGetFileInfo("C:\",0,&shFi,sizeof(shFi),
  152. SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
  153. if(!hImageList)
  154. return ;
  155. m_ctImageList.m_hImageList=hImageList;
  156. m_hDragCursor=AfxGetApp()->LoadIcon(IDI_CURSOR);
  157. m_bDragging=FALSE;
  158. }
  159. CFtpParaClass::~CFtpParaClass()
  160. {
  161. if(m_ctImageList.m_hImageList)
  162. m_ctImageList.Detach();
  163. }
  164. void CFtpParaClass::SetFileColumns(CListCtrl* pListCtrl)
  165. {
  166. static struct
  167. {
  168. LPSTR pszText;
  169. int uiFormat;
  170. }columns[]={
  171. _T("文件名"),LVCFMT_LEFT,
  172. _T("日期"),LVCFMT_CENTER,
  173. _T("字节数"),LVCFMT_CENTER
  174. };
  175. for(int i=0,j=120;i<sizeof(columns)/sizeof(columns[0]);i++,j-=10)
  176. pListCtrl->InsertColumn(i,columns[i].pszText,columns[i].uiFormat,j);
  177. }
  178. void CFtpParaClass::SetPopMenu(int nIndex)
  179. {
  180. CMenu dMenu;
  181. if(!dMenu.LoadMenu(IDR_LOC_SERV_MENU))
  182. AfxThrowResourceException();
  183. CMenu* pPopMenu=dMenu.GetSubMenu(nIndex);
  184. ASSERT(pPopMenu!=NULL);
  185. POINT pt;
  186. ::GetCursorPos(&pt);
  187. pPopMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,pt.x,pt.y,AfxGetMainWnd());
  188. }
  189. BOOL CFtpParaClass::SetImageList(CListCtrl* pListCtrl,CComboBoxEx* pCombo)
  190. {
  191. pListCtrl->SetImageList(&m_ctImageList,LVSIL_SMALL);
  192. if(!pCombo)
  193. return TRUE;
  194. pCombo->SetImageList(&m_ctImageList);
  195. return TRUE;
  196. }
  197. void CFtpParaClass::GetFileIcon(CString& fileName,int* iIcon,int* iIconSel)
  198. {
  199. CString str=fileName;
  200. if(str.Right(1)!="\")
  201. str+="\";
  202. SHFILEINFO shFi;
  203. SHGetFileInfo(str,0,&shFi,sizeof(shFi),SHGFI_ICON|SHGFI_SMALLICON|SHGFI_DISPLAYNAME);
  204. *iIcon=shFi.iIcon;
  205. DestroyIcon(shFi.hIcon);
  206. if(iIconSel)
  207. {
  208. SHGetFileInfo(str,0,&shFi,sizeof(shFi),SHGFI_ICON|SHGFI_SMALLICON|SHGFI_OPENICON|SHGFI_DISPLAYNAME);
  209. *iIconSel=shFi.iIcon;
  210. DestroyIcon(shFi.hIcon);
  211. }
  212. // fileName=shFi.szDisplayName;
  213. return ;
  214. }
  215. void CFtpParaClass::OnInsertFile(CListCtrl* pListCtrl,LPVOID pIn,LPARAM lParam)
  216. {
  217. FILE_FTP_INFO*pInfo=(FILE_FTP_INFO*)pIn;
  218. LVITEM lvIt;
  219. int iIcon,nItem;
  220. if(pInfo->nType==DIRECTORYICON)
  221. nItem=0;
  222. else
  223. nItem=pListCtrl->GetItemCount();
  224. CString fileName=pInfo->szFilePath;
  225. if(fileName.Right(1)=="\")
  226. fileName+=pInfo->szFileName;
  227. else
  228. {
  229. fileName+="\";
  230. fileName+=pInfo->szFileName;
  231. }
  232. if((int)lParam==LOCFILE)
  233. GetFileIcon(fileName,&iIcon);
  234. else
  235. iIcon=pInfo->nType;
  236. lvIt.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
  237. lvIt.iImage=iIcon;
  238. lvIt.lParam=pInfo->nType;
  239. lvIt.pszText=pInfo->szFileName;
  240. lvIt.iSubItem=0;
  241. lvIt.iItem=nItem;
  242. int iPos=pListCtrl->InsertItem(&lvIt);
  243. lvIt.mask=LVIF_TEXT;
  244. lvIt.iItem=iPos;
  245. lvIt.pszText=pInfo->szFileDate;
  246. lvIt.iSubItem=1;
  247. pListCtrl->SetItem(&lvIt);
  248. lvIt.pszText=pInfo->szFileSize;
  249. lvIt.iSubItem=2;
  250. pListCtrl->SetItem(&lvIt);
  251. IsFree=TRUE;
  252. }
  253. int CFtpParaClass::OnInsertDir(CComboBoxEx* pCombo,CString& str,int iIcon,int iIconSel)
  254. {
  255. int nItem=pCombo->GetCount();
  256. COMBOBOXEXITEM Combo;
  257. Combo.mask=CBEIF_IMAGE|CBEIF_TEXT|CBEIF_SELECTEDIMAGE;
  258. Combo.iImage=iIcon;
  259. Combo.iSelectedImage=iIconSel;
  260. Combo.pszText=(LPTSTR)(LPCTSTR)str;
  261.     Combo.iItem=nItem;
  262. pCombo->InsertItem(&Combo);
  263. return nItem;
  264. }
  265. void CFtpParaClass::OnFileName(CListCtrl* pListCtrl)
  266. {
  267. POSITION iPos=pListCtrl->GetFirstSelectedItemPosition();
  268. CString str;
  269. int nItem=pListCtrl->GetNextSelectedItem(iPos);
  270. if(nItem==-1)return;
  271. str=pListCtrl->GetItemText(nItem,0);
  272. CInputEdit* pEdit=new CInputEdit(nItem,0,str,pListCtrl);
  273. CRect rect;
  274. pListCtrl->GetItemRect(nItem,&rect,LVIR_LABEL);
  275. rect.left+=1;
  276. rect.right-=10;
  277. rect.top+=26;
  278. rect.bottom+=26;
  279. pEdit->Create(WS_CHILD|WS_VISIBLE|ES_LEFT|WS_BORDER|ES_MULTILINE|ES_AUTOVSCROLL,rect,pListCtrl->GetParent(),IDD_INPUT_EDIT);
  280. }
  281. /////////////////////////////////////////////////////////////////////////////
  282. // CLocFileView
  283. IMPLEMENT_DYNCREATE(CLocFileView, CFormView)
  284. CLocFileView::CLocFileView()
  285. : CFormView(CLocFileView::IDD)
  286. {
  287. m_bHaveDotFlag=FALSE;
  288. m_pSendFileThread=NULL;
  289. //{{AFX_DATA_INIT(CLocFileView)
  290. // NOTE: the ClassWizard will add member initialization here
  291. //}}AFX_DATA_INIT
  292. }
  293. CLocFileView::~CLocFileView()
  294. {
  295. if(m_pFindLocFileThread)
  296. {
  297. m_pFindLocFileThread->ResumeThread();
  298. ::WaitForSingleObject(m_pFindLocFileThread->m_hThread,100);
  299. delete m_pFindLocFileThread;
  300. }
  301. if(m_pSendFileThread)
  302. {   m_pSendFileThread->ResumeThread();
  303. ::WaitForSingleObject(m_pSendFileThread->m_hThread,100);
  304. delete m_pSendFileThread;
  305. }
  306. }
  307. void CLocFileView::DoDataExchange(CDataExchange* pDX)
  308. {
  309. CFormView::DoDataExchange(pDX);
  310. //{{AFX_DATA_MAP(CLocFileView)
  311. DDX_Control(pDX, IDC_LOC_FILE, m_ctLocFile);
  312. DDX_Control(pDX, IDC_LOC_DIR, m_ctLocDir);
  313. //}}AFX_DATA_MAP
  314. }
  315. BEGIN_MESSAGE_MAP(CLocFileView, CFormView)
  316. //{{AFX_MSG_MAP(CLocFileView)
  317. ON_NOTIFY(NM_DBLCLK, IDC_LOC_FILE, OnDblclkLocFile)
  318. ON_WM_SIZE()
  319. ON_CBN_SELCHANGE(IDC_LOC_DIR, OnSelchangeLocDir)
  320. ON_NOTIFY(LVN_BEGINDRAG, IDC_LOC_FILE, OnBegindragLocFile)
  321. ON_WM_MOUSEMOVE()
  322. ON_WM_LBUTTONUP()
  323. ON_NOTIFY(NM_RCLICK, IDC_LOC_FILE, OnRclickLocFile)
  324. ON_NOTIFY(LVN_BEGINLABELEDIT, IDC_LOC_FILE, OnBeginlabeleditLocFile)
  325. ON_NOTIFY(LVN_ENDLABELEDIT, IDC_LOC_FILE, OnEndlabeleditLocFile)
  326. //}}AFX_MSG_MAP
  327. ON_MESSAGE(WM_SETFILE,CLocFileView::OnInsertLocFile)
  328. ON_MESSAGE(WM_SETREDRAWFLAG,CLocFileView::OnSetLocRedrawFlag)
  329. ON_MESSAGE(WM_SETDIRECTORYDISPLAY,CLocFileView::OnSetLocDirectoryDisplay)
  330. ON_MESSAGE(WM_REDISPLAYFILE,CLocFileView::OnReDisplayLocFile)
  331. ON_MESSAGE(WM_SETDIR,CLocFileView::OnSetLocDir)
  332. ON_MESSAGE(WM_PRESENDFILE,CLocFileView::OnPreSendFile)
  333. ON_COMMAND(ID_FILE_DELETE,CLocFileView::OnLocFileDelete)
  334. ON_COMMAND(ID_FILE_SEND,CLocFileView::OnLocFileSend)
  335. ON_COMMAND(ID_FILE_RENAME,CLocFileView::OnLocFileReName)
  336. ON_COMMAND(ID_FILE_EXECUTE,CLocFileView::OnLocFileOpen)
  337. END_MESSAGE_MAP()
  338. /////////////////////////////////////////////////////////////////////////////
  339. // CLocFileView diagnostics
  340. #ifdef _DEBUG
  341. void CLocFileView::AssertValid() const
  342. {
  343. CFormView::AssertValid();
  344. }
  345. void CLocFileView::Dump(CDumpContext& dc) const
  346. {
  347. CFormView::Dump(dc);
  348. }
  349. #endif //_DEBUG
  350. /////////////////////////////////////////////////////////////////////////////
  351. // CLocFileView message handlers
  352. /////////////////////////////////////////////////////////////////////////////
  353. // CServFileView
  354. IMPLEMENT_DYNCREATE(CServFileView, CFormView)
  355. CServFileView::CServFileView()
  356. : CFormView(CServFileView::IDD)
  357. {
  358. m_bHaveDotFlag=FALSE;
  359. m_pRenameFileThread=NULL;
  360. m_pReceiveFileThread=NULL;
  361. m_pFindServFileThread=NULL;
  362. m_pDeleteFileThread=NULL;
  363. //{{AFX_DATA_INIT(CServFileView)
  364. //}}AFX_DATA_INIT
  365. }
  366. CServFileView::~CServFileView()
  367. {
  368. if(m_ctServImageList.m_hImageList)
  369. m_ctServImageList.Detach();
  370. if(m_pFindServFileThread)
  371. {
  372. ::WaitForSingleObject(m_pFindServFileThread->m_hThread,100);
  373. delete m_pFindServFileThread;
  374. }
  375. if(m_pReceiveFileThread)
  376. {
  377. ::WaitForSingleObject(m_pReceiveFileThread->m_hThread,100);
  378. delete m_pReceiveFileThread;
  379. }
  380. if(m_pDeleteFileThread)
  381. {
  382. ::WaitForSingleObject(m_pDeleteFileThread->m_hThread,100);
  383. delete m_pDeleteFileThread;
  384. }
  385. if(m_pRenameFileThread)
  386. {
  387. ::WaitForSingleObject(m_pRenameFileThread->m_hThread,100);
  388. delete m_pRenameFileThread;
  389. }
  390. DeleteObject(hBitmap);
  391. }
  392. void CServFileView::DoDataExchange(CDataExchange* pDX)
  393. {
  394. CFormView::DoDataExchange(pDX);
  395. //{{AFX_DATA_MAP(CServFileView)
  396. DDX_Control(pDX, IDC_BACK, m_ctBack);
  397. DDX_Control(pDX, IDC_SERV_FILE, m_ctServFile);
  398. DDX_Control(pDX, IDC_SERV_DIR, m_ctServDir);
  399. //}}AFX_DATA_MAP
  400. }
  401. BEGIN_MESSAGE_MAP(CServFileView, CFormView)
  402. //{{AFX_MSG_MAP(CServFileView)
  403. ON_WM_SIZE()
  404. ON_NOTIFY(NM_DBLCLK, IDC_SERV_FILE, OnDblclkServFile)
  405. ON_NOTIFY(LVN_BEGINDRAG, IDC_SERV_FILE, OnBegindragServFile)
  406. ON_WM_MOUSEMOVE()
  407. ON_WM_LBUTTONUP()
  408. ON_NOTIFY(NM_RCLICK, IDC_SERV_FILE, OnRclickServFile)
  409. ON_NOTIFY(LVN_BEGINLABELEDIT, IDC_SERV_FILE, OnBeginlabeleditServFile)
  410. ON_NOTIFY(LVN_ENDLABELEDIT, IDC_SERV_FILE, OnEndlabeleditServFile)
  411. ON_BN_CLICKED(IDC_BACK, OnBack)
  412. ON_CBN_SELCHANGE(IDC_SERV_DIR, OnSelchangeServDir)
  413. //}}AFX_MSG_MAP
  414. ON_MESSAGE(WM_SETFILE,CServFileView::OnInsertServFile)
  415. ON_MESSAGE(WM_SETREDRAWFLAG,CServFileView::OnSetServRedrawFlag)
  416. ON_MESSAGE(WM_SETDIRECTORYDISPLAY,CServFileView::OnSetServDirectoryDisplay)
  417. ON_MESSAGE(WM_REDISPLAYFILE,CServFileView::OnReDisplayServFile)
  418. ON_MESSAGE(WM_SETDIR,CServFileView::OnSetServDir)
  419. ON_MESSAGE(WM_PREDELETEFILE,CServFileView::OnPreDeleteFile)
  420. ON_MESSAGE(WM_PRERECEIVEFILE,CServFileView::OnPreReceiveFile)
  421. ON_COMMAND(ID_FILE_DELETE,CServFileView::OnServFileDelete)
  422. ON_COMMAND(ID_FILE_FTP_DOWNLOAD,CServFileView::OnServFileDownload)
  423. ON_COMMAND(ID_FILE_RENAME,CServFileView::OnServFileReName)
  424. END_MESSAGE_MAP()
  425. /////////////////////////////////////////////////////////////////////////////
  426. // CServFileView diagnostics
  427. #ifdef _DEBUG
  428. void CServFileView::AssertValid() const
  429. {
  430. CFormView::AssertValid();
  431. }
  432. void CServFileView::Dump(CDumpContext& dc) const
  433. {
  434. CFormView::Dump(dc);
  435. }
  436. #endif //_DEBUG
  437. /////////////////////////////////////////////////////////////////////////////
  438. // CServFileView message handlers
  439. /////////////////////////////////////////////////////////////////////////////
  440. // CFtpInfoView
  441. IMPLEMENT_DYNCREATE(CFtpInfoView, CEditView)
  442. CFtpInfoView::CFtpInfoView()
  443. {
  444. }
  445. CFtpInfoView::~CFtpInfoView()
  446. {
  447. m_NewFont.DeleteObject();
  448. }
  449. BEGIN_MESSAGE_MAP(CFtpInfoView, CEditView)
  450. //{{AFX_MSG_MAP(CFtpInfoView)
  451. ON_WM_CREATE()
  452. ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
  453. ON_WM_CHAR()
  454. //}}AFX_MSG_MAP
  455. ON_MESSAGE(WM_RECORDFTPINFO,CFtpInfoView::OnRecordFtpInfo)
  456. END_MESSAGE_MAP()
  457. /////////////////////////////////////////////////////////////////////////////
  458. // CFtpInfoView drawing
  459. void CFtpInfoView::OnDraw(CDC* pDC)
  460. {
  461. CDocument* pDoc = GetDocument();
  462. }
  463. /////////////////////////////////////////////////////////////////////////////
  464. // CFtpInfoView diagnostics
  465. #ifdef _DEBUG
  466. void CFtpInfoView::AssertValid() const
  467. {
  468. CEditView::AssertValid();
  469. }
  470. void CFtpInfoView::Dump(CDumpContext& dc) const
  471. {
  472. CEditView::Dump(dc);
  473. }
  474. #endif //_DEBUG
  475. /////////////////////////////////////////////////////////////////////////////
  476. // CFtpInfoView message handlers
  477. LRESULT CFtpInfoView::OnRecordFtpInfo(WPARAM wParam,LPARAM lParam)
  478. {
  479. CEdit& edit=GetEditCtrl();
  480. CString str=(LPCTSTR)lParam;
  481. int nLine=edit.GetLineCount();
  482. int nStart=edit.LineIndex(nLine);
  483. edit.SetSel(nStart,str.GetLength()+nStart);
  484. edit.ReplaceSel("rn"+str);
  485. return 0L;
  486. }
  487. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
  488. {
  489. // CG: The following block was added by the Splitter Bar component. { if(!m_wndSplitter1.CreateStatic(this,3,1))
  490. return FALSE;
  491.         if(!m_wndSplitter1.CreateView(0,0,RUNTIME_CLASS(CFtpInfoView),CSize(375,100),pContext)||
  492. !m_wndSplitter1.CreateView(2,0,RUNTIME_CLASS(CXiongFtpView),CSize(375,100),pContext))
  493. return FALSE;
  494. m_wndSplitter1.SetRowInfo(1,180,0);
  495. if(m_wndSplitter2.CreateStatic(&m_wndSplitter1,1,2,WS_CHILD|WS_VISIBLE,m_wndSplitter1.IdFromRowCol(1,0))==NULL)
  496. return FALSE;
  497. if(!m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(CLocFileView),CSize(375,180),pContext)||
  498. !m_wndSplitter2.CreateView(0,1,RUNTIME_CLASS(CServFileView),CSize(375,180),pContext))
  499. return FALSE;
  500. return TRUE; }
  501. }
  502. void CLocFileView::OnInitialUpdate() 
  503. {
  504. CFormView::OnInitialUpdate();
  505. m_pMainFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
  506. nThreadCount=0;
  507. pLocView=this;
  508. m_pFindLocFileThread=NULL;
  509.     SetFileColumns(&m_ctLocFile);
  510. SetImageList(&m_ctLocFile,&m_ctLocDir);
  511. m_ctLocFile.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
  512. GetLocDir();
  513. int i=m_ctLocDir.FindStringExact(-1,"C:\");
  514. m_ctLocDir.SetCurSel(i);
  515. ::SetCurrentDirectory("C:\");
  516. CMyAppThread* pThread=new CMyAppThread("C:\");
  517. if(!BeginFindLocFile(pThread))
  518. AfxMessageBox("起动查找线程失败");
  519. }
  520. int CLocFileView::InsertLocDir(CString& str,int iIcon,int iIconSel)
  521. {
  522. return OnInsertDir(&m_ctLocDir,str,iIcon,iIconSel);
  523. }
  524. void CServFileView::OnInitialUpdate() 
  525. {
  526. CFormView::OnInitialUpdate();
  527. m_ctServFile.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
  528. m_pMainFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
  529. pServView=this;
  530. hBitmap=::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BACKBITMAP));
  531. m_ctBack.SetBitmap(hBitmap);
  532. SetFileColumns(&m_ctServFile);
  533. SetServImageList(IDB_FILE_BITMAP);
  534. }
  535. LRESULT CServFileView::OnInsertServFile(WPARAM wParam,LPARAM lParam)
  536. {
  537. FILE_FTP_INFO* pInfo=(FILE_FTP_INFO*)wParam;
  538. CString str=pInfo->szFileName;
  539. if(str=="."||str=="..")
  540. {
  541. m_bHaveDotFlag=TRUE;
  542. return 0L;
  543. }
  544. OnInsertFile(&m_ctServFile,(LPVOID)pInfo,lParam);
  545.     return 0L;
  546. }
  547. LRESULT CServFileView::OnSetServRedrawFlag(WPARAM wParam,LPARAM lParam)
  548. {
  549. CMyAppThread* pThread=(CMyAppThread*)lParam;
  550. if(m_bHaveDotFlag)
  551. {
  552. CString str="..";
  553. int iIcon=DIRECTORYICON;
  554. m_ctServFile.InsertItem(0,str,iIcon);
  555. m_ctServFile.SetItemData(0,DIRECTORYICON);
  556. m_bHaveDotFlag=FALSE;
  557. }
  558. m_ctServFile.Invalidate();
  559. m_ctServFile.SetRedraw();
  560. return 0L;
  561. }
  562. LRESULT CServFileView::OnSetServDirectoryDisplay(WPARAM wParam,LPARAM lParam)
  563. {
  564. CString str=(LPCTSTR)lParam;
  565. int nItem=m_ctServDir.FindStringExact(-1,str);
  566. if(nItem==CB_ERR)
  567. nItem=OnInsertDir(&m_ctServDir,str,DIRECTORYICON,DIRECTORYSEL);
  568. m_ctServDir.SetCurSel(nItem);
  569. return 0L;
  570. }
  571. LRESULT CServFileView::OnReDisplayServFile(WPARAM wParam,LPARAM lParam)
  572. {
  573. CString strFtp=(LPCTSTR)lParam;
  574. OnSetServDirectoryDisplay(0,lParam);
  575. CMyAppThread* pThread=new CMyAppThread(NULL,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
  576. m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE);
  577. if(!BeginFindServFile(pThread))
  578. AfxMessageBox("建立网络线程失败");
  579. return 0L;
  580. }
  581. LRESULT CServFileView::OnSetServDir(WPARAM wParam,LPARAM lParam)
  582. {
  583.     CString str=(LPCTSTR)lParam;
  584. int nItem=m_ctServDir.FindStringExact(-1,str);
  585. if(nItem==CB_ERR)
  586. nItem=OnInsertDir(&m_ctServDir,str,DIRECTORYICON,DIRECTORYSEL);
  587. m_ctServDir.SetCurSel(nItem);
  588. m_ctServFile.SetRedraw(FALSE);
  589. m_ctServFile.DeleteAllItems();
  590. m_ctServFile.SetRedraw();
  591. return 0L;
  592. }
  593. void CServFileView::OnServFileDelete()
  594. {
  595. if(!m_bConnected)return;
  596. CString strFtp;
  597. int i=0;
  598. POSITION iPos;
  599. int nItem=m_ctServDir.GetCurSel();
  600. m_ctServDir.GetLBText(nItem,strFtp);
  601. i=m_ctServFile.GetSelectedCount();
  602. FILE_COUNT_INFO* pFileCount=new FILE_COUNT_INFO[i];
  603. SEND_RECEIVE_INFO* pSeRe=new SEND_RECEIVE_INFO;
  604. iPos=m_ctServFile.GetFirstSelectedItemPosition();
  605. for(int j=0;j<i;j++)
  606. {
  607. int nItem=m_ctServFile.GetNextSelectedItem(iPos);
  608. m_ctServFile.GetItemText(nItem,0,pFileCount[j].fileName,256);
  609. pFileCount[j].ufileFlag=m_ctServFile.GetItemData(nItem);
  610. }
  611. CMyAppThread* pThread=new CMyAppThread(NULL,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
  612. m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE,i);
  613. pSeRe->pCount=pFileCount;
  614. pSeRe->pThread=pThread;
  615. if(!BeginDeleteFile(pSeRe))
  616. AfxMessageBox("建立文件删除线程出错");
  617. }
  618. void CServFileView::OnServFileDownload()
  619. {
  620. if(!m_bConnected)return;
  621. CString str,strFtp;
  622. int i=0;
  623. POSITION iPos;
  624. int nItem=pLocView->m_ctLocDir.GetCurSel();
  625. pLocView->m_ctLocDir.GetLBText(nItem,str);
  626. nItem=m_ctServDir.GetCurSel();
  627. m_ctServDir.GetLBText(nItem,strFtp);
  628. i=m_ctServFile.GetSelectedCount();
  629. FILE_COUNT_INFO* pFileCount=new FILE_COUNT_INFO[i];
  630. SEND_RECEIVE_INFO* pSeRe=new SEND_RECEIVE_INFO;
  631. iPos=m_ctServFile.GetFirstSelectedItemPosition();
  632. for(int j=0;j<i;j++)
  633. {
  634. int nItem=m_ctServFile.GetNextSelectedItem(iPos);
  635. m_ctServFile.GetItemText(nItem,0,pFileCount[j].fileName,256);
  636. pFileCount[j].ufileFlag=m_ctServFile.GetItemData(nItem);
  637. }
  638. CMyAppThread* pThread=new CMyAppThread(str,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
  639. m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE,i);
  640. pSeRe->pCount=pFileCount;
  641. pSeRe->pThread=pThread;
  642. if(!BeginReceiveFile(pSeRe))
  643. AfxMessageBox("建立文件接收线程出错");
  644. }
  645. void CServFileView::OnServFileReName()
  646. {
  647. OnFileName(&m_ctServFile);
  648. }
  649. BOOL CServFileView::BeginDeleteFile(LPVOID pInfo)
  650. {
  651. SEND_RECEIVE_INFO* pInf=(SEND_RECEIVE_INFO*)pInfo;
  652. CMyAppThread* pThread=(CMyAppThread*)pInf->pThread;
  653. if(m_pDeleteFileThread)
  654. {
  655. ::WaitForSingleObject(m_pDeleteFileThread->m_hThread,INFINITE);
  656. delete m_pDeleteFileThread;
  657. m_pDeleteFileThread=NULL;
  658. }
  659. if(m_pDeleteFileThread=AfxBeginThread(pThread->StartDeleteFileThread,pInfo,THREAD_PRIORITY_ABOVE_NORMAL,
  660. 0,CREATE_SUSPENDED,NULL))
  661. {
  662. m_pDeleteFileThread->m_bAutoDelete=FALSE;
  663. nThreadCount++;
  664. m_pDeleteFileThread->ResumeThread();
  665. return TRUE;
  666. }
  667. return FALSE;
  668. }
  669. BOOL CServFileView::BeginRenameFile(LPVOID pInfo)
  670. {
  671. FILE_CHANGE_INFO* pInf=(FILE_CHANGE_INFO*)pInfo;
  672. CMyAppThread* pThread=(CMyAppThread*)pInf->pThread;
  673. if(m_pRenameFileThread)
  674. {
  675. ::WaitForSingleObject(m_pRenameFileThread->m_hThread,100);
  676. delete m_pRenameFileThread;
  677. m_pRenameFileThread=NULL;
  678. }
  679. if(m_pRenameFileThread=AfxBeginThread(pThread->StartRenameFileThread,pInfo,THREAD_PRIORITY_ABOVE_NORMAL,
  680. 0,CREATE_SUSPENDED,NULL))
  681. {
  682. m_pRenameFileThread->m_bAutoDelete=FALSE;
  683. m_pRenameFileThread->ResumeThread();
  684. return TRUE;
  685. }
  686. return FALSE;
  687. }
  688. BOOL CServFileView::BeginFindServFile(LPVOID lParam)
  689. {
  690. CMyAppThread* pThread=(CMyAppThread*)lParam;
  691. if(m_pFindServFileThread)
  692. {
  693. ::WaitForSingleObject(m_pFindServFileThread->m_hThread,INFINITE);
  694. delete m_pFindServFileThread;
  695. m_pFindServFileThread=NULL;
  696. }
  697. if(m_pFindServFileThread=AfxBeginThread(pThread->StartFindServFileThread,lParam,THREAD_PRIORITY_BELOW_NORMAL,
  698. 0,CREATE_SUSPENDED,NULL))
  699. {
  700. m_pFindServFileThread->m_bAutoDelete=FALSE;
  701. m_ctServFile.SetRedraw(FALSE);
  702. m_ctServFile.DeleteAllItems();
  703. m_pFindServFileThread->ResumeThread();
  704. return TRUE;
  705. }
  706. return FALSE;
  707. }
  708. void CLocFileView::GetLocDir()
  709. {
  710. int iIcon,iIconSel;
  711. char lpBuffer[MAX_PATH];
  712. char* ptr;
  713. CString str;
  714. m_iDirCount=0;
  715. ::GetLogicalDriveStrings(MAX_PATH,lpBuffer);
  716. ptr=lpBuffer;
  717. while(*ptr)
  718. {
  719. m_iDirCount++;
  720. str=ptr;
  721. GetFileIcon(str,&iIcon,&iIconSel);
  722. InsertLocDir(str,iIcon,iIconSel);
  723. ptr+=strlen(ptr)+1;
  724. }
  725. }
  726. BOOL CLocFileView::BeginFindLocFile(LPVOID pInfo)
  727. {
  728. CMyAppThread* pThread=(CMyAppThread*)pInfo;
  729. if(m_pFindLocFileThread)
  730. {
  731. ::WaitForSingleObject(m_pFindLocFileThread->m_hThread,100);
  732. delete m_pFindLocFileThread;
  733. m_pFindLocFileThread=NULL;
  734. }
  735. if(m_pFindLocFileThread=AfxBeginThread(pThread->StartFindLocFileThread,pInfo,THREAD_PRIORITY_ABOVE_NORMAL,
  736. 0,CREATE_SUSPENDED,NULL))
  737. {
  738. m_pFindLocFileThread->m_bAutoDelete=FALSE;
  739. m_ctLocFile.SetRedraw(FALSE);
  740. m_ctLocFile.DeleteAllItems();
  741. m_pFindLocFileThread->ResumeThread();
  742. return TRUE;
  743. }
  744. return FALSE;
  745. }
  746. BOOL CLocFileView::BeginSendFile(LPVOID pInfo)
  747. {
  748. SEND_RECEIVE_INFO* pInf=(SEND_RECEIVE_INFO*)pInfo;
  749. CMyAppThread* pThread=(CMyAppThread*)pInf->pThread;
  750. if(m_pSendFileThread)
  751. {
  752. ::WaitForSingleObject(m_pSendFileThread->m_hThread,10);
  753. delete m_pSendFileThread;
  754. m_pSendFileThread=NULL;
  755. }
  756. if(m_pSendFileThread=AfxBeginThread(pThread->StartSendFileThread,pInfo,THREAD_PRIORITY_ABOVE_NORMAL,
  757. 0,CREATE_SUSPENDED,NULL))
  758. {
  759. m_pSendFileThread->m_bAutoDelete=FALSE;
  760. nThreadCount++;
  761. m_pSendFileThread->ResumeThread();
  762. return TRUE;
  763. }
  764. else
  765. return FALSE;
  766. }
  767. BOOL CLocFileView::BeginPreSendFile(LPVOID pInfo)
  768. {
  769. CMyAppThread* pThread=(CMyAppThread*)pInfo;
  770. CWinThread* pPreSendFile=NULL;
  771. if(pPreSendFile=AfxBeginThread(pThread->StartPreSendFileThread,pInfo,THREAD_PRIORITY_NORMAL,
  772. 0,CREATE_SUSPENDED,NULL))
  773. {
  774. nThreadCount++;
  775. pPreSendFile->ResumeThread();
  776. return TRUE;
  777. }
  778. return FALSE;
  779. }
  780. LRESULT CLocFileView::OnSetLocDirectoryDisplay(WPARAM wParam,LPARAM lParam)
  781. {
  782. int iIcon,iIconSel,nItem;
  783. CString str=(LPCTSTR)lParam;
  784. if(str.Right(1)=="\")
  785. m_ctLocDir.DeleteItem(m_iDirCount);
  786. nItem=m_ctLocDir.FindStringExact(-1,str);
  787. if(nItem==CB_ERR)
  788. {
  789. GetFileIcon(str,&iIcon,&iIconSel);
  790. int iCount=m_ctLocDir.GetCount();
  791. if(iCount==m_iDirCount)
  792. nItem=InsertLocDir(str,iIcon,iIconSel);
  793. else
  794. {
  795. m_ctLocDir.DeleteItem(m_iDirCount);
  796. nItem=InsertLocDir(str,iIcon,iIconSel);
  797. }
  798. }
  799. m_ctLocDir.SetCurSel(nItem);
  800. return 0L;
  801. }
  802. LRESULT CLocFileView::OnPreSendFile(WPARAM wParam,LPARAM lParam)
  803. {
  804. CString str=(LPCTSTR)wParam;
  805. CString strFtp=(LPCTSTR)lParam;
  806. CMyAppThread* pThread=new CMyAppThread(str,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
  807. m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE);
  808. if(!BeginPreSendFile(pThread))
  809. AfxMessageBox("起动发送子线程失败");
  810. return 0L;
  811. }
  812. LRESULT CLocFileView::OnSetLocRedrawFlag(WPARAM wParam,LPARAM lParam)
  813. {
  814. if(m_bHaveDotFlag)
  815. {
  816. CString str="..";
  817. int iIcon=DIRECTORYICON;
  818. m_ctLocFile.InsertItem(0,str,iIcon);
  819. m_ctLocFile.SetItemData(0,DIRECTORYICON);
  820. m_bHaveDotFlag=FALSE;
  821. }
  822. m_ctLocFile.Invalidate();
  823. m_ctLocFile.SetRedraw();
  824. return 0L;
  825. }
  826. LRESULT CLocFileView::OnReDisplayLocFile(WPARAM wParam,LPARAM lParam)
  827. {
  828. CString str=(LPCTSTR)lParam;
  829. OnSetLocDirectoryDisplay(0,lParam);
  830. CMyAppThread* pThread=new CMyAppThread(str);
  831. if(!BeginFindLocFile(pThread))
  832. AfxMessageBox("建立网络线程失败");
  833. return 0L;
  834. }
  835. LRESULT CLocFileView::OnInsertLocFile(WPARAM wParam,LPARAM lParam)
  836. {
  837. FILE_FTP_INFO* pInfo=(FILE_FTP_INFO*)wParam;
  838. CString str=pInfo->szFileName;
  839. if(str=="."||str=="..")
  840. {
  841. m_bHaveDotFlag=TRUE;
  842. return 0L;
  843. }
  844. OnInsertFile(&m_ctLocFile,pInfo,lParam);
  845. return 0L;
  846. }
  847. /////////////////////////////////////////////////////////////////////////////
  848. // CMyAppThread
  849. IMPLEMENT_DYNCREATE(CMyAppThread, CWinThread)
  850. CMyAppThread::CMyAppThread()
  851. {
  852. }
  853. CMyAppThread::~CMyAppThread()
  854. {
  855. if(hFtpConn)
  856. InternetCloseHandle(hFtpConn);
  857. }
  858. BOOL CMyAppThread::InitInstance()
  859. {
  860. // TODO:  perform and per-thread initialization here
  861. return TRUE;
  862. }
  863. int CMyAppThread::ExitInstance()
  864. {
  865. // TODO:  perform any per-thread cleanup here
  866. return CWinThread::ExitInstance();
  867. }
  868. BEGIN_MESSAGE_MAP(CMyAppThread, CWinThread)
  869. //{{AFX_MSG_MAP(CMyAppThread)
  870. // NOTE - the ClassWizard will add and remove mapping macros here.
  871. //}}AFX_MSG_MAP
  872. END_MESSAGE_MAP()
  873. /////////////////////////////////////////////////////////////////////////////
  874. // CMyAppThread message handlers
  875. UINT CMyAppThread::StartRenameFileThread(LPVOID lParam)
  876. {
  877. CFtpParaClass::FILE_CHANGE_INFO* pInfo=(CFtpParaClass::FILE_CHANGE_INFO*)lParam;
  878. CMyAppThread* pThis=(CMyAppThread*)pInfo->pThread;
  879. return pThis->RenameFileThread(lParam);
  880. }
  881. UINT CMyAppThread::StartDeleteFileThread(LPVOID lParam)
  882. {
  883. CFtpParaClass::SEND_RECEIVE_INFO* pInfo=(CFtpParaClass::SEND_RECEIVE_INFO*)lParam;
  884. CMyAppThread* pThis=(CMyAppThread*)pInfo->pThread;
  885. return pThis->DeleteFileThread(lParam);
  886. }
  887. UINT CMyAppThread::StartReceiveFileThread(LPVOID lParam)
  888. {
  889. CFtpParaClass::SEND_RECEIVE_INFO* pInfo=(CFtpParaClass::SEND_RECEIVE_INFO*)lParam;
  890. CMyAppThread* pThis=(CMyAppThread*)pInfo->pThread;
  891. return pThis->ReceiveFileThread(lParam);
  892. }
  893. UINT CMyAppThread::StartSendFileThread(LPVOID lParam)
  894. {
  895. CFtpParaClass::SEND_RECEIVE_INFO* pInfo=(CFtpParaClass::SEND_RECEIVE_INFO*)lParam;
  896. CMyAppThread* pThis=(CMyAppThread*)pInfo->pThread;
  897. return pThis->SendFileThread(lParam);
  898. }
  899. UINT CMyAppThread::StartPreSendFileThread(LPVOID lParam)
  900. {
  901. CMyAppThread* pThis=(CMyAppThread*)lParam;
  902. return pThis->PreSendFileThread(lParam);
  903. }
  904. UINT CMyAppThread::StartPreReceiveFileThread(LPVOID lParam)
  905. {
  906. CMyAppThread* pThis=(CMyAppThread*)lParam;
  907. return pThis->PreRecieveFileThread(lParam);
  908. }
  909. UINT CMyAppThread::StartPreDeleteFileThread(LPVOID lParam)
  910. {
  911. CMyAppThread* pThis=(CMyAppThread*)lParam;
  912. return pThis->PreDeleteFileThread(lParam);
  913. }
  914. UINT CMyAppThread::StartFindLocFileThread(LPVOID lParam)
  915. {
  916. CMyAppThread* pThis=(CMyAppThread*)lParam;
  917. return pThis->FindLocFileThread(lParam);
  918. }
  919. UINT CMyAppThread::StartFindServFileThread(LPVOID lParam)
  920. {
  921. CMyAppThread* pThis=(CMyAppThread*)lParam;
  922. return pThis->FindServFileThread(lParam);
  923. }
  924. UINT CMyAppThread::FindLocFileThread(LPVOID lParam)
  925. {
  926. CMyAppThread* pThread=(CMyAppThread*)lParam;
  927. CFtpParaClass::FILE_FTP_INFO* pInfo=new (CFtpParaClass::FILE_FTP_INFO);
  928. CFileFind fileFind;
  929. CString str;
  930. UINT i=0;
  931. CTime time;
  932. BOOL bContinue;
  933. ::SetCurrentDirectory(m_szLocDirectory);
  934. ::GetCurrentDirectory(MAX_PATH,(LPTSTR)(LPCTSTR)m_szLocDirectory);
  935. strcpy(pInfo->szFilePath,m_szLocDirectory);
  936. ::PostMessage(pLocView->m_hWnd,WM_SETDIRECTORYDISPLAY,0,(LPARAM)(LPCSTR)m_szLocDirectory);
  937. bContinue=fileFind.FindFile("*.*");
  938. if(!bContinue)
  939. goto end;
  940. while(bContinue)
  941. {
  942. bContinue=fileFind.FindNextFile();
  943. if(fileFind.IsHidden())continue;
  944. str=fileFind.GetFileName();
  945. strcpy(pInfo->szFileName,str);
  946. fileFind.GetLastWriteTime(time);
  947. str=time.Format("%x");
  948. strcpy(pInfo->szFileDate,str);
  949. if(fileFind.IsDirectory())
  950. {
  951. strcpy(pInfo->szFileSize,"<DIR>");
  952. pInfo->nType=DIRECTORYICON;
  953. }
  954. else
  955. {
  956. int i=fileFind.GetLength();
  957. if(i>1024)
  958. {
  959. str.Format("%d",i/1024);
  960. str+="KB";
  961. }
  962. else
  963. str.Format("%d",i);
  964. strcpy(pInfo->szFileSize,str);
  965. pInfo->nType=FILEICON;
  966. }
  967. ::SendMessage(pLocView->m_hWnd,WM_SETFILE,(WPARAM)pInfo,(LPARAM)LOCFILE);
  968. }
  969. end:
  970. ::PostMessage(pLocView->m_hWnd,WM_SETREDRAWFLAG,0,0);
  971. fileFind.Close();
  972. delete pInfo;
  973. delete pThread;
  974. return 0L;
  975. }
  976. UINT CMyAppThread::FindServFileThread(LPVOID lParam)
  977. {
  978. CString str,szFile,szFtpInfo;
  979. if(!hFtpConn)
  980. {
  981. szFtpInfo=m_szFtpName+"服务器未接上";
  982. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  983. return 0L;
  984. }
  985. CMyAppThread* pThread=(CMyAppThread*)lParam;
  986. CFtpParaClass::FILE_FTP_INFO* pInfo=new(CFtpParaClass::FILE_FTP_INFO);
  987. FILETIME fileTime;
  988. WIN32_FIND_DATA findData;
  989. HINTERNET hFind;
  990. szFtpInfo="正在连接"+m_szFtpName+"服务器";
  991. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  992. szFtpInfo=m_szFtpName+"服务器已连上,用户"+m_szFtpUser+"登录成功";
  993. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  994. DWORD dwLength=MAX_PATH;
  995. if(m_szFtpDirectory!=" ")
  996. FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
  997. FtpGetCurrentDirectory(hFtpConn,(LPTSTR)(LPCTSTR)m_szFtpDirectory,&dwLength);
  998. ::SendMessage(pServView->m_hWnd,WM_SETDIRECTORYDISPLAY,0,(LPARAM)(LPCTSTR)m_szFtpDirectory);
  999. szFtpInfo="正在查找文件";
  1000. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1001. if(!(hFind=FtpFindFirstFile(hFtpConn,_T("*"),&findData,0,0)))
  1002. {
  1003. if (GetLastError()  == ERROR_NO_MORE_FILES) 
  1004. {
  1005. AfxMessageBox("目录为空,没有多余的内容");
  1006. goto end;
  1007. }
  1008. else
  1009. {
  1010. szFtpInfo="文件查找出错,退回,请查明原因";
  1011. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1012. goto end;
  1013. }
  1014. }
  1015. do{
  1016. szFile=findData.cFileName;
  1017. strcpy(pInfo->szFileName,szFile);
  1018. fileTime=findData.ftLastWriteTime;
  1019. CTime time=CTime(fileTime);
  1020. CString str=time.Format("%x");
  1021. strcpy(pInfo->szFileDate,str);
  1022. if(findData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
  1023. {
  1024. strcpy(pInfo->szFileSize,"<DIR>");
  1025. pInfo->nType=DIRECTORYICON;
  1026. }
  1027. else
  1028. {
  1029. DWORD i=findData.nFileSizeLow;
  1030. if(i>1024)
  1031. {
  1032. str.Format("%ld",i/1024);
  1033. str+="KB";
  1034. }
  1035. else
  1036. str.Format("%ld",i);
  1037. strcpy(pInfo->szFileSize,str);
  1038. pInfo->nType=FILEICON;
  1039. }
  1040. ::SendMessage(pServView->m_hWnd,WM_SETFILE,(WPARAM)pInfo,(LPARAM)SERVFILE);
  1041. }while(InternetFindNextFile(hFind,&findData));
  1042. ::SendMessage(pServView->m_hWnd,WM_SETREDRAWFLAG,0,(LPARAM)lParam);
  1043. InternetCloseHandle(hFind);
  1044. end:
  1045. szFtpInfo="查找文件结束";
  1046. ::Sleep(0);
  1047. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1048. delete pInfo;
  1049. delete pThread;
  1050. return 0L;
  1051. }
  1052. UINT CMyAppThread::SendFileThread(LPVOID lParam)
  1053. {
  1054. IsFree=TRUE;
  1055. int i=0;
  1056. CFtpParaClass:: FILE_FTP_INFO* pInf=new (CFtpParaClass::FILE_FTP_INFO);
  1057. CFtpParaClass::SEND_RECEIVE_INFO* pInf1=(CFtpParaClass::SEND_RECEIVE_INFO*)lParam;
  1058. CMyAppThread* pThread=(CMyAppThread*)pInf1->pThread;
  1059. CFtpParaClass::FILE_COUNT_INFO* pInfo=pInf1->pCount;
  1060.     CString str,strFtp,szFtpInfo,DirName;
  1061. if(!hFtpConn)
  1062. goto end;
  1063. FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
  1064. ::SetCurrentDirectory(m_szLocDirectory);
  1065. for(;i<m_nCount;i++)
  1066. {
  1067. str=m_szLocDirectory;
  1068. strFtp=m_szFtpDirectory;
  1069. DirName=pInfo[i].fileName;
  1070. if(DirName=="..")continue;
  1071. if(m_szLocDirectory.Right(1)=="\")
  1072. str+=DirName;
  1073. else
  1074. str+="\"+DirName;
  1075. if(m_szFtpDirectory.Right(1)=='/')
  1076. strFtp+=DirName;
  1077. else
  1078. strFtp+="/"+DirName;
  1079. if(pInfo[i].ufileFlag==FILEICON)
  1080. {
  1081. szFtpInfo="发送";
  1082. szFtpInfo+=DirName;
  1083. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1084. if(FtpPutFile(hFtpConn,str,strFtp,INTERNET_FLAG_NO_CACHE_WRITE,0))
  1085. {
  1086. if(IsFree)
  1087. {
  1088. IsFree=FALSE;
  1089. strcpy(pInf->szFileName,DirName);
  1090. strcpy(pInf->szFileDate,"");
  1091. strcpy(pInf->szFileSize,"");
  1092. pInf->nType=FILEICON;
  1093. ::PostMessage(pServView->m_hWnd,WM_SETFILE,(WPARAM)pInf,SERVFILE);
  1094. }
  1095. continue;
  1096. }
  1097. else
  1098. {
  1099. szFtpInfo="发送"+DirName+"出错";
  1100. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1101. break;
  1102. }
  1103. }
  1104. else
  1105. pLocView->SendMessage(WM_PRESENDFILE,(WPARAM)(LPCTSTR)str,(LPARAM)(LPCTSTR)strFtp);
  1106. }
  1107. end:
  1108. nThreadCount--;
  1109. ::Sleep(10);
  1110. while(1)
  1111. {
  1112. if(nThreadCount==0)
  1113. {
  1114. szFtpInfo="文件发送结束,退回";
  1115. szFtpInfo+=m_szLocDirectory;
  1116. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1117. ::SendMessage(pServView->m_hWnd,WM_REDISPLAYFILE,0,(LPARAM)(LPCTSTR)m_szFtpDirectory);
  1118. break;
  1119. }
  1120. ::Sleep(100);
  1121. }
  1122. delete[] pInfo;
  1123. delete pInf;
  1124. delete pThread;
  1125. delete pInf1;
  1126. return 0L;
  1127. }
  1128. UINT CMyAppThread::PreSendFileThread(LPVOID lParam)
  1129. {
  1130. CMyAppThread* pThread=(CMyAppThread*)lParam;
  1131. CFtpParaClass:: FILE_FTP_INFO* pInfo=new CFtpParaClass::FILE_FTP_INFO;
  1132. CFileFind fileFind;
  1133. CString szFtpInfo,str,strFtp;
  1134. szFtpInfo="创建"+m_szFtpDirectory+"目录";
  1135. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1136. FtpCreateDirectory(hFtpConn,m_szFtpDirectory);
  1137. FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
  1138. ::SetCurrentDirectory(m_szLocDirectory);
  1139. szFtpInfo="进入"+m_szFtpDirectory+"目录";
  1140. pServView->SendMessage(WM_SETDIR,0,(LPARAM)(LPCTSTR)m_szFtpDirectory);
  1141. if(IsFree)
  1142. pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1143. UINT bContinue=fileFind.FindFile("*");
  1144. CString tFile;
  1145. if(bContinue)
  1146. {
  1147. do
  1148. {
  1149. str=m_szLocDirectory;
  1150. strFtp=m_szFtpDirectory;
  1151. bContinue=fileFind.FindNextFile();
  1152. tFile=fileFind.GetFileName();
  1153. if(tFile=="."||tFile==".."||fileFind.IsHidden())continue;
  1154. if(m_szLocDirectory.Right(1)=='\')
  1155. str+=tFile;
  1156. else
  1157. str+="\"+tFile;
  1158. if(m_szFtpDirectory.Right(1)=='/')
  1159. strFtp+=tFile;
  1160. else
  1161. strFtp+="/"+tFile;
  1162. if(fileFind.IsDirectory())
  1163. pLocView->SendMessage(WM_PRESENDFILE,(WPARAM)(LPCTSTR)str,(LPARAM)(LPCTSTR)strFtp);
  1164. else
  1165. {
  1166. szFtpInfo="发送"+tFile;
  1167. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1168. FtpPutFile(hFtpConn,str,strFtp,INTERNET_FLAG_NO_CACHE_WRITE,0)?TRUE:FALSE;
  1169. if(IsFree)
  1170. {
  1171. IsFree=FALSE;
  1172. strcpy(pInfo->szFileName,tFile);
  1173. strcpy(pInfo->szFileDate,"");
  1174. strcpy(pInfo->szFileSize,"");
  1175. pInfo->nType=FILEICON;
  1176. ::PostMessage(pServView->m_hWnd,WM_SETFILE,(WPARAM)pInfo,SERVFILE);
  1177. }
  1178. }
  1179. }while(bContinue);
  1180. fileFind.Close();
  1181. }
  1182. delete pInfo;
  1183. delete pThread;
  1184. nThreadCount--;
  1185. return 0L;
  1186. }
  1187. UINT CMyAppThread::ReceiveFileThread(LPVOID lParam)
  1188. {
  1189. IsFree=TRUE;
  1190. int i=0;
  1191. CFtpParaClass:: FILE_FTP_INFO* pInf=new (CFtpParaClass::FILE_FTP_INFO);
  1192. CFtpParaClass::SEND_RECEIVE_INFO* pInf1=(CFtpParaClass::SEND_RECEIVE_INFO*)lParam;
  1193. CMyAppThread* pThread=(CMyAppThread*)pInf1->pThread;
  1194. CFtpParaClass::FILE_COUNT_INFO* pInfo=pInf1->pCount;
  1195.     CString str,strFtp,szFtpInfo,DirName;
  1196. if(!hFtpConn)
  1197. goto end;
  1198. FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
  1199. ::SetCurrentDirectory(m_szLocDirectory);
  1200. for(;i<m_nCount;i++)
  1201. {
  1202. str=m_szLocDirectory;
  1203. strFtp=m_szFtpDirectory;
  1204. DirName=pInfo[i].fileName;
  1205. if(DirName=="..")continue;
  1206. if(m_szLocDirectory.Right(1)=="\")
  1207. str+=DirName;
  1208. else
  1209. str+="\"+DirName;
  1210. if(m_szFtpDirectory.Right(1)=='/')
  1211. strFtp+=DirName;
  1212. else
  1213. strFtp+="/"+DirName;
  1214. if(pInfo[i].ufileFlag==FILEICON)
  1215. {
  1216. szFtpInfo="接收"+DirName;
  1217. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1218. if(FtpGetFile(hFtpConn,strFtp,str,FALSE,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_BINARY |
  1219. INTERNET_FLAG_NO_CACHE_WRITE,0))
  1220. {
  1221. if(IsFree)
  1222. {
  1223. IsFree=FALSE;
  1224. strcpy(pInf->szFileName,DirName);
  1225. strcpy(pInf->szFileDate,"");
  1226. strcpy(pInf->szFileSize,"");
  1227. pInf->nType=FILEICON;
  1228. ::PostMessage(pLocView->m_hWnd,WM_SETFILE,(WPARAM)pInf,SERVFILE);
  1229. }
  1230. continue;
  1231. }
  1232. else
  1233. {
  1234. szFtpInfo="接收"+DirName+"出错";
  1235. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1236. break;
  1237. }
  1238. }
  1239. else
  1240. pServView->SendMessage(WM_PRERECEIVEFILE,(WPARAM)(LPCTSTR)str,(LPARAM)(LPCTSTR)strFtp);
  1241. }
  1242. end:
  1243. nThreadCount--;
  1244. ::Sleep(10);
  1245. while(1)
  1246. {
  1247. if(nThreadCount==0)
  1248. {
  1249. szFtpInfo="文件接收结束,退回"+m_szLocDirectory;
  1250. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1251. ::SendMessage(pLocView->m_hWnd,WM_REDISPLAYFILE,0,(LPARAM)(LPCTSTR)m_szLocDirectory);
  1252. break;
  1253. }
  1254. ::Sleep(100);
  1255. }
  1256. delete[] pInfo;
  1257. delete pInf;
  1258. delete pThread;
  1259. delete pInf1;
  1260. return 0L;
  1261. }
  1262. UINT CMyAppThread::PreRecieveFileThread(LPVOID lParam)
  1263. {
  1264. CMyAppThread* pThread=(CMyAppThread*)lParam;
  1265. CFtpParaClass:: FILE_FTP_INFO* pInfo=new CFtpParaClass::FILE_FTP_INFO;
  1266. WIN32_FIND_DATA  fileData;
  1267. HINTERNET hFind;
  1268. CString szFtpInfo,str,strFtp;
  1269. szFtpInfo="创建"+m_szLocDirectory+"目录";
  1270. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1271. CreateDirectory(m_szLocDirectory,NULL);
  1272. ::SetCurrentDirectory(m_szLocDirectory);
  1273. if(IsFree)
  1274. pLocView->SendMessage(WM_SETDIR,0,(LPARAM)(LPCTSTR)m_szLocDirectory);
  1275. FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
  1276. szFtpInfo="进入"+m_szFtpDirectory+"目录成功";
  1277. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1278. CString tFile;
  1279. if(!(hFind=FtpFindFirstFile(hFtpConn,_T("*"),&fileData,0,0)))
  1280. goto end;
  1281. do
  1282. {
  1283. tFile=fileData.cFileName;
  1284. if(tFile=="."||tFile==".."||fileData.dwFileAttributes==FILE_ATTRIBUTE_HIDDEN)continue;
  1285. str=m_szLocDirectory;
  1286. strFtp=m_szFtpDirectory;
  1287. if(m_szLocDirectory.Right(1)=='\')
  1288. str+=tFile;
  1289. else
  1290. str+="\"+tFile;
  1291. if(m_szFtpDirectory.Right(1)=='/')
  1292. strFtp+=tFile;
  1293. else
  1294. strFtp+="/"+tFile;
  1295. if(fileData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
  1296. pServView->SendMessage(WM_PRERECEIVEFILE,(WPARAM)(LPCTSTR)str,(LPARAM)(LPCTSTR)strFtp);
  1297. else
  1298. {
  1299. szFtpInfo="正在接收"+tFile;
  1300. pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1301. if(!FtpGetFile(hFtpConn,strFtp,str,FALSE,FILE_ATTRIBUTE_NORMAL,FTP_TRANSFER_TYPE_BINARY |
  1302. INTERNET_FLAG_NO_CACHE_WRITE,0))
  1303. {
  1304. szFtpInfo="接收"+strFtp+"出错";
  1305. pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1306. break;
  1307. }
  1308. if(IsFree)
  1309. {
  1310. IsFree=FALSE;
  1311. strcpy(pInfo->szFileName,tFile);
  1312. strcpy(pInfo->szFileDate,"");
  1313. strcpy(pInfo->szFileSize,"");
  1314. pInfo->nType=FILEICON;
  1315. ::PostMessage(pLocView->m_hWnd,WM_SETFILE,(WPARAM)pInfo,SERVFILE);
  1316. }
  1317. }
  1318. }while(InternetFindNextFile(hFind,&fileData));
  1319. InternetCloseHandle(hFind);
  1320. end:
  1321. delete pInfo;
  1322. delete pThread;
  1323. nThreadCount--;
  1324. return 0L;
  1325. }
  1326. UINT CMyAppThread::PreDeleteFileThread(LPVOID lParam)
  1327. {
  1328. CMyAppThread* pThread=(CMyAppThread*)lParam;
  1329. CFtpParaClass:: FILE_FTP_INFO* pInfo=new CFtpParaClass::FILE_FTP_INFO;
  1330. WIN32_FIND_DATA  fileData;
  1331. HINTERNET hFind;
  1332. CString szFtpInfo,strFtp;
  1333. FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
  1334. szFtpInfo="进入"+m_szFtpDirectory+"目录成功";
  1335. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1336. CString tFile;
  1337. if(!(hFind=FtpFindFirstFile(hFtpConn,_T("*"),&fileData,0,0)))
  1338. goto end;
  1339. do
  1340. {
  1341. tFile=fileData.cFileName;
  1342. if(tFile=="."||tFile==".."||fileData.dwFileAttributes==FILE_ATTRIBUTE_HIDDEN)continue;
  1343. strFtp=m_szFtpDirectory;
  1344. if(m_szFtpDirectory.Right(1)=='/')
  1345. strFtp+=tFile;
  1346. else
  1347. strFtp+="/"+tFile;
  1348. if(fileData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
  1349. pServView->SendMessage(WM_PREDELETEFILE,0,(LPARAM)(LPCTSTR)strFtp);
  1350. else
  1351. {
  1352. szFtpInfo="正在删除"+tFile;
  1353. pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1354. if(!FtpDeleteFile(hFtpConn,strFtp))
  1355. {
  1356. szFtpInfo="删除"+strFtp+"出错";
  1357. pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1358. break;
  1359. }
  1360. }
  1361. }while(InternetFindNextFile(hFind,&fileData));
  1362. InternetCloseHandle(hFind);
  1363. end:
  1364. FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory+"/"+"..");
  1365. szFtpInfo="正在删除"+m_szFtpDirectory+"目录";
  1366. pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1367. while(1)
  1368. {
  1369. if(FtpRemoveDirectory(hFtpConn,m_szFtpDirectory))
  1370. //必须在此添加修改m_ctServDir的功能;
  1371. break;
  1372. ::Sleep(100);
  1373. }
  1374. delete pInfo;
  1375. delete pThread;
  1376. nThreadCount--;
  1377. return 0L;
  1378. }
  1379. UINT CMyAppThread::DeleteFileThread(LPVOID lParam)
  1380. {
  1381. IsFree=TRUE;
  1382. int i=0;
  1383. CFtpParaClass:: FILE_FTP_INFO* pInf=new (CFtpParaClass::FILE_FTP_INFO);
  1384. CFtpParaClass::SEND_RECEIVE_INFO* pInf1=(CFtpParaClass::SEND_RECEIVE_INFO*)lParam;
  1385. CMyAppThread* pThread=(CMyAppThread*)pInf1->pThread;
  1386. CFtpParaClass::FILE_COUNT_INFO* pInfo=pInf1->pCount;
  1387.     CString strFtp,szFtpInfo,DirName;
  1388. if(!hFtpConn)
  1389. goto end;
  1390. FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
  1391. ::SetCurrentDirectory(m_szLocDirectory);
  1392. for(;i<m_nCount;i++)
  1393. {
  1394. strFtp=m_szFtpDirectory;
  1395. DirName=pInfo[i].fileName;
  1396. if(DirName=="..")continue;
  1397. if(m_szFtpDirectory.Right(1)=='/')
  1398. strFtp+=DirName;
  1399. else
  1400. strFtp+="/"+DirName;
  1401. if(pInfo[i].ufileFlag==FILEICON)
  1402. {
  1403. szFtpInfo="删除"+DirName;
  1404. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1405. if(FtpDeleteFile(hFtpConn,strFtp))
  1406. {
  1407. continue;
  1408. }
  1409. else
  1410. {
  1411. szFtpInfo="删除"+DirName+"出错";
  1412. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1413. break;
  1414. }
  1415. }
  1416. else;
  1417. pServView->SendMessage(WM_PREDELETEFILE,0,(LPARAM)(LPCTSTR)strFtp);
  1418. }
  1419. end:
  1420. nThreadCount--;
  1421. ::Sleep(10);
  1422. while(1)
  1423. {
  1424. if(nThreadCount==0)
  1425. {
  1426. szFtpInfo="文件删除结束,退回"+m_szLocDirectory;
  1427. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1428. ::SendMessage(pServView->m_hWnd,WM_REDISPLAYFILE,0,(LPARAM)(LPCTSTR)m_szFtpDirectory);
  1429. break;
  1430. }
  1431. ::Sleep(100);
  1432. }
  1433. delete[] pInfo;
  1434. delete pInf;
  1435. delete pThread;
  1436. delete pInf1;
  1437. return 0L;
  1438. }
  1439. UINT CMyAppThread::RenameFileThread(LPVOID lParam)
  1440. {
  1441. CString szFtpInfo;
  1442. CFtpParaClass::FILE_CHANGE_INFO* pInfo=(CFtpParaClass::FILE_CHANGE_INFO*)lParam;
  1443. CMyAppThread* pThread=(CMyAppThread*)pInfo->pThread;
  1444. szFtpInfo="正在连接"+m_szFtpName+"服务器";
  1445. pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1446. if(!hFtpConn)
  1447. {
  1448. szFtpInfo="未连上"+m_szFtpName+"服务器,请查明原因,目前只能返回";
  1449. pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1450. ::Sleep(10);
  1451. goto end;
  1452. }
  1453. szFtpInfo=m_szFtpName+"服务器连接成功,现进行改名操作";
  1454. pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1455. FtpSetCurrentDirectory(hFtpConn,m_szFtpDirectory);
  1456. szFtpInfo="正在把";
  1457. szFtpInfo+=pInfo->OldName;
  1458. szFtpInfo+="改为";
  1459. szFtpInfo+=pInfo->NewName;
  1460. pFtpInfoView->PostMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1461.     if(FtpRenameFile(hFtpConn,pInfo->OldName,pInfo->NewName))
  1462. szFtpInfo="改名成功";
  1463. else
  1464. {
  1465. szFtpInfo="改名失败,有可能有重名文件";
  1466. pServView->PostMessage(WM_REDISPLAYFILE,0,(LPARAM)(LPCTSTR)m_szFtpDirectory);
  1467. }
  1468. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  1469. end:
  1470. ::Sleep(0);
  1471. delete pThread;
  1472. delete pInfo;
  1473. return 0L;
  1474. }
  1475. void CLocFileView::OnDblclkLocFile(NMHDR* pNMHDR, LRESULT* pResult) 
  1476. {
  1477.     NMLVDISPINFO* pLocInfo=(NMLVDISPINFO*)pNMHDR;
  1478. CString str,buf;
  1479. int iIcon,iIconSel;
  1480. str.Format("%d",pLocInfo->item);
  1481. if(str=="-1")return;
  1482. int nItem=atoi(str);
  1483. DWORD dwFlag=m_ctLocFile.GetItemData(nItem);
  1484. if(dwFlag==FILEICON)
  1485. {
  1486. OnLocFileOpen();
  1487. return;
  1488. }
  1489. buf=m_ctLocFile.GetItemText(nItem,0);
  1490. nItem=m_ctLocDir.GetCurSel();
  1491. m_ctLocDir.GetLBText(nItem,str);
  1492. if(str.Right(1)!="\")
  1493. str+="\";
  1494. str+=buf;
  1495. GetFileIcon(str,&iIcon,&iIconSel);
  1496. int i=m_ctLocDir.FindStringExact(-1,str);
  1497. if(i==CB_ERR)
  1498. {
  1499. int iCount=m_ctLocDir.GetCount();
  1500. if(iCount==m_iDirCount)
  1501. {
  1502. i=InsertLocDir(str,iIcon,iIconSel);
  1503. }
  1504. else
  1505. {
  1506. m_ctLocDir.DeleteItem(m_iDirCount);
  1507. i=InsertLocDir(str,iIcon,iIconSel);
  1508. }
  1509. }
  1510. m_ctLocDir.SetCurSel(i);
  1511. CMyAppThread* pThread=new CMyAppThread(str);
  1512. BeginFindLocFile(pThread);
  1513. *pResult = 0;
  1514. }
  1515. void CLocFileView::OnSize(UINT nType, int cx, int cy) 
  1516. {
  1517. // CFormView::OnSize(nType, cx, cy);
  1518. if(m_ctLocDir.m_hWnd)
  1519. m_ctLocDir.SetWindowPos(this,0,0,cx-3,0,SWP_NOZORDER|SWP_NOMOVE);
  1520. if(m_ctLocFile.m_hWnd)
  1521. {
  1522. m_ctLocFile.ShowWindow(SW_HIDE);
  1523. m_ctLocFile.SetWindowPos(this,0,0,cx-1,cy-22,SWP_NOZORDER|SWP_NOMOVE);
  1524. m_ctLocFile.ShowWindow(SW_SHOW);
  1525. }
  1526. }
  1527. void CServFileView::OnSize(UINT nType, int cx, int cy) 
  1528. {
  1529. // CFormView::OnSize(nType, cx, cy);
  1530.     if(m_ctServDir.m_hWnd&&m_ctBack.m_hWnd)
  1531. {
  1532. m_ctServDir.SetWindowPos(this,0,0,cx-30,0,SWP_NOZORDER|SWP_NOMOVE);
  1533. m_ctBack.SetWindowPos(this,cx-28,0,0,0,SWP_NOZORDER|SWP_NOSIZE);
  1534. }
  1535. if(m_ctServFile.m_hWnd)
  1536. {
  1537. m_ctServFile.ShowWindow(SW_HIDE);
  1538. m_ctServFile.SetWindowPos(this,0,0,cx,cy-22,SWP_NOZORDER|SWP_NOMOVE);
  1539. m_ctServFile.ShowWindow(SW_SHOW);
  1540. }
  1541. }
  1542. BOOL CServFileView::SetServImageList(UINT nBitmapID)
  1543. {
  1544. if(m_ctServImageList.Create(nBitmapID,16,1,RGB(0,255,0)))
  1545. {
  1546. m_ctServFile.SetImageList(&m_ctServImageList,LVSIL_SMALL);
  1547. m_ctServDir.SetImageList(&m_ctServImageList);
  1548. }
  1549. else
  1550. return FALSE;
  1551. return TRUE;
  1552. }
  1553. void CLocFileView::OnSelchangeLocDir() 
  1554. {
  1555. CString str;
  1556. char lpBuffer[MAX_PATH];
  1557. ::GetCurrentDirectory(MAX_PATH,lpBuffer);
  1558. int i=m_ctLocDir.GetCurSel();
  1559. m_ctLocDir.GetLBText(i,str);
  1560. if(str==lpBuffer)return;
  1561. i=0;
  1562. while(1)
  1563. {
  1564. if(!SetCurrentDirectory(str))
  1565. {
  1566. i++;
  1567. if(i<2)
  1568. {
  1569. AfxMessageBox("请插入磁盘再试");
  1570. continue;
  1571. }
  1572. str=lpBuffer;
  1573. if((i=m_ctLocDir.FindStringExact(-1,str))!=-1)
  1574. m_ctLocDir.SetCurSel(i);
  1575. }
  1576. else
  1577. {
  1578. CMyAppThread* pThread=new CMyAppThread(str);
  1579. BeginFindLocFile(pThread);
  1580. }
  1581. break;
  1582. }
  1583. }
  1584. void CServFileView::OnDblclkServFile(NMHDR* pNMHDR, LRESULT* pResult) 
  1585. {
  1586. NMLVDISPINFO* pLocInfo=(NMLVDISPINFO*)pNMHDR;
  1587. CString str,buf;
  1588. str.Format("%d",pLocInfo->item);
  1589. if(str=="-1")
  1590. return;
  1591. int nItem=atoi(str);
  1592. buf=m_ctServFile.GetItemText(nItem,0);
  1593. DWORD dwFlag=m_ctServFile.GetItemData(nItem);
  1594. if(dwFlag==FILEICON)
  1595. return;
  1596. nItem=m_ctServDir.GetCurSel();
  1597. m_ctServDir.GetLBText(nItem,str);
  1598. if(str!="/")
  1599. str+="/";
  1600. str+=buf;
  1601. nItem=m_ctServDir.FindStringExact(-1,str);
  1602. if(nItem==CB_ERR)
  1603. nItem=OnInsertDir(&m_ctServDir,str,DIRECTORYICON,DIRECTORYSEL);
  1604. m_ctServDir.SetCurSel(nItem);
  1605. OnQuickConnect();
  1606. if(buf=="..")
  1607. m_ctServDir.DeleteItem(nItem);
  1608. *pResult = 0;
  1609. }
  1610. void CLocFileView::OnBegindragLocFile(NMHDR* pNMHDR, LRESULT* pResult) 
  1611. {
  1612. if(m_bDragging)return;
  1613. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;    
  1614. *pResult = 0;
  1615. int nItem=pNMListView->iItem;
  1616. POINT pt=pNMListView->ptAction;
  1617. m_pDragImageList=m_ctLocFile.CreateDragImage(nItem,&pt);
  1618. m_bDragging=TRUE;
  1619. m_pDragImageList->BeginDrag(0,CPoint(0,0));
  1620. m_pDragImageList->DragEnter(NULL,pt);
  1621. SetCapture();
  1622. SetCursor(m_hDragCursor);
  1623. *pResult = 0;
  1624. }
  1625. void CLocFileView::OnMouseMove(UINT nFlags, CPoint point) 
  1626. {
  1627.     if(m_bDragging)
  1628. {
  1629. CRect rect;
  1630. pServView->m_ctServFile.GetWindowRect(&rect);
  1631. ClientToScreen(&point);
  1632. if(rect.PtInRect(point)&&m_bConnected)
  1633. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  1634. else
  1635. SetCursor(m_hDragCursor);
  1636. m_pDragImageList->DragMove(point);
  1637. }
  1638. CFormView::OnMouseMove(nFlags, point);
  1639. }
  1640. void CLocFileView::OnLButtonUp(UINT nFlags, CPoint point) 
  1641. {
  1642.     if(m_bDragging)
  1643. {
  1644. m_bDragging=FALSE;
  1645. CImageList::DragLeave(NULL);
  1646. CImageList::EndDrag();
  1647. ReleaseCapture();
  1648. delete m_pDragImageList;
  1649. m_pDragImageList=NULL;
  1650. CRect rect;
  1651. pServView->m_ctServFile.GetWindowRect(&rect);
  1652. ClientToScreen(&point);
  1653. if(rect.PtInRect(point)&&m_bConnected)
  1654. OnLocFileSend();
  1655. }
  1656. CFormView::OnLButtonUp(nFlags, point);
  1657. }
  1658. void CLocFileView::OnLocFileSend()
  1659. {
  1660. if(!m_bConnected)return;
  1661. CString str,strFtp;
  1662. int i=0;
  1663. POSITION iPos;
  1664. int nItem=pServView->m_ctServDir.GetCurSel();
  1665. pServView->m_ctServDir.GetLBText(nItem,strFtp);
  1666. nItem=m_ctLocDir.GetCurSel();
  1667. m_ctLocDir.GetLBText(nItem,str);
  1668. i=m_ctLocFile.GetSelectedCount();
  1669. FILE_COUNT_INFO* pFileCount=new FILE_COUNT_INFO[i];
  1670. SEND_RECEIVE_INFO* pSeRe=new SEND_RECEIVE_INFO;
  1671. iPos=m_ctLocFile.GetFirstSelectedItemPosition();
  1672. for(int j=0;j<i;j++)
  1673. {
  1674. int nItem=m_ctLocFile.GetNextSelectedItem(iPos);
  1675. m_ctLocFile.GetItemText(nItem,0,pFileCount[j].fileName,256);
  1676. pFileCount[j].ufileFlag=m_ctLocFile.GetItemData(nItem);
  1677. }
  1678. CMyAppThread* pThread=new CMyAppThread(str,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
  1679. m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE,i);
  1680. pSeRe->pCount=pFileCount;
  1681. pSeRe->pThread=pThread;
  1682. if(!BeginSendFile(pSeRe))
  1683. AfxMessageBox("建立文件发送线程出错");
  1684. }
  1685. void CLocFileView::OnLocFileOpen()
  1686. {
  1687. CString str,szFile;
  1688. int nItem,i;
  1689. nItem=m_ctLocDir.GetCurSel();
  1690. if(nItem==CB_ERR)return;
  1691. m_ctLocDir.GetLBText(nItem,str);
  1692. szFile=str;
  1693. POSITION iPos=m_ctLocFile.GetFirstSelectedItemPosition();
  1694. nItem=m_ctLocFile.GetNextSelectedItem(iPos);
  1695. i=m_ctLocFile.GetItemData(nItem);
  1696. if(str.Right(1)=="\")
  1697. szFile+=m_ctLocFile.GetItemText(nItem,0);
  1698. else
  1699. szFile+="\"+m_ctLocFile.GetItemText(nItem,0);
  1700. if(i==FILEICON)
  1701. ::ShellExecute(m_hWnd,NULL,szFile,"open",str,SW_SHOWDEFAULT);
  1702. else
  1703. {
  1704. CMyAppThread* pThread=new CMyAppThread(szFile);
  1705. BeginFindLocFile(pThread);
  1706. }
  1707. }
  1708. void CLocFileView::OnLocFileDelete()
  1709. {
  1710. POSITION iPos=m_ctLocFile.GetFirstSelectedItemPosition();
  1711. if(!iPos)return;
  1712. SHFILEOPSTRUCT lpsh;
  1713. CString str;
  1714. int nItem;
  1715. int i=m_ctLocFile.GetSelectedCount();
  1716. ZeroMemory(&lpsh,sizeof(lpsh));
  1717. lpsh.hwnd= HWND_DESKTOP;
  1718. lpsh.fFlags=FOF_NOCONFIRMATION;
  1719. lpsh.wFunc=FO_DELETE;
  1720. for(int j=0;j<i;j++)
  1721. {
  1722. nItem=m_ctLocFile.GetNextSelectedItem(iPos);
  1723. str=m_ctLocFile.GetItemText(nItem,0);
  1724. char buf[MAX_PATH];
  1725. strcpy(buf,str);
  1726. buf[str.GetLength()+1]='';
  1727. lpsh.pFrom=buf;
  1728. if( 0 != SHFileOperation(&lpsh))
  1729. {
  1730. AfxMessageBox("删除文件出错,请检查");
  1731. return ;
  1732. }
  1733. }
  1734. nItem=m_ctLocDir.GetCurSel();
  1735. if(nItem==CB_ERR)
  1736. str="C:\";
  1737. else
  1738. m_ctLocDir.GetLBText(nItem,str);
  1739. CMyAppThread* pThread=new CMyAppThread(str);
  1740. BeginFindLocFile(pThread);
  1741. }
  1742. void CLocFileView::OnLocFileReName()
  1743. {
  1744. OnFileName(&m_ctLocFile);
  1745. }
  1746. void CLocFileView::OnRclickLocFile(NMHDR* pNMHDR, LRESULT* pResult) 
  1747. {
  1748. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  1749. *pResult = 0;
  1750. int nItem=pNMListView->iItem;
  1751. if(nItem==-1)return;
  1752. SetPopMenu(0);
  1753. *pResult = 0;
  1754. }
  1755. void CLocFileView::OnBeginlabeleditLocFile(NMHDR* pNMHDR, LRESULT* pResult) 
  1756. {
  1757. LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
  1758. // TODO: Add your control notification handler code here
  1759. *pResult = 0;
  1760. }
  1761. void CLocFileView::OnEndlabeleditLocFile(NMHDR* pNMHDR, LRESULT* pResult) 
  1762. {
  1763. int nItem;
  1764. CString str,buf;
  1765. nItem=m_ctLocDir.GetCurSel();
  1766.     m_ctLocDir.GetLBText(nItem,str);
  1767. ::SetCurrentDirectory(str);
  1768. LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
  1769. LV_ITEM * pItem=&pDispInfo->item;
  1770. nItem=pItem->iItem;
  1771. buf=m_ctLocFile.GetItemText(nItem,0);
  1772. if(pItem->pszText&&buf!=pItem->iItem)
  1773. {
  1774. m_ctLocFile.SetItemText(pItem->iItem,pItem->iSubItem,pItem->pszText);
  1775. ::rename(buf,pItem->pszText);
  1776. CMyAppThread* pThread=new CMyAppThread(str);
  1777. BeginFindLocFile(pThread);
  1778. }
  1779. *pResult = 0;
  1780. }
  1781. LRESULT CLocFileView::OnSetLocDir(WPARAM wParam,LPARAM lParam)
  1782. {
  1783. OnSetLocDirectoryDisplay(wParam,lParam);
  1784. m_ctLocFile.SetRedraw(FALSE);
  1785. m_ctLocFile.DeleteAllItems();
  1786. m_ctLocFile.SetRedraw();
  1787. return 0L;
  1788. }
  1789. /////////////////////////////////////////////////////////////////////////////
  1790. // CInputEdit
  1791. CInputEdit::CInputEdit(int iItem,int iSubItem,CString& szInitText,CListCtrl* pListCtrl)
  1792. {
  1793. m_pListCtrl=pListCtrl;
  1794. m_iItem=iItem;
  1795. m_iSubItem=iSubItem;
  1796. m_szInitText=szInitText;
  1797. m_bEsc=FALSE;
  1798. }
  1799. CInputEdit::~CInputEdit()
  1800. {
  1801. }
  1802. BEGIN_MESSAGE_MAP(CInputEdit, CEdit)
  1803. //{{AFX_MSG_MAP(CInputEdit)
  1804. ON_WM_CHAR()
  1805. ON_WM_KILLFOCUS()
  1806. ON_WM_CREATE()
  1807. ON_WM_NCDESTROY()
  1808. //}}AFX_MSG_MAP
  1809. END_MESSAGE_MAP()
  1810. /////////////////////////////////////////////////////////////////////////////
  1811. // CInputEdit message handlers
  1812. void CInputEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
  1813. {
  1814. if(nChar==VK_ESCAPE||nChar==VK_RETURN)
  1815. {
  1816. if(nChar==VK_ESCAPE)
  1817. m_bEsc=TRUE;
  1818. GetParent()->SetFocus();
  1819. return;
  1820. }
  1821. CEdit::OnChar(nChar, nRepCnt, nFlags);
  1822. CString str;
  1823. GetWindowText(str);
  1824. CWindowDC dc(this);
  1825. CFont* pFont=GetParent()->GetFont();
  1826. CFont* pFontDC=dc.SelectObject(pFont);
  1827. CSize size=dc.GetTextExtent(str);
  1828. dc.SelectObject(pFontDC);
  1829. size.cx+=5;
  1830. CRect rect,parentrect;
  1831. GetClientRect(&rect);
  1832. GetParent()->GetClientRect(&parentrect);
  1833. ClientToScreen(&rect);
  1834. GetParent()->ScreenToClient(&rect);
  1835. if(size.cx>rect.Width())
  1836. {
  1837. if(size.cx+rect.left<parentrect.right)
  1838. rect.right=rect.left+size.cx;
  1839. else
  1840. rect.right=parentrect.right;
  1841. MoveWindow(&rect);
  1842. }
  1843. }
  1844. void CInputEdit::OnKillFocus(CWnd* pNewWnd) 
  1845. {
  1846. CEdit::OnKillFocus(pNewWnd);
  1847. CString str;
  1848. GetWindowText(str);
  1849. LV_DISPINFO dispinfo;
  1850. dispinfo.hdr.hwndFrom=m_pListCtrl->m_hWnd;
  1851. dispinfo.hdr.idFrom=GetDlgCtrlID();
  1852. dispinfo.hdr.code=LVN_ENDLABELEDIT;
  1853. dispinfo.item.mask=LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
  1854. dispinfo.item.iItem=m_iItem;
  1855. dispinfo.item.iSubItem=m_iSubItem;
  1856. dispinfo.item.pszText=m_bEsc?NULL:(LPTSTR)(LPCTSTR)str;
  1857. dispinfo.item.cchTextMax=str.GetLength();
  1858. GetParent()->SendMessage(WM_NOTIFY,GetParent()->GetDlgCtrlID(),(LPARAM)&dispinfo);
  1859. DestroyWindow();
  1860. }
  1861. BOOL CInputEdit::PreTranslateMessage(MSG* pMsg) 
  1862. {
  1863. if(pMsg->wParam==VK_RETURN||pMsg->wParam==VK_DELETE||pMsg->wParam==VK_ESCAPE||
  1864. GetKeyState(VK_CONTROL))
  1865. {
  1866. ::TranslateMessage(pMsg);
  1867. ::DispatchMessage(pMsg);
  1868. return TRUE;
  1869. }
  1870. return CEdit::PreTranslateMessage(pMsg);
  1871. }
  1872. int CInputEdit::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  1873. {
  1874. if (CEdit::OnCreate(lpCreateStruct) == -1)
  1875. return -1;
  1876. CFont* font=GetParent()->GetFont();
  1877. SetFont(font);
  1878. SetWindowText(m_szInitText);
  1879. SetFocus();
  1880. SetSel(0,-1);
  1881. return 0;
  1882. }
  1883. void CInputEdit::OnNcDestroy() 
  1884. {
  1885. CEdit::OnNcDestroy();
  1886. delete this;
  1887. }
  1888. BOOL CLocFileView::PreTranslateMessage(MSG* pMsg) 
  1889. {
  1890. if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_ESCAPE&&m_bDragging)
  1891. {
  1892. m_bDragging=FALSE;
  1893. CImageList::DragLeave(NULL);
  1894. CImageList::EndDrag();
  1895. ReleaseCapture();
  1896. delete m_pDragImageList;
  1897. return TRUE;
  1898. }
  1899. return CFormView::PreTranslateMessage(pMsg);
  1900. }
  1901. void CServFileView::OnBegindragServFile(NMHDR* pNMHDR, LRESULT* pResult) 
  1902. {
  1903. if(m_bDragging)return;
  1904. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;    
  1905. *pResult = 0;
  1906. int nItem=pNMListView->iItem;
  1907. POINT pt=pNMListView->ptAction;
  1908. m_pDragImageList=m_ctServFile.CreateDragImage(nItem,&pt);
  1909. m_bDragging=TRUE;
  1910. m_pDragImageList->BeginDrag(0,CPoint(0,0));
  1911. m_pDragImageList->DragEnter(NULL,pt);
  1912. SetCapture();
  1913. }
  1914. void CServFileView::OnMouseMove(UINT nFlags, CPoint point) 
  1915. {
  1916.     if(m_bDragging)
  1917. {
  1918. CRect rect;
  1919. pLocView->m_ctLocFile.GetWindowRect(&rect);
  1920. ClientToScreen(&point);
  1921. if(rect.PtInRect(point)&&m_bConnected)
  1922. SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  1923. else
  1924. SetCursor(m_hDragCursor);
  1925. m_pDragImageList->DragMove(point);
  1926. }
  1927. CFormView::OnMouseMove(nFlags, point);
  1928. }
  1929. BOOL CServFileView::PreTranslateMessage(MSG* pMsg) 
  1930. {
  1931. if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==VK_ESCAPE&&m_bDragging)
  1932. {
  1933. m_bDragging=FALSE;
  1934. CImageList::DragLeave(NULL);
  1935. CImageList::EndDrag();
  1936. ReleaseCapture();
  1937. delete m_pDragImageList;
  1938. return TRUE;
  1939. }
  1940. return CFormView::PreTranslateMessage(pMsg);
  1941. }
  1942. void CServFileView::OnLButtonUp(UINT nFlags, CPoint point) 
  1943. {
  1944.     if(m_bDragging)
  1945. {
  1946. m_bDragging=FALSE;
  1947. CImageList::DragLeave(NULL);
  1948. CImageList::EndDrag();
  1949. ReleaseCapture();
  1950. delete m_pDragImageList;
  1951. m_pDragImageList=NULL;
  1952. CRect rect;
  1953. pLocView->m_ctLocFile.GetWindowRect(&rect);
  1954. ClientToScreen(&point);
  1955. if(rect.PtInRect(point)&&m_bConnected)
  1956. OnServFileDownload();
  1957. }
  1958. CFormView::OnLButtonUp(nFlags, point);
  1959. }
  1960. BOOL CServFileView::BeginReceiveFile(LPVOID pInfo)
  1961. {
  1962. SEND_RECEIVE_INFO* pInf=(SEND_RECEIVE_INFO*)pInfo;
  1963. CMyAppThread* pThread=(CMyAppThread*)pInf->pThread;
  1964. if(m_pReceiveFileThread)
  1965. {
  1966. ::WaitForSingleObject(m_pReceiveFileThread->m_hThread,INFINITE);
  1967. delete m_pReceiveFileThread;
  1968. m_pReceiveFileThread=NULL;
  1969. }
  1970. if(m_pReceiveFileThread=AfxBeginThread(pThread->StartReceiveFileThread,pInfo,THREAD_PRIORITY_ABOVE_NORMAL,
  1971. 0,CREATE_SUSPENDED,NULL))
  1972. {
  1973. m_pReceiveFileThread->m_bAutoDelete=FALSE;
  1974. nThreadCount++;
  1975. m_pReceiveFileThread->ResumeThread();
  1976. return TRUE;
  1977. }
  1978. return FALSE;
  1979. }
  1980. BOOL CServFileView::BeginPreReceiveFile(LPVOID pInfo)
  1981. {
  1982. CMyAppThread* pThread=(CMyAppThread*)pInfo;
  1983. CWinThread* pPreReceiveFile=NULL;
  1984. if(pPreReceiveFile=AfxBeginThread(pThread->StartPreReceiveFileThread,pInfo,THREAD_PRIORITY_NORMAL,
  1985. 0,CREATE_SUSPENDED,NULL))
  1986. {
  1987. nThreadCount++;
  1988. pPreReceiveFile->ResumeThread();
  1989. return TRUE;
  1990. }
  1991. return FALSE;
  1992. }
  1993. BOOL CServFileView::BeginPreDeleteFile(LPVOID pInfo)
  1994. {
  1995. CMyAppThread* pThread=(CMyAppThread*)pInfo;
  1996. CWinThread* pPreDeleteFile=NULL;
  1997. if(pPreDeleteFile=AfxBeginThread(pThread->StartPreDeleteFileThread,pInfo,THREAD_PRIORITY_NORMAL,
  1998. 0,CREATE_SUSPENDED,NULL))
  1999. {
  2000. nThreadCount++;
  2001. pPreDeleteFile->ResumeThread();
  2002. return TRUE;
  2003. }
  2004. return FALSE;
  2005. }
  2006. LRESULT CServFileView::OnPreReceiveFile(WPARAM wParam,LPARAM lParam)
  2007. {
  2008. CString str=(LPCTSTR)wParam;
  2009. CString strFtp=(LPCTSTR)lParam;
  2010. CMyAppThread* pThread=new CMyAppThread(str,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
  2011. m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE);
  2012. if(!BeginPreReceiveFile(pThread))
  2013. AfxMessageBox("起动发送子线程失败");
  2014. return 0L;
  2015. }
  2016. LRESULT CServFileView::OnPreDeleteFile(WPARAM wParam,LPARAM lParam)
  2017. {
  2018. CString strFtp=(LPCTSTR)lParam;
  2019. CMyAppThread* pThread=new CMyAppThread(NULL,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
  2020. m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE);
  2021. if(!BeginPreDeleteFile(pThread))
  2022. AfxMessageBox("起动发送子线程失败");
  2023. return 0L;
  2024. }
  2025. void CServFileView::OnRclickServFile(NMHDR* pNMHDR, LRESULT* pResult) 
  2026. {
  2027. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  2028. *pResult = 0;
  2029. int nItem=pNMListView->iItem;
  2030. if(nItem==-1||!m_bConnected)return;
  2031. SetPopMenu(1);
  2032. }
  2033. void CServFileView::OnBeginlabeleditServFile(NMHDR* pNMHDR, LRESULT* pResult) 
  2034. {
  2035. LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
  2036. *pResult = 0;
  2037. }
  2038. void CServFileView::OnEndlabeleditServFile(NMHDR* pNMHDR, LRESULT* pResult) 
  2039. {
  2040. int nItem;
  2041. CString str,strFtp;
  2042. nItem=m_ctServDir.GetCurSel();
  2043. if(nItem==CB_ERR)return;
  2044. m_ctServDir.GetLBText(nItem,strFtp);
  2045. LV_DISPINFO* pDispInfo = (LV_DISPINFO*)pNMHDR;
  2046. LV_ITEM * pItem=&pDispInfo->item;
  2047. nItem=pItem->iItem;
  2048. FILE_CHANGE_INFO* pInfo=new FILE_CHANGE_INFO;
  2049. str=m_ctServFile.GetItemText(nItem,0);
  2050. if(pItem->pszText&&str!=pItem->pszText)
  2051. {
  2052. CMyAppThread* pThread=new CMyAppThread(NULL,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
  2053. m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),strFtp,TRUE);
  2054. pInfo->pThread=pThread;
  2055. strcpy(pInfo->OldName,str);
  2056. strcpy(pInfo->NewName,pItem->pszText);
  2057. if(!BeginRenameFile(pInfo))
  2058. AfxMessageBox("建立文件重命名线程出错,返回");
  2059. m_ctServFile.SetItemText(pItem->iItem,pItem->iSubItem,pItem->pszText);
  2060. }
  2061. *pResult = 0;
  2062. }
  2063. void CServFileView::OnBack() 
  2064. {
  2065. CString str;
  2066. int nItem=m_ctServDir.GetCurSel();
  2067. if(nItem==CB_ERR)return;
  2068. m_ctServDir.GetLBText(nItem,str);
  2069. if(str=="/")return;
  2070. if(str.Right(1)!="/")
  2071. str+="/";
  2072. str+="..";
  2073. nItem=OnInsertDir(&m_ctServDir,str,DIRECTORYICON,DIRECTORYSEL);
  2074. m_ctServDir.SetCurSel(nItem);
  2075. OnQuickConnect();
  2076. m_ctServDir.DeleteItem(nItem);
  2077. }
  2078. void CServFileView::OnQuickConnect()
  2079. {
  2080. CString str;
  2081. int nItem=m_ctServDir.GetCurSel();
  2082. if(nItem!=CB_ERR)
  2083. m_ctServDir.GetLBText(nItem,str);
  2084. else
  2085. str=" ";
  2086. CMyAppThread* pThread=new CMyAppThread(NULL,m_pMainFrame->GetFtpName(),m_pMainFrame->GetFtpUser(),
  2087. m_pMainFrame->GetFtpPassword(),m_pMainFrame->GetFtpPort(),str,TRUE);
  2088. if(!BeginFindServFile(pThread))
  2089. AfxMessageBox("建立网络线程失败");
  2090. }
  2091. int CFtpInfoView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  2092. {
  2093. if (CEditView::OnCreate(lpCreateStruct) == -1)
  2094. return -1;
  2095.     pFtpInfoView=this;
  2096. m_NewFont.CreatePointFont(70,"Arial",NULL);
  2097. GetEditCtrl().SetFont(&m_NewFont,true);
  2098. return 0;
  2099. }
  2100. void CFtpInfoView::OnChange() 
  2101. {
  2102. return;
  2103. }
  2104. void CFtpInfoView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
  2105. {
  2106. //  CEditView::OnChar(nChar, nRepCnt, nFlags);
  2107. }
  2108. void CMainFrame::OnFileDisconnect() 
  2109. {
  2110. CString str,szFtpInfo;
  2111.     m_wndMyDialogBar.GetDlgItem(IDC_FTPNAME)->GetWindowText(str);
  2112. szFtpInfo="已中断与"+str+"的连接";
  2113. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  2114. InternetCloseHandle(hInetSession);
  2115. m_wndMyDialogBar.GetDlgItem(IDC_QUICKCONNECT)->ShowWindow(SW_HIDE);
  2116. m_bConnected=FALSE;
  2117. }
  2118. void CMainFrame::OnUpdateFileDisconnect(CCmdUI* pCmdUI) 
  2119. {
  2120.    pCmdUI->Enable(m_bConnected);
  2121.    
  2122. }
  2123. void CMainFrame::OnFileReconnect()
  2124. {
  2125. OnQuickconnect();
  2126. }
  2127. void CMainFrame::OnFileConnect() 
  2128. {
  2129. CString szFtpInfo;
  2130. if(hInetSession=InternetOpen(AfxGetAppName(),INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0))
  2131. {
  2132. szFtpInfo="已建立连接会话,请选择《快速连接》按钮连接至你所需要的文件服务器";
  2133. m_bConnected=TRUE;
  2134. m_wndMyDialogBar.GetDlgItem(IDC_QUICKCONNECT)->ShowWindow(SW_SHOW);
  2135. pFtpInfoView->SendMessage(WM_RECORDFTPINFO,0,(LPARAM)(LPCTSTR)szFtpInfo);
  2136. }
  2137. // OnQuickconnect();
  2138. }
  2139. void CMainFrame::OnUpdateFileConnect(CCmdUI* pCmdUI) 
  2140. {
  2141. pCmdUI->Enable(!m_bConnected);
  2142. }
  2143. void CMainFrame::OnUpdateFileReconnect(CCmdUI* pCmdUI) 
  2144. {
  2145.     pCmdUI->Enable(m_bConnected);
  2146. }
  2147. void CMainFrame::OnFileStop() 
  2148. {
  2149. m_bConnected=FALSE;
  2150. }
  2151. void CMainFrame::OnUpdateFileStop(CCmdUI* pCmdUI) 
  2152. {
  2153.    pCmdUI->Enable(m_bConnected);
  2154. }
  2155. void CMainFrame::OnUpdateFileSend(CCmdUI* pCmdUI) 
  2156. {
  2157.    pCmdUI->Enable(m_bConnected);
  2158. }
  2159. void CMainFrame::OnUpdateFileFtpDownload(CCmdUI* pCmdUI) 
  2160. {
  2161.    pCmdUI->Enable(m_bConnected);
  2162. }
  2163. /////////////////////////////////////////////////////////////////////////////
  2164. // CDialDlg dialog
  2165. CDialDlg::CDialDlg(CWnd* pParent /*=NULL*/)
  2166. : CDialog(CDialDlg::IDD, pParent)
  2167. {
  2168. //{{AFX_DATA_INIT(CDialDlg)
  2169. m_szPassword = _T("");
  2170. m_szUserID = _T("");
  2171. //}}AFX_DATA_INIT
  2172. }
  2173. void CDialDlg::DoDataExchange(CDataExchange* pDX)
  2174. {
  2175. CDialog::DoDataExchange(pDX);
  2176. //{{AFX_DATA_MAP(CDialDlg)
  2177. DDX_Control(pDX, IDC_INETNUMBER, m_ctEntryName);
  2178. DDX_Text(pDX, IDC_INETPASSWORD, m_szPassword);
  2179. DDX_Text(pDX, IDC_INETUSER, m_szUserID);
  2180. //}}AFX_DATA_MAP
  2181. }
  2182. BEGIN_MESSAGE_MAP(CDialDlg, CDialog)
  2183. //{{AFX_MSG_MAP(CDialDlg)
  2184. //}}AFX_MSG_MAP
  2185. END_MESSAGE_MAP()
  2186. /////////////////////////////////////////////////////////////////////////////
  2187. // CDialDlg message handlers
  2188. BOOL CDialDlg::OnInitDialog() 
  2189. {
  2190. CDialog::OnInitDialog();
  2191. return TRUE;  // return TRUE unless you set the focus to a control
  2192.               // EXCEPTION: OCX Property Pages should return FALSE
  2193. }
  2194. void CServFileView::OnSelchangeServDir() 
  2195. {
  2196. OnQuickConnect();
  2197. }