PageFiles.cpp
资源名称:Netmanag.zip [点击查看]
上传用户:geanq888
上传日期:2007-01-03
资源大小:316k
文件大小:14k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // PageFiles.cpp : implementation file
- //
- #include "stdafx.h"
- #include "NetManager.h"
- #include "PageFiles.h"
- #include "GlobalsExtern.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CPageFiles property page
- IMPLEMENT_DYNCREATE(CPageFiles, CPropertyPage)
- CPageFiles::CPageFiles() : CPropertyPage(CPageFiles::IDD)
- {
- //{{AFX_DATA_INIT(CPageFiles)
- m_sSourceCopyFile = _T("");
- m_sDestCopyFile = _T("");
- m_bDeleteOnEnd = FALSE;
- m_bReturnOnEnd = FALSE;
- m_bCopyOnStart = FALSE;
- //}}AFX_DATA_INIT
- m_nColumnWidth = 100;
- }
- CPageFiles::~CPageFiles()
- {
- }
- void CPageFiles::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPageFiles)
- DDX_Control(pDX, IDC_FILESSPIN, m_FilesSpin);
- DDX_Control(pDX, IDB_AUTOSTART, m_AutoStart);
- DDX_Control(pDX, IDC_FILEPATH, m_FilePath);
- DDX_Control(pDX, IDC_FILE_DEST, m_DestCopyFile);
- DDX_Control(pDX, IDC_FILE_SOURCE, m_SourceCopyFile);
- DDX_Text(pDX, IDC_FILE_SOURCE, m_sSourceCopyFile);
- DDX_Text(pDX, IDC_FILE_DEST, m_sDestCopyFile);
- DDX_Check(pDX, IDB_ONEND_DELETE, m_bDeleteOnEnd);
- DDX_Check(pDX, IDB_ONEND_RETURN, m_bReturnOnEnd);
- DDX_Check(pDX, IDB_ONSTART_COPY, m_bCopyOnStart);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPageFiles, CPropertyPage)
- //{{AFX_MSG_MAP(CPageFiles)
- ON_BN_CLICKED(IDC_COPY_FILE, OnCopyFile)
- ON_BN_CLICKED(IDC_DELETE_FILE, OnDeleteFile)
- ON_BN_CLICKED(IDC_RETURN_FILE, OnReturnFile)
- ON_BN_CLICKED(IDC_BROWSE_SOURCEFILE, OnBrowseSourceFile)
- ON_BN_CLICKED(IDC_BROWSE_DESTFILE, OnBrowseDestFile)
- ON_BN_CLICKED(IDC_ADD_EXE, OnAddExe)
- ON_BN_CLICKED(IDC_REMOVE_EXE, OnRemoveExe)
- ON_BN_CLICKED(IDC_EXECUTE_EXE, OnExecuteExe)
- ON_BN_CLICKED(IDB_AUTOSTART, OnAutostart)
- ON_NOTIFY(UDN_DELTAPOS, IDC_FILESSPIN, OnDeltaposFilesspin)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPageFiles message handlers
- UINT g_AddIcon(LPVOID pParam)
- {
- CPtrArray* paAddIcon = ((CPtrArray*)pParam);
- CPageFilesExeList* pExeFiles = (CPageFilesExeList*)paAddIcon->GetAt(0);
- ARRAY_EXEFILES* paExeFiles = (ARRAY_EXEFILES*)paAddIcon->GetAt(1);
- CImageList* pImagesSmall = (CImageList*)paAddIcon->GetAt(2);
- CImageList* pImagesLarge = (CImageList*)paAddIcon->GetAt(3);
- CString sIconPath;
- LPSTR psIconPath;
- int j = paExeFiles->GetSize();
- for(int i = 0; i < j; i++)
- {
- sIconPath = paExeFiles->GetAt(i).sPath;
- psIconPath = sIconPath.GetBuffer(MAX_PATH);
- WORD wIconIndex = 0;
- HICON hExeIcon;
- if((hExeIcon = ExtractIcon(AfxGetInstanceHandle(), psIconPath, 0)) != NULL)
- {
- pImagesSmall->Add(hExeIcon);
- pImagesLarge->Add(hExeIcon);
- }
- else if((hExeIcon = ExtractAssociatedIcon(AfxGetInstanceHandle(), psIconPath, &wIconIndex)) != NULL)
- {
- pImagesSmall->Add(hExeIcon);
- pImagesLarge->Add(hExeIcon);
- }
- sIconPath.ReleaseBuffer();
- pExeFiles->Update(i);
- }
- paAddIcon->RemoveAll();
- delete paAddIcon;
- return 0;
- }
- /////////////////////////////////////////////////////////////////////////////
- BOOL CPageFiles::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
- m_ToolTip.Create(this);
- m_ToolTip.Activate(TRUE);
- CWnd* pWnd = GetWindow(GW_CHILD);
- while(pWnd)
- {
- int nID = pWnd->GetDlgCtrlID();
- if (nID != -1)
- m_ToolTip.AddTool(pWnd, pWnd->GetDlgCtrlID());
- pWnd = pWnd->GetWindow(GW_HWNDNEXT);
- }
- m_ExeFiles.SubclassDlgItem(IDC_EXE_FILES, this);
- // image list ---------------------------------------------------------------
- m_ImagesSmall.Create(16, 16, ILC_COLORDDB | ILC_MASK, 1, 100);
- m_ImagesLarge.Create(32, 32, ILC_COLORDDB | ILC_MASK, 1, 100);
- m_ImagesStates.Create(16, 16, ILC_COLORDDB | ILC_MASK, 2, 0);
- m_ImagesStates.Add(g_pThisApp->LoadIcon(IDI_UNCHECKED));
- m_ImagesStates.Add(g_pThisApp->LoadIcon(IDI_CHECKED));
- m_ExeFiles.SetImageList(&m_ImagesStates, LVSIL_STATE);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::SetSmallImages()
- {
- m_ExeFiles.SetImageList(&m_ImagesSmall, LVSIL_SMALL);
- m_ExeFiles.SetColumnWidth(0, m_FilesSpin.GetPos());
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::SetLargeImages()
- {
- m_ExeFiles.SetImageList(&m_ImagesLarge, LVSIL_SMALL);
- m_ExeFiles.SetColumnWidth(0, m_FilesSpin.GetPos());
- }
- /////////////////////////////////////////////////////////////////////////////
- UINT g_Execute(LPVOID pParam)
- {
- CString sFileToExe = ((CStringArray*)pParam)->GetAt(0);
- CString sFileName = ((CStringArray*)pParam)->GetAt(1);
- ((CStringArray*)pParam)->RemoveAll();
- delete ((CStringArray*)pParam);
- if((int)ShellExecute(::GetDesktopWindow(), _T("open"), sFileToExe, NULL, NULL, SW_NORMAL) < 33)
- g_WriteToHistory(TRUE, "[Files] Error - Execute File " + sFileToExe);
- else
- g_WriteToHistory(TRUE, "[Files] Executed " + sFileName);
- return 0;
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::FilesExecute(int nWhich)
- {
- g_AnimateWait->Play(0, -1, -1);
- CString sFileToExe;
- CStringArray* pasFiles = new CStringArray;
- pasFiles->Add(m_aExeFiles[nWhich].sPath);
- pasFiles->Add(m_ExeFiles.GetItemText(nWhich, 0));
- AfxBeginThread(g_Execute, pasFiles);
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::OnCopyFile()
- {
- UpdateData();
- FilesCopy();
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::FilesCopy()
- {
- g_AnimateWait->Play(0, -1, -1);
- if(!CopyFile(m_sSourceCopyFile, m_sDestCopyFile, FALSE))
- g_WriteToHistory(TRUE, "[Files] Error - Copy file " + m_sSourceCopyFile + " -> " + m_sDestCopyFile);
- else
- g_WriteToHistory(TRUE, "[Files] File copied (" + m_sSourceCopyFile + " -> " + m_sDestCopyFile + ")");
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::OnReturnFile()
- {
- UpdateData();
- FilesReturn();
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::FilesReturn()
- {
- g_AnimateWait->Play(0, -1, -1);
- if(!CopyFile(m_sDestCopyFile, m_sSourceCopyFile, FALSE))
- g_WriteToHistory(TRUE, "[Files] Error - Return file " + m_sDestCopyFile + " -> " + m_sSourceCopyFile);
- else
- g_WriteToHistory(TRUE, "[Files] File returned (" + m_sDestCopyFile + " -> " + m_sSourceCopyFile + ")");
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::OnDeleteFile()
- {
- UpdateData();
- FilesDelete();
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::FilesDelete()
- {
- g_AnimateWait->Play(0, -1, -1);
- if(!DeleteFile(m_sDestCopyFile))
- g_WriteToHistory(TRUE, "[Files] Error - Delete file (" + m_sDestCopyFile + ")");
- else
- g_WriteToHistory(TRUE, "[Files] File deleted (" + m_sDestCopyFile + ")");
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::OnBrowseSourceFile()
- {
- UpdateData();
- CFileDialog BrowseDialog(TRUE);
- if(BrowseDialog.DoModal() == IDOK)
- {
- m_sSourceCopyFile = BrowseDialog.GetPathName();
- m_SourceCopyFile.SetWindowText(m_sSourceCopyFile);
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::OnBrowseDestFile()
- {
- UpdateData();
- CFileDialog BrowseDialog(TRUE);
- if(BrowseDialog.DoModal() == IDOK)
- {
- m_sDestCopyFile = BrowseDialog.GetPathName();
- m_DestCopyFile.SetWindowText(m_sDestCopyFile);
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::OnAddExe()
- {
- CFileDialog AddExeDialog(TRUE);
- if(AddExeDialog.DoModal() == IDOK)
- AddExe(AddExeDialog.GetPathName());
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::AddExe(CString sPath)
- {
- EXEFILE exefile;
- exefile.sPath = sPath;
- exefile.nAutoStart = 0;
- CString sName = sPath;
- sName.MakeReverse();
- sName = sName.Left(sName.Find('\'));
- sName.MakeReverse();
- exefile.sName = sName;
- int i = m_ExeFiles.InsertItem(m_ExeFiles.GetItemCount(), sName);
- if(i != -1)
- {
- m_aExeFiles.Add(exefile);
- HICON hExeIcon;
- char* psIconPath;
- WORD wIconIndex = 0;
- psIconPath = sPath.GetBuffer(MAX_PATH);
- if((hExeIcon = ExtractIcon(AfxGetInstanceHandle(), psIconPath, 0)) != NULL)
- {
- m_ImagesSmall.Add(hExeIcon);
- m_ImagesLarge.Add(hExeIcon);
- }
- else if((hExeIcon = ExtractAssociatedIcon(AfxGetInstanceHandle(), psIconPath, &wIconIndex)) != NULL)
- {
- m_ImagesSmall.Add(hExeIcon);
- m_ImagesLarge.Add(hExeIcon);
- }
- sPath.ReleaseBuffer();
- m_ExeFiles.SetItem(i, NULL, LVIF_IMAGE, NULL, i, NULL, NULL, NULL);
- m_ExeFiles.SetItemState(i, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK);
- g_WriteToHistory(TRUE, "[Files] Added " + sName);
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::OnRemoveExe()
- {
- if(m_ExeFiles.GetSelectedCount() != 0)
- {
- if(MessageBox("Remove item(s)???", NULL, MB_ICONQUESTION | MB_YESNO) == IDYES)
- {
- int nItem = -1;
- while((nItem = m_ExeFiles.GetNextItem(nItem, LVNI_SELECTED)) != -1)
- {
- g_WriteToHistory(TRUE, "[Files] Removed " + m_ExeFiles.GetItemText(nItem, 0));
- m_ExeFiles.DeleteItem(nItem);
- m_aExeFiles.RemoveAt(nItem);
- m_ImagesSmall.Remove(nItem);
- m_ImagesLarge.Remove(nItem);
- m_FilePath.SetWindowText("");
- nItem = -1;
- }
- int j = m_ExeFiles.GetItemCount();
- for(int i = 0; i < j; i++)
- {
- m_ExeFiles.SetItem(i, NULL, LVIF_IMAGE, NULL, i, NULL, NULL, NULL);
- m_ExeFiles.SetItemState(i, INDEXTOSTATEIMAGEMASK(m_aExeFiles[i].nAutoStart + 1), LVIS_STATEIMAGEMASK);
- }
- }
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::OnExecuteExe()
- {
- if(m_ExeFiles.GetSelectedCount() != 0)
- {
- int nWhichItem = 0;
- if(m_ExeFiles.GetSelectedCount() == 1)
- {
- while(m_ExeFiles.GetItemState(nWhichItem, LVIS_SELECTED) != LVIS_SELECTED)
- nWhichItem++;
- }
- FilesExecute(nWhichItem);
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::OnAutostart()
- {
- if(m_ExeFiles.GetSelectedCount() != 0)
- m_ExeFiles.SwitchExeAuto();
- }
- /////////////////////////////////////////////////////////////////////////////
- BOOL CPageFiles::PreTranslateMessage(MSG* pMsg)
- {
- // transate the message based on TTM_WINDOWFROMPOINT
- MSG msg = *pMsg;
- msg.hwnd = (HWND)m_ToolTip.SendMessage(TTM_WINDOWFROMPOINT, 0, (LPARAM)&msg.pt);
- CPoint pt = pMsg->pt;
- if (msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST)
- ::ScreenToClient(msg.hwnd, &pt);
- msg.lParam = MAKELONG(pt.x, pt.y);
- // Let the ToolTip process this message.
- m_ToolTip.RelayEvent(&msg);
- if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
- {
- switch(GetFocus()->GetDlgCtrlID())
- {
- case IDC_FILE_SOURCE:
- NextDlgCtrl();
- break;
- case IDC_FILE_DEST:
- NextDlgCtrl();
- break;
- }
- }
- return CPropertyPage::PreTranslateMessage(pMsg);
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::OnDeltaposFilesspin(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- m_ExeFiles.SetColumnWidth(0, m_FilesSpin.GetPos());
- *pResult = 0;
- }
- /////////////////////////////////////////////////////////////////////////////
- void CPageFiles::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- { // storing code
- ar << m_ExeFiles.GetColumnWidth(0);
- int j = m_aExeFiles.GetSize();
- ar << j;
- for(int i = 0; i < j; i++)
- {
- ar << m_aExeFiles[i].sName;
- ar << m_aExeFiles[i].sPath;
- ar << m_aExeFiles[i].nAutoStart;
- }
- ar << m_sSourceCopyFile;
- ar << m_sDestCopyFile;
- ar << m_bCopyOnStart;
- ar << m_bReturnOnEnd;
- ar << m_bDeleteOnEnd;
- }
- else
- { // loading code
- ar >> m_nColumnWidth;
- m_FilesSpin.SetRange(32, 400);
- m_FilesSpin.SetPos(m_nColumnWidth);
- m_ExeFiles.SetColumnWidth(0, m_nColumnWidth);
- EXEFILE exefile;
- int j;;
- ar >> j;
- for(int i = 0; i < j; i++)
- {
- ar >> exefile.sName;
- ar >> exefile.sPath;
- ar >> exefile.nAutoStart;
- m_aExeFiles.Add(exefile);
- m_ExeFiles.InsertItem(i, m_aExeFiles[i].sName);
- m_ExeFiles.SetItem(i, NULL, LVIF_IMAGE, NULL, i, NULL, NULL, NULL);
- m_ExeFiles.SetItemState(i, INDEXTOSTATEIMAGEMASK(m_aExeFiles[i].nAutoStart + 1), LVIS_STATEIMAGEMASK);
- }
- CPtrArray* paIcon = new CPtrArray;
- paIcon->Add(&m_ExeFiles);
- paIcon->Add(&m_aExeFiles);
- paIcon->Add(&m_ImagesSmall);
- paIcon->Add(&m_ImagesLarge);
- AfxBeginThread(g_AddIcon, paIcon);
- ar >> m_sSourceCopyFile;
- ar >> m_sDestCopyFile;
- ar >> m_bCopyOnStart;
- ar >> m_bReturnOnEnd;
- ar >> m_bDeleteOnEnd;
- if(!g_bExeImages)
- SetSmallImages();
- else
- SetLargeImages();
- }
- }
- /////////////////////////////////////////////////////////////////////////////