📄 bubbleserverdlg.cpp
字号:
// BubbleServerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "BubbleServer.h"
#include "BubbleServerDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static UINT auIDStatusBar[] =
{
ID_SEPARATOR,
ID_INDICATOR_DATA_RECEIVED,
ID_INDICATOR_DATA_SEND,
ID_INDICATOR_ONLINELED,
ID_INDICATOR_OFFLINELED
};
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBubbleServerDlg dialog
CBubbleServerDlg::CBubbleServerDlg(CWnd* pParent /*=NULL*/)
: CDialogResize(CBubbleServerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBubbleServerDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_bInitialized = FALSE;
}
void CBubbleServerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogResize::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBubbleServerDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
DDX_Control(pDX, IDC_INFOBAR, m_InfobarCtrl);
DDX_Control(pDX, IDC_OUTLOOKBAR, m_OutlookBar);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBubbleServerDlg, CDialogResize)
//{{AFX_MSG_MAP(CBubbleServerDlg)
ON_WM_SYSCOMMAND()
ON_WM_SIZE()
ON_WM_DESTROY()
ON_COMMAND(ID_SERVER_START, OnServerStart)
ON_UPDATE_COMMAND_UI(ID_SERVER_START, OnBubbleServerStart)
ON_COMMAND(ID_SERVER_STOP, OnServerStop)
ON_UPDATE_COMMAND_UI(ID_SERVER_STOP, OnBubbleServerStop)
ON_COMMAND(ID_SERVER_EXIT, OnServerExit)
ON_NOTIFY(NM_CLICK, IDC_OUTLOOKBAR, OnClickOutlookBar)
ON_NOTIFY(LVN_KEYDOWN, IDC_OUTLOOKBAR, OnKeydownOutlookBar)
ON_COMMAND(ID_USER_ACCOUNTS, OnUserAccounts)
ON_WM_CLOSE()
ON_COMMAND(IDC_VIEW_TRACE, OnViewTrace)
ON_COMMAND(IDC_VIEW_ONLINE_USERS, OnViewOnlineUsers)
ON_COMMAND(IDC_VIEW_CONFIGURATION, OnViewConfiguration)
ON_UPDATE_COMMAND_UI(IDC_VIEW_TRACE, OnUpdateViewTrace)
ON_UPDATE_COMMAND_UI(IDC_VIEW_ONLINE_USERS, OnUpdateViewOnlineUsers)
ON_UPDATE_COMMAND_UI(IDC_VIEW_CONFIGURATION, OnUpdateViewConfiguration)
ON_COMMAND(ID_HELP_ABOUT, OnHelpAbout)
ON_COMMAND(IDC_VIEW_STATISTICS, OnViewStatistics)
ON_UPDATE_COMMAND_UI(IDC_VIEW_STATISTICS, OnUpdateViewStatistics)
ON_COMMAND(IDC_VIEW_SECURITY, OnViewSecurity)
ON_UPDATE_COMMAND_UI(IDC_VIEW_SECURITY, OnUpdateViewSecurity)
ON_COMMAND(ID_ACCOUNT_WIZARD, OnAccountWizard)
ON_WM_TIMER()
ON_COMMAND(IDC_VIEW_FILEGROUP, OnViewFilegroup)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipText)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipText)
ON_COMMAND(IDC_APPLY, OnApply)
END_MESSAGE_MAP()
BEGIN_DLGRESIZE_MAP(CBubbleServerDlg)
DLGRESIZE_CONTROL(IDC_OUTLOOKBAR, DLSZ_SIZE_Y)
DLGRESIZE_CONTROL(IDC_DIALOG_AREA, DLSZ_SIZE_X | DLSZ_SIZE_Y)
DLGRESIZE_CONTROL(AFX_IDW_STATUS_BAR, DLSZ_MOVE_Y | DLSZ_SIZE_X)
DLGRESIZE_CONTROL(AFX_IDW_TOOLBAR, DLSZ_SIZE_X)
DLGRESIZE_CONTROL(IDC_STATIC1, DLSZ_SIZE_X)
DLGRESIZE_CONTROL(IDC_INFOBAR, DLSZ_SIZE_X)
END_DLGRESIZE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBubbleServerDlg message handlers
BOOL CBubbleServerDlg::OnInitDialog()
{
CDialogResize::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
m_hIcon = AfxGetApp()->LoadIcon(IDI_SERVER);
// setup listview ctrl, so that it looks like the outbar control
SetupOutlookBar();
// Add statusbar to the dialog
CreateStatusbar();
CRect rect;
GetDlgItem(IDC_STATIC1)->GetWindowRect(rect);
ScreenToClient(rect);
rect.right+=4;
GetDlgItem(IDC_STATIC1)->MoveWindow(rect);
InitResizing(FALSE);
int s, t, b, r, l;
if (AfxGetApp()->GetProfileInt("Settings", "SavePosition", 1))
{
// only restore if there is a previously saved position
if ( -1 != (s = AfxGetApp()->GetProfileInt("Settings", "FrameStatus", -1)) &&
-1 != (t = AfxGetApp()->GetProfileInt("Settings", "FrameTop", -1)) &&
-1 != (l = AfxGetApp()->GetProfileInt("Settings", "FrameLeft", -1)) &&
-1 != (b = AfxGetApp()->GetProfileInt("Settings", "FrameBottom", -1)) &&
-1 != (r = AfxGetApp()->GetProfileInt("Settings", "FrameRight", -1))
)
{
WINDOWPLACEMENT wp;
// restore the window's status
wp.showCmd = s;
// restore the window's width and height
wp.rcNormalPosition.bottom = b;
wp.rcNormalPosition.right = r;
// the following correction is needed when the taskbar is
// at the left or top and it is not "auto-hidden"
RECT workArea;
SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
l += workArea.left;
t += workArea.top;
// make sure the window is not completely out of sight
int max_x = GetSystemMetrics(SM_CXSCREEN) -
GetSystemMetrics(SM_CXICON);
int max_y = GetSystemMetrics(SM_CYSCREEN) -
GetSystemMetrics(SM_CYICON);
wp.rcNormalPosition.top = min(t, max_y);
wp.rcNormalPosition.left = min(l, max_x);
SetWindowPlacement(&wp);
}
}
// create property pages
m_TracePage.Create(IDD_PROPPAGE_TRACE, this);
m_OnlineUsersPage.Create(IDD_PROPPAGE_ONLINE, this);
m_ConfigurationPage.Create(IDD_PROPPAGE_CONFIGURATION, this);
m_StatisticsPage.Create(IDD_PROPPAGE_STATISTICS, this);
m_SecurityPage.Create(IDD_PROPPAGE_SECURITY, this);
// m_file_group_page.Create(IDD_PROPPAGE_FILE_GROUP, this);
// activate main page
ActivatePage(0);
// Set the icon for this dialog.
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// get registry values
m_ConfigurationPage.m_nPort = AfxGetApp()->GetProfileInt("Settings", "Port", 21);
m_ConfigurationPage.m_nMaxUsers = AfxGetApp()->GetProfileInt("Settings", "MaxUsers", 10);
m_ConfigurationPage.m_nTimeout = AfxGetApp()->GetProfileInt("Settings", "Timeout", 5);
m_ConfigurationPage.m_strWelcomeMessage = AfxGetApp()->GetProfileString("Settings", "WelcomeMsg", "Welcome to Bubble Server");
m_ConfigurationPage.m_strGoodbyeMessage = AfxGetApp()->GetProfileString("Settings", "GoodbyeMsg", "Bye");
m_ConfigurationPage.m_bLaunchOnStartup = AfxGetApp()->GetProfileInt("Settings", "LaunchOnStartup", 0);
m_ConfigurationPage.m_bStartInTray = AfxGetApp()->GetProfileInt("Settings", "StartInTray", 0);
m_ConfigurationPage.m_bAutoActivate = AfxGetApp()->GetProfileInt("Settings", "AutoActivate", TRUE);
m_ConfigurationPage.m_nLogLevel = AfxGetApp()->GetProfileInt("Settings", "LogLevel", 1);
m_ConfigurationPage.m_strApplicationName = AfxGetApp()->GetProfileString("Settings", "AppName", "Bubble Server");
m_ConfigurationPage.UpdateData(FALSE);
SetWindowText(m_ConfigurationPage.m_strApplicationName);
// set log level
// theApp.m_LogFile.SetLogLevel(m_ConfigurationPage.m_nLogLevel);
// and finally, let's add some tooltips
m_ToolTipCtrl.Create(this);
m_ToolTipCtrl.Activate(TRUE);
// minimize at startup ?
if (m_ConfigurationPage.m_bStartInTray)
{
PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
// this seems to be a workaround to let the statement above to get working
CRect rect;
GetWindowRect(rect);
SetWindowPos(&CWnd::wndTop, rect.left, rect.top, rect.Width(), rect.Height(), SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE);
}
// theServer.Initialize(this);
if (m_ConfigurationPage.m_bAutoActivate)
{
OnServerStart();
}
m_bInitialized = TRUE;
return TRUE;
}
void CBubbleServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
//void CBubbleServerDlg::OnPaint()
//{
// if (IsIconic())
// {
// CPaintDC dc(this); // device context for painting
//
// SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
//
// // Center icon in client rectangle
// int cxIcon = GetSystemMetrics(SM_CXICON);
// int cyIcon = GetSystemMetrics(SM_CYICON);
// CRect rect;
// GetClientRect(&rect);
// int x = (rect.Width() - cxIcon + 1) / 2;
// int y = (rect.Height() - cyIcon + 1) / 2;
//
// // Draw the icon
// dc.DrawIcon(x, y, m_hIcon);
// }
// else
// {
// CDialogResize::OnPaint();
// }
//}
//
//// The system calls this to obtain the cursor to display while the user drags
//// the minimized window.
//HCURSOR CBubbleServerDlg::OnQueryDragIcon()
//{
// return (HCURSOR) m_hIcon;
//}
/********************************************************************/
/* */
/* Function name : OnSize */
/* Description : Handle WM_SIZE message */
/* */
/********************************************************************/
void CBubbleServerDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogResize::OnSize(nType, cx, cy);
if (m_bInitialized)
MoveChilds();
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
/********************************************************************/
/* */
/* Function name : OnClose */
/* Description : Hide the dialogbox (instead of closing it) */
/* */
/********************************************************************/
void CBubbleServerDlg::OnClose()
{
if (AfxGetApp()->GetProfileInt("Settings", "SavePosition", 1))
{
// Save main window position
WINDOWPLACEMENT wp;
GetWindowPlacement(&wp);
AfxGetApp()->WriteProfileInt("Settings", "FrameStatus", wp.showCmd);
AfxGetApp()->WriteProfileInt("Settings", "FrameTop", wp.rcNormalPosition.top);
AfxGetApp()->WriteProfileInt("Settings", "FrameLeft", wp.rcNormalPosition.left);
AfxGetApp()->WriteProfileInt("Settings", "FrameBottom", wp.rcNormalPosition.bottom);
AfxGetApp()->WriteProfileInt("Settings", "FrameRight", wp.rcNormalPosition.right);
}
CDialog::OnClose();
}
/********************************************************************/
/* */
/* Function name : OnDestroy */
/* Description : Handle WM_DESTROY message */
/* */
/********************************************************************/
void CBubbleServerDlg::OnDestroy()
{
// OnServerStop();
CDialogResize::OnDestroy();
}
/********************************************************************/
/* */
/* Function name : OnServerStart */
/* Description : Start FTP server -> start listening on port 21 */
/* */
/********************************************************************/
void CBubbleServerDlg::OnServerStart()
{
// m_ConfigurationPage.UpdateData();
// theServer.SetPort(m_ConfigurationPage.m_nPort);
// theServer.SetMaxUsers(m_ConfigurationPage.m_nMaxUsers);
// theServer.SetTimeout(m_ConfigurationPage.m_nTimeout);
// theServer.SetWelcomeMessage(m_ConfigurationPage.m_strWelcomeMessage);
// theServer.SetGoodbyeMessage(m_ConfigurationPage.m_strGoodbyeMessage);
// theServer.SetStatisticsInterval(5000);
// BOOL bBlockAll = AfxGetApp()->GetProfileInt("Settings", "BlockAll", 0);
// theServer.SetSecurityMode(!bBlockAll);
//char strPath[MAX_PATH];
//GetCurrentDirectory(MAX_PATH, strPath);
//InitServer(strPath, "");
if(FALSE==StartServer())
return;
SetTimer(TIMER_LOOP, 30, NULL);
// if (theServer.Start())
// {
m_wndStatusBar.SetPaneText(0, "Bubble Server is online", TRUE);
SetOnlineLed(TRUE);
SetOfflineLed(FALSE);
// }
}
/********************************************************************/
/* */
/* Function name : OnBubbleServerStart */
/* Description : Update 'Start' status */
/* */
/********************************************************************/
void CBubbleServerDlg::OnBubbleServerStart(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!IsActive());
}
/********************************************************************/
/* */
/* Function name : OnServerStop */
/* Description : Stop FTP server */
/* */
/********************************************************************/
void CBubbleServerDlg::OnServerStop()
{
// theServer.Stop();
StopServer();
KillTimer(TIMER_LOOP);
m_wndStatusBar.SetPaneText(0, "Bubble Server is offline", TRUE);
SetOnlineLed(FALSE);
SetOfflineLed(TRUE);
}
/********************************************************************/
/* */
/* Function name : OnBubbleServerStop */
/* Description : Update 'Stop' status */
/* */
/********************************************************************/
void CBubbleServerDlg::OnBubbleServerStop(CCmdUI* pCmdUI)
{
pCmdUI->Enable(IsActive());
}
/********************************************************************/
/* */
/* Function name : OnKickIdle */
/* Description : Make ON_UPDATE_COMMAND_UI work for this dialog. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -