⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 applicationdlg.cpp

📁 这时一个ftp服务器,可以根据这个小的服务器原型做出更大的服务器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	CMenu* pMainMenu = GetMenu();
    CCmdUI cmdUI;
    // update menu enable/disable state
    for (UINT n = 0; n < pMainMenu->GetMenuItemCount(); ++n)
    {
        CMenu* pSubMenu = pMainMenu->GetSubMenu(n);
        cmdUI.m_nIndexMax = pSubMenu->GetMenuItemCount();
        for (UINT i = 0; i < cmdUI.m_nIndexMax;++i)
        {
            cmdUI.m_nIndex = i;
            cmdUI.m_nID = pSubMenu->GetMenuItemID(i);
            cmdUI.m_pMenu = pSubMenu;
            cmdUI.DoUpdate(this, FALSE);
        }
    }
	// enable/disable toolbar buttons    
	if (m_wndToolBar.IsWindowVisible()) 
	{
		// OnUpdateCmdUI expects a CFrameWnd pointer, so let's fake it ..
		CFrameWnd *pParent = (CFrameWnd *)this;
		if (pParent)
			m_wndToolBar.OnUpdateCmdUI(pParent, TRUE);
	} 

	return Default();
}


/********************************************************************/
/*																	*/
/* Function name : OnHelpAbout										*/		
/* Description   : Show Aboutbox.									*/	
/*																	*/
/********************************************************************/
void CApplicationDlg::OnHelpAbout() 
{
	CAboutDlg dlg;
	dlg.DoModal();
}


/********************************************************************/
/*																	*/
/* Function name : OnServerExit										*/		
/* Description   : Let's get out of here...							*/	
/*																	*/
/********************************************************************/
void CApplicationDlg::OnServerExit() 
{
	OnCancel();	
}


/********************************************************************/
/*																	*/
/* Function name : CApplicationDlg::SetupOutlookBar					*/		
/* Description   : Initialize listview, change color/iconspacing to	*/
/*				   make it look a little bit like the outlook bar.	*/
/*																	*/
/********************************************************************/
void CApplicationDlg::SetupOutlookBar()
{
    // create Imagelist
	m_ImageList.Create(32, 32, ILC_COLOR16|ILC_MASK,1, 4);

    HICON hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LOG));
    m_ImageList.Add(hIcon);
    hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ONLINE_USERS));
    m_ImageList.Add(hIcon);
    hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CONFIGURATION));
    m_ImageList.Add(hIcon);
    hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_STATISTICS));
    m_ImageList.Add(hIcon);
    hIcon = ::LoadIcon (AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SECURITY));
    m_ImageList.Add(hIcon);
	
	m_OutlookBar.SetImageList(&m_ImageList, LVSIL_NORMAL);

	CRect rc;
	m_OutlookBar.GetClientRect(rc);
	
	// set new icon spacing
	m_OutlookBar.SetIconSpacing(rc.Width(), 64);

	// change colors
	m_OutlookBar.SetTextColor(RGB(255,255,255));
	m_OutlookBar.SetTextBkColor(RGB(128,128,128));
	m_OutlookBar.SetBkColor(RGB(128,128,128));	

	// insert items
	m_OutlookBar.InsertColumn(0, "OutlookBar");

	m_OutlookBar.InsertItem(0, "Server Log", 0);
	m_OutlookBar.InsertItem(1, "Online Users", 1);
	m_OutlookBar.InsertItem(2, "Configuration", 2);
	m_OutlookBar.InsertItem(3, "Statistics", 3);
	m_OutlookBar.InsertItem(4, "Security", 4);

//	m_OutlookBar.SetExtendedStyle(LVS_EX_TRACKSELECT);
}


/********************************************************************/
/*																	*/
/* Function name : CApplicationDlg::MoveChilds						*/		
/* Description   : Move child windows into place holder area.		*/
/*																	*/
/********************************************************************/
void CApplicationDlg::MoveChilds()
{
	// position property pages 
	CRect rcDlgs;
	
	// get dialog area rect
	GetDlgItem(IDC_DIALOG_AREA)->GetWindowRect(rcDlgs);
	
	ScreenToClient(rcDlgs);
	
	m_ConfigurationPage.MoveWindow(rcDlgs); 
	m_TracePage.MoveWindow(rcDlgs); 
	m_OnlineUsersPage.MoveWindow(rcDlgs); 
	m_StatisticsPage.MoveWindow(rcDlgs); 
	m_SecurityPage.MoveWindow(rcDlgs); 
}


/********************************************************************/
/*																	*/
/* Function name : CApplicationDlg::ActivatePage					*/
/* Description   : Called when an icon on the outlookbar is pressed.*/
/*																	*/
/********************************************************************/
void CApplicationDlg::ActivatePage(int nIndex)
{
	switch(nIndex)
	{
		case 0:
			m_OnlineUsersPage.ShowWindow(SW_HIDE);	
			m_ConfigurationPage.ShowWindow(SW_HIDE);
			m_StatisticsPage.ShowWindow(SW_HIDE);	
			m_SecurityPage.ShowWindow(SW_HIDE);	
			m_TracePage.ShowWindow(SW_SHOW);
			m_InfobarCtrl.SetText("Server Log");
			break;
		case 1:
			m_TracePage.ShowWindow(SW_HIDE);	
			m_ConfigurationPage.ShowWindow(SW_HIDE);	
			m_StatisticsPage.ShowWindow(SW_HIDE);	
			m_SecurityPage.ShowWindow(SW_HIDE);	
			m_OnlineUsersPage.ShowWindow(SW_SHOW);
			m_InfobarCtrl.SetText("Online Users");
			break;
		case 2:
			m_OnlineUsersPage.ShowWindow(SW_HIDE);	
			m_TracePage.ShowWindow(SW_HIDE);	
			m_StatisticsPage.ShowWindow(SW_HIDE);	
			m_SecurityPage.ShowWindow(SW_HIDE);	
			m_ConfigurationPage.ShowWindow(SW_SHOW);	
			m_InfobarCtrl.SetText("Configuration");
			break;
		case 3:
			m_OnlineUsersPage.ShowWindow(SW_HIDE);	
			m_TracePage.ShowWindow(SW_HIDE);	
			m_ConfigurationPage.ShowWindow(SW_HIDE);	
			m_SecurityPage.ShowWindow(SW_HIDE);	
			m_StatisticsPage.ShowWindow(SW_SHOW);	
			m_InfobarCtrl.SetText("Statistics");
			break;
		case 4:
			m_OnlineUsersPage.ShowWindow(SW_HIDE);	
			m_TracePage.ShowWindow(SW_HIDE);	
			m_ConfigurationPage.ShowWindow(SW_HIDE);	
			m_SecurityPage.ShowWindow(SW_SHOW);	
			m_StatisticsPage.ShowWindow(SW_HIDE);	
			m_InfobarCtrl.SetText("Security");
			break;
		default:
			break;
	}
	MoveChilds();
}


/********************************************************************/
/*																	*/
/* Function name : CApplicationDlg::OnClickOutlookBar				*/
/* Description   : User clicked on our listview -> activate page.	*/
/*																	*/
/********************************************************************/
void CApplicationDlg::OnClickOutlookBar(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// get index of selected item
	int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
    
    if(nIndex == -1)
        return;
		
	ActivatePage(nIndex);

	*pResult = 0;
}


/********************************************************************/
/*																	*/
/* Function name : CApplicationDlg::OnKeydownOutlookBar				*/
/* Description   : User pressed a key -> activate page.				*/
/*																	*/
/********************************************************************/
void CApplicationDlg::OnKeydownOutlookBar(NMHDR* pNMHDR, LRESULT* pResult) 
{
	LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;

    // get index of selected item
	int nIndex = m_OutlookBar.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED); 
    
    if(nIndex == -1)
        return;

	if (pLVKeyDow->wVKey == VK_DOWN)
	{
		if (m_OutlookBar.GetItemCount()-1 > nIndex)
		{
			ActivatePage(nIndex+1);
		}
	}
	else
	if (pLVKeyDow->wVKey == VK_UP)
	{
		if (nIndex > 0)
		{
			ActivatePage(nIndex-1);
		}
	}
	else
	if (pLVKeyDow->wVKey == VK_NEXT)
	{
		ActivatePage(m_OutlookBar.GetItemCount()-1);
	}
	else
	if (pLVKeyDow->wVKey == VK_PRIOR)
	{
		ActivatePage(0);
	}

	*pResult = 0;
}



/********************************************************************/
/*																	*/
/* Function name : CreateStatusbar									*/	
/* Description   : This function creates a statusbar on a dialogbox.*/
/*																	*/
/********************************************************************/
BOOL CApplicationDlg::CreateStatusbar()
{
	// Create the Toolbar and attach the resource
	if(!m_wndToolBar.Create(this) || !m_wndToolBar.LoadToolBar(IDR_TOOLBAR1))
	{
		TRACE0("Failed to Create Dialog Toolbar\n");
		return FALSE;	
	}

	m_wndToolBar.SetBarStyle(m_wndToolBar.GetBarStyle() | CBRS_SIZE_DYNAMIC | CBRS_TOOLTIPS | CBRS_FLYBY);
	
	// Make it flat.
	m_wndToolBar.ModifyStyle(0, m_wndToolBar.GetStyle()|TBSTYLE_FLAT);

	// Create status bar at the bottom of the dialog window
	if (m_wndStatusBar.Create(this))
	{
		m_wndStatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar)/sizeof(UINT));
		
		m_wndStatusBar.SetPaneText(0, "FTP Server is offline", TRUE);
		// Make a sunken or recessed border around the first pane
		m_wndStatusBar.SetPaneInfo(0, m_wndStatusBar.GetItemID(0), SBPS_STRETCH, NULL );

		SetOnlineLed(FALSE);
		SetOfflineLed(FALSE);

		m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED),ID_INDICATOR_ONLINELED, SBPS_NOBORDERS, 14);
//		m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_ONLINELED), "This status light is green when the server is online");

		m_wndStatusBar.SetPaneInfo(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED),ID_INDICATOR_OFFLINELED, SBPS_NOBORDERS, 14);
//		m_wndStatusBar.GetStatusBarCtrl().SetTipText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_OFFLINELED), "This status light is green when the server is online");
	}

    // We need to resize the dialog to make room for control bars.
	// First, figure out how big the control bars are.
	CRect rcClientStart;
	CRect rcClientNow;
	GetClientRect(rcClientStart);
	RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);

    // Now move all the controls so they are in the same relative
	// position within the remaining client area as they would be
	// with no control bars.
	CPoint ptOffset(rcClientNow.left - rcClientStart.left, rcClientNow.top - rcClientStart.top); 

	CRect  rcChild;					
	CWnd* pwndChild = GetWindow(GW_CHILD);
	while (pwndChild)
	{                               
		pwndChild->GetWindowRect(rcChild);
		ScreenToClient(rcChild);
		rcChild.OffsetRect(ptOffset);
		pwndChild->MoveWindow(rcChild, FALSE);
		pwndChild = pwndChild->GetNextWindow();
	}

	// Adjust the dialog window dimensions
	CRect rcWindow;
	GetWindowRect(rcWindow);
	rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
	rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
	MoveWindow(rcWindow, FALSE);
	
	// And position the control bars
	RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
    return TRUE;
}


/********************************************************************/
/*																	*/
/* Function name : OnUserAccounts									*/		
/* Description   : Show user accounts.								*/	
/*																	*/
/********************************************************************/
void CApplicationDlg::OnUserAccounts() 
{
	CUserAccountsDlg dlg;

	theServer.m_UserManager.GetUserList(dlg.m_UserArray);
	if (dlg.DoModal() == IDOK)
	{
		theServer.m_UserManager.UpdateUserList(dlg.m_UserArray);
	}
}


/********************************************************************/
/*																	*/
/* Function name : OnFTPUserConnected								*/
/* Description   : A user has connected to our server.				*/
/*																	*/
/********************************************************************/
void CApplicationDlg::OnFTPUserConnected(DWORD nThreadID, LPCTSTR lpszUser, LPCSTR lpszAddress)
{
	m_OnlineUsersPage.AddUser(nThreadID, lpszUser, lpszAddress);
}


/********************************************************************/
/*																	*/
/* Function name : OnFTPUserDisconnected							*/
/* Description   : A user has disconnected from our server.			*/
/*																	*/
/********************************************************************/
void CApplicationDlg::OnFTPUserDisconnected(DWORD nThreadID, LPCTSTR lpszUser)
{
	m_OnlineUsersPage.RemoveUser(nThreadID);
}


/********************************************************************/
/*																	*/
/* Function name : OnFTPStatusChange								*/		
/* Description   : FTP Status changed.								*/	
/*																	*/
/********************************************************************/
void CApplicationDlg::OnFTPStatusChange(int nType, LPCTSTR lpszText)
{
	m_TracePage.AddTraceLine(nType, lpszText);
	
	switch(nType)
	{
		case 3:
			theApp.m_LogFile << error_lvl << date << time << lpszText << endl;
			break;
		default:
			theApp.m_LogFile << trace_lvl << date << time << lpszText << endl;
			break;
	}
}


/********************************************************************/
/*																	*/
/* Function name : OnFTPReceivedBytesChange							*/		
/* Description   : Number of received bytes has changed.			*/	
/*																	*/
/********************************************************************/
void CApplicationDlg::OnFTPReceivedBytesChange(int nBytes) 
{
	m_StatisticsPage.SetValue(6, FormatSize(nBytes, 0));

	CString strStatus;
	strStatus.Format("%s received", FormatSize(nBytes, 0));
	m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_DATA_RECEIVED), strStatus, TRUE);

	CClientDC dc(this);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -