TransmitFileDlg.cpp
资源名称:FTP总集.rar [点击查看]
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:7k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // TransmitFileDlg.cpp : implementation file
- //
- /*********************************************
- **该文件是属于WolfFTP工程中的。如果有什么问题
- **请联系
- ** tablejiang@21cn.com
- **或者访问
- ** http://wolfftp.51.net
- **以得到最新的支持。
- *********************************************/
- #include "stdafx.h"
- #include "quickftp.h"
- #include "TransmitFileDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CTransmitFileDlg dialog
- CTransmitFileDlg::CTransmitFileDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CTransmitFileDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CTransmitFileDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- m_FileQueue.SetSaveFileName( "BkTransmit.QFQ" ) ;
- }
- void CTransmitFileDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CTransmitFileDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CTransmitFileDlg, CDialog)
- //{{AFX_MSG_MAP(CTransmitFileDlg)
- ON_WM_SIZE()
- ON_WM_CLOSE()
- ON_WM_DESTROY()
- ON_COMMAND(IDR_BACK_RUN, OnBackRun)
- ON_COMMAND(IDR_BACK_STOP, OnBackStop)
- ON_COMMAND(IDR_BACK_SELALL, OnBackSelall)
- ON_COMMAND(IDR_BACK_STOPALL, OnBackStopall)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTransmitFileDlg message handlers
- void CTransmitFileDlg::OnOK()
- {
- // TODO: Add extra validation here
- //CDialog::OnOK();
- }
- void CTransmitFileDlg::OnCancel()
- {
- // TODO: Add extra cleanup here
- ShowWindow( SW_HIDE ) ;
- //CDialog::OnCancel();
- }
- BOOL CTransmitFileDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- m_Bar.Create( WS_CHILD|WS_VISIBLE|CCS_BOTTOM|SBARS_SIZEGRIP,
- CRect(0,0,0,0), this, 0x413 ) ;
- RECT rect ;
- GetWindowRect( &rect ) ;
- rect.top = rect.bottom - 20 ;
- m_Bar.SetControlPos( rect.right - rect.left ) ;
- m_Bar.MoveWindow( &rect ) ;
- m_Bar.SetPos( 0 ) ;
- InitList( ) ;
- m_Transmit.m_hParentWnd = m_hWnd ;
- m_FileQueue.m_hParentWnd = m_hWnd ;
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- BOOL CTransmitFileDlg::InitList()
- {
- RECT rect ;
- GetClientRect( &rect ) ;
- rect.bottom -= 20 ;
- m_ListCtrl.Create( WS_CHILD|WS_VISIBLE|LVS_REPORT ,
- rect , this , IDC_TRANSMITFILELIST ) ;
- m_ListCtrl.SetRowFullSelect( ) ;
- m_ListCtrl.SetParentWnd( m_hWnd ) ;
- RefreshJobList( ) ;
- return true ;
- }
- void CTransmitFileDlg::OnSize(UINT nType, int cx, int cy)
- {
- CDialog::OnSize(nType, cx, cy);
- // TODO: Add your message handler code here
- RECT rect ;
- GetClientRect( &rect ) ;
- rect.bottom -= 20 ;
- if( m_ListCtrl.m_hWnd )
- m_ListCtrl.MoveWindow( &rect , true ) ;
- if( m_Bar.m_hWnd )
- {
- GetWindowRect( &rect ) ;
- m_Bar.SetControlPos( rect.right - rect.left ) ;
- //Must move the window ,it will auto move to bottom
- m_Bar.MoveWindow( 0 , 0 , 100 , 100 ) ;
- }
- }
- BOOL CTransmitFileDlg::StartTransmitFile( )
- {
- RefreshJobList( ) ;
- m_Transmit.SetFileQueue( &m_FileQueue ) ;
- m_Transmit.SetParentWnd( m_hWnd ) ;
- m_Transmit.StartTransmit( m_hWnd ) ;
- return true ;
- }
- LRESULT CTransmitFileDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // TODO: Add your specialized code here and/or call the base class
- switch( message )
- {
- case REFRESH_WND_MSG :
- {
- RefreshJobList( ) ;
- }
- break ;
- case FTP_TRANSMIT_DATA_MSG :
- {
- m_Bar.SetPos( wParam ) ;
- m_Bar.SetSpeed( lParam ) ;
- }
- break ;
- case SEND_TRANSMIT_FILENAME_MSG :
- {
- char* pName ;
- pName = (char*)wParam ;
- m_Bar.SetDisplayString( pName ) ;
- delete pName ;
- }
- break ;
- case JOBLIST_KEYDOWN_MSG :
- {
- switch( wParam )
- {
- case VK_DELETE :
- DeleteSelectItem( ) ;
- break ;
- default :
- break ;
- }
- }
- break ;
- case JOBLIST_RBTN_UP_MSG :
- {
- POINT point ;
- GetCursorPos( &point ) ;
- ScreenToClient( &point ) ;
- CMenu PopMenu ;
- CPoint myPoint ;
- myPoint = point ;
- ClientToScreen( &myPoint );
- PopMenu.LoadMenu( IDR_MAINFRAME ) ;
- CMenu *pPopMenu = PopMenu.GetSubMenu( 5 ) ;
- pPopMenu->TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON , myPoint.x , myPoint.y , this ) ;
- PopMenu.DestroyMenu() ;
- }
- break ;
- default :
- break ;
- }
- return CDialog::DefWindowProc(message, wParam, lParam);
- }
- BOOL CTransmitFileDlg::RefreshJobList()
- {
- m_ListCtrl.DeleteAllItems( ) ;
- FTPFILEINFO* pCur ;
- m_FileQueue.LockTheFileList( ) ;
- pCur = m_FileQueue.m_pFileTransmitQueue ;
- int iItem = 0 ;
- while( pCur != NULL )
- {
- m_ListCtrl.AddItem( pCur , 0 ) ;
- pCur = pCur->pNext ;
- iItem ++ ;
- }
- m_FileQueue.UnLockTheFileList() ;
- return true ;
- }
- BOOL CTransmitFileDlg::AddToBkQueue(FTPFILEINFO *pFileInfo)
- {
- m_FileQueue.AddItem( pFileInfo ) ;
- RefreshJobList( ) ;
- return true ;
- }
- void CTransmitFileDlg::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
- CDialog::OnClose();
- }
- void CTransmitFileDlg::OnDestroy()
- {
- CDialog::OnDestroy();
- m_FileQueue.DeleteAllFileQueue( ) ;
- // TODO: Add your message handler code here
- }
- BOOL CTransmitFileDlg::DeleteSelectItem()
- {
- FTPFILEINFO FtpFile ;
- UINT iSelectCount = m_ListCtrl.GetSelectedCount( ) ;
- if( iSelectCount <= 0 )
- return true ;
- int iItem = -1 ;
- for( UINT i= 0 ; i < iSelectCount ; i ++ )
- {
- iItem = m_ListCtrl.GetNextItem( iItem , LVNI_SELECTED ) ;
- m_ListCtrl.GetItemInfo( iItem , &FtpFile ) ;
- m_FileQueue.DeleteItem( &FtpFile ) ;
- }
- RefreshJobList( ) ;
- return true ;
- }
- BOOL CTransmitFileDlg::SetSelectItemStatus(int iState)
- {
- FTPFILEINFO FtpFile ;
- UINT iSelectCount = m_ListCtrl.GetSelectedCount( ) ;
- if( iSelectCount <= 0 )
- return true ;
- int iItem = -1 ;
- for( UINT i= 0 ; i < iSelectCount ; i ++ )
- {
- iItem = m_ListCtrl.GetNextItem( iItem , LVNI_SELECTED ) ;
- m_ListCtrl.GetItemInfo( iItem , &FtpFile ) ;
- if( iState == FILE_STATE_STOP )
- {
- if( FtpFile.state == FILE_STATE_RUNNING )
- {
- m_Transmit.StopNowCommand( ) ;
- }
- }
- m_FileQueue.SetItemState( iState , &FtpFile ) ;
- }
- RefreshJobList( ) ;
- return true ;
- }
- void CTransmitFileDlg::OnBackRun()
- {
- // TODO: Add your command handler code here
- SetSelectItemStatus( FILE_STATE_READY ) ;
- StartTransmitFile( ) ;
- }
- void CTransmitFileDlg::OnBackStop()
- {
- // TODO: Add your command handler code here
- m_Transmit.SetStopSign( false ) ;
- SetSelectItemStatus( FILE_STATE_STOP ) ;
- }
- void CTransmitFileDlg::OnBackSelall()
- {
- // TODO: Add your command handler code here
- m_ListCtrl.SelectAllItem( ) ;
- }
- BOOL CTransmitFileDlg::StopAllTransmitTask()
- {
- FTPFILEINFO FtpFile ;
- UINT iSelectCount = m_ListCtrl.GetItemCount( ) ;
- if( iSelectCount <= 0 )
- return true ;
- int iItem ;
- for( UINT i= 0 ; i < iSelectCount ; i ++ )
- {
- iItem = i ;
- m_ListCtrl.GetItemInfo( iItem , &FtpFile ) ;
- if( FtpFile.state == FILE_STATE_RUNNING )
- {
- m_Transmit.StopNowCommand( ) ;
- }
- m_FileQueue.SetItemState( FILE_STATE_STOP , &FtpFile ) ;
- }
- RefreshJobList( ) ;
- return true ;
- }
- void CTransmitFileDlg::OnBackStopall()
- {
- // TODO: Add your command handler code here
- m_Transmit.SetStopSign( false ) ;
- StopAllTransmitTask( ) ;
- }