// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "myFtpClient.h" #include "MainFrm.h" #include "myftpclientview.h" #include "localdirview.h" #include "messageShowView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_BN_CLICKED(IDC_CONNECT, OnConnect) ON_COMMAND(ID_FILE_BACK, OnFileBack) ON_COMMAND(IDC_LINK, OnLink) ON_UPDATE_COMMAND_UI(IDC_LINK, OnUpdateLink) ON_COMMAND(IDC_CUT, OnCut) ON_UPDATE_COMMAND_UI(IDC_CUT, OnUpdateCut) ON_UPDATE_COMMAND_UI(ID_FILE_BACK, OnUpdateFileBack) ON_COMMAND(IDC_EXIT, OnExit) //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { // TODO: add member initialization code here } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_wndToolBar.LoadToolBar(IDR_MAINFRAME)) { TRACE0("Failed to create toolbar\n"); return -1; // fail to create } if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } // TODO: Delete these three lines if you don't want the toolbar to // be dockable m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndToolBar); if (!m_wndMyDialogBar.Create(this, GJL_FLOAT, CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE, GJL_FLOAT)) { TRACE0("Failed to create dialog bar m_wndMyDialogBar\n"); return -1; // fail to create } m_wndMyDialogBar.EnableDocking(CBRS_ALIGN_TOP | CBRS_ALIGN_BOTTOM); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndMyDialogBar); m_wndMyDialogBar.SetDlgItemText(IDC_PORT,"21"); m_wndMyDialogBar.SetDlgItemText(IDC_HOST,"127.0.0.1"); m_wndMyDialogBar.SetDlgItemText(IDC_ID,"ftp"); m_wndMyDialogBar.SetDlgItemText(IDC_KEY,"ftp"); return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { // TODO: Add your specialized code here and/or call the base class if(!m_splitterWnd1.CreateStatic(this,2,1)) { return false; } if(!m_splitterWnd1.CreateView(0,0,RUNTIME_CLASS(messageShowView),CSize(100,80),pContext)) { return false; } if(! m_splitterWnd2.CreateStatic(&m_splitterWnd1,1,2,WS_CHILD|WS_VISIBLE,m_splitterWnd1.IdFromRowCol(1,0))) { return false; } if(!m_splitterWnd2.CreateView(0,0,RUNTIME_CLASS(localDirView),CSize(300,500),pContext)) { return false; } if(!m_splitterWnd2.CreateView(0,1,RUNTIME_CLASS(CMyFtpClientView),CSize(800,500),pContext)) { return false; } return TRUE; } void CMainFrame::OnConnect() { // TODO: Add your control notification handler code here CMyFtpClientView *pLView = (CMyFtpClientView *)(m_splitterWnd2.GetPane(0,1)); pLView->callConnect(); OnFileBack(); } void CMainFrame::OnFileBack() { // TODO: Add your command handler code here CMyFtpClientView *pLView = (CMyFtpClientView *)(m_splitterWnd2.GetPane(0,1)); pLView->callFileBack(); } void CMainFrame::OnLink() { // TODO: Add your command handler code here CMyFtpClientView *pLView = (CMyFtpClientView *)(m_splitterWnd2.GetPane(0,1)); pLView->callConnect(); } void CMainFrame::OnUpdateLink(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here CMyFtpClientView *pLView = (CMyFtpClientView *)(m_splitterWnd2.GetPane(0,1)); if(pLView->m_bConnect) { pCmdUI->Enable(FALSE); // 将按钮置灰 pCmdUI->SetCheck(TRUE); // 将按钮置成按下状态 } else { pCmdUI->Enable(TRUE); pCmdUI->SetCheck(FALSE); } } void CMainFrame::OnCut() { // TODO: Add your command handler code here CMyFtpClientView *pLView = (CMyFtpClientView *)(m_splitterWnd2.GetPane(0,1)); pLView->callConnect(); } void CMainFrame::OnUpdateCut(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here CMyFtpClientView *pLView = (CMyFtpClientView *)(m_splitterWnd2.GetPane(0,1)); if(!pLView->m_bConnect) { pCmdUI->Enable(FALSE); // 将按钮置灰 pCmdUI->SetCheck(TRUE); // 将按钮置成按下状态 } else { pCmdUI->Enable(TRUE); pCmdUI->SetCheck(FALSE); } } void CMainFrame::OnUpdateFileBack(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here CMyFtpClientView *pLView = (CMyFtpClientView *)(m_splitterWnd2.GetPane(0,1)); if(!pLView->m_bConnect) { pCmdUI->Enable(FALSE); // 将按钮置灰 pCmdUI->SetCheck(TRUE); // 将按钮置成按下状态 } else { pCmdUI->Enable(TRUE); pCmdUI->SetCheck(FALSE); } } void CMainFrame::OnExit() { // TODO: Add your command handler code here ::PostMessage(AfxGetMainWnd()->m_hWnd, WM_CLOSE,0,0); }