?? fullserverwithrmtmonitordemodlg.cpp
字號:
// fullServerWithRmtMonitorDemoDlg.cpp : 實現文件
//
#include "stdafx.h"
#include "fullServerWithRmtMonitorDemo.h"
#include "fullServerWithRmtMonitorDemoDlg.h"
#include ".\fullserverwithrmtmonitordemodlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 用于應用程序“關于”菜單項的 CAboutDlg 對話框
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// 對話框數據
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 實現
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CfullServerWithRmtMonitorDemoDlg 對話框
CfullServerWithRmtMonitorDemoDlg::CfullServerWithRmtMonitorDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CfullServerWithRmtMonitorDemoDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CfullServerWithRmtMonitorDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_MSG, m_tabMsgList);
}
BEGIN_MESSAGE_MAP(CfullServerWithRmtMonitorDemoDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_NOTIFY(TCN_SELCHANGE, IDC_MSG, OnTcnSelchangeMsg)
ON_BN_CLICKED(IDC_START_SVR, OnBnClickedStartSvr)
ON_BN_CLICKED(IDC_STOP_SVR, OnBnClickedStopSvr)
ON_BN_CLICKED(IDC_PAUSE_SVR, OnBnClickedPauseSvr)
ON_BN_CLICKED(IDC_SVR_STATE, OnBnClickedSvrState)
ON_BN_CLICKED(IDC_EXIT_NOW, OnBnClickedExitNow)
ON_BN_CLICKED(IDC_RESMUE_SVR, OnBnClickedResmueSvr)
END_MESSAGE_MAP()
// CfullServerWithRmtMonitorDemoDlg 消息處理程序
BOOL CfullServerWithRmtMonitorDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 將\“關于...\”菜單項添加到系統菜單中。
// IDM_ABOUTBOX 必須在系統命令范圍內。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 設置此對話框的圖標。當應用程序主窗口不是對話框時,框架將自動
// 執行此操作
SetIcon(m_hIcon, TRUE); // 設置大圖標
SetIcon(m_hIcon, FALSE); // 設置小圖標
// TODO: 在此添加額外的初始化代碼
m_tabMsgList.InsertItem(0,"所有信息");
m_tabMsgList.InsertItem(1,"錯誤信息");
CRect rcW;
m_tabMsgList.GetWindowRect(rcW);
rcW.top+= 25;
rcW.bottom-=5;
rcW.left+=5;
rcW.right-=5;
ScreenToClient(rcW);
m_wndShowAll.CreateChildWnd(0,this,"all",rcW,10090+1,4,90,80,40);
m_conAll.SetBufferWnd(&m_wndShowAll);
m_wndShowError.CreateChildWnd(0,this,"all",rcW,10090+2,4,90,80,40);
m_conError.SetBufferWnd(&m_wndShowError);
SetBufferWndShow();
m_outputDemo.SetOutputWnd(&m_conAll, &m_conError);
return TRUE; // 除非設置了控件的焦點,否則返回 TRUE
}
void CfullServerWithRmtMonitorDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 如果向對話框添加最小化按鈕,則需要下面的代碼
// 來繪制該圖標。對于使用文檔/視圖模型的 MFC 應用程序,
// 這將由框架自動完成。
void CfullServerWithRmtMonitorDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于繪制的設備上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使圖標在工作矩形中居中
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;
// 繪制圖標
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//當用戶拖動最小化窗口時系統調用此函數取得光標顯示。
HCURSOR CfullServerWithRmtMonitorDemoDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CfullServerWithRmtMonitorDemoDlg::SetBufferWndShow(void)
{
int iSel = m_tabMsgList.GetCurSel();
if(iSel ==0)
{
m_wndShowAll.ShowWindow(SW_SHOW);
m_wndShowError.ShowWindow(SW_HIDE);
}
else if(iSel ==1)
{
m_wndShowAll.ShowWindow(SW_HIDE);
m_wndShowError.ShowWindow(SW_SHOW);
}
}
void CfullServerWithRmtMonitorDemoDlg::OnTcnSelchangeMsg(NMHDR *pNMHDR, LRESULT *pResult)
{
int iSel = m_tabMsgList.GetCurSel();
TRACE("cur sel=%d\n",iSel);
*pResult = 0;
SetBufferWndShow();
}
DWORD __stdcall CfullServerWithRmtMonitorDemoDlg::StartServersThread(LPVOID pObj)
{
CfullServerWithRmtMonitorDemoDlg* pThis = (CfullServerWithRmtMonitorDemoDlg*)pObj;
pThis->EnableButtons();
pThis->m_outputDemo.PutLine(COutputDemo::Message,"開始設置參數");
pThis->m_svrDemo.InitServerName("TCP_Svr_with_Rmt_Monitor_DEMO");
pThis->m_svrDemo.InitOutput(&pThis->m_outputDemo);
pThis->m_svrDemo.InitSocketServerNetPara(NULL,13601);
pThis->m_svrDemo.InitMonitorServerNetPara(NULL,13602);
pThis->m_svrDemo.InitSocketServerCallback(TCPSocketServerCallBack);
pThis->m_svrDemo.InitMonitorServerCallback(RmtCallBack);
pThis->m_outputDemo.PutLine(COutputDemo::Message,"設置參數完成");
pThis->m_outputDemo.PutLine(COutputDemo::Message,"開始啟動服務");
BOOL fOK = pThis->m_svrDemo.StartServers();
pThis->m_outputDemo.PutLine(COutputDemo::Message,(fOK)?"啟動服務成功":"啟動服務失敗");
pThis->m_outputDemo.PutLine(COutputDemo::Message,"-*-*-*-*-*-*-*-*-*-*-*-*-");
pThis->m_outputDemo.SetRmtMonitor(pThis->m_svrDemo.GetRemoteMonitorManager());
pThis->EnableButtons(1,1,1,1,1);
return 0;
}
DWORD __stdcall CfullServerWithRmtMonitorDemoDlg::StopServersThread(LPVOID pObj)
{
CfullServerWithRmtMonitorDemoDlg* pThis = (CfullServerWithRmtMonitorDemoDlg*)pObj;
pThis->EnableButtons();
BOOL fOK = pThis->m_svrDemo.StopServers();
pThis->m_outputDemo.PutLine(COutputDemo::Message,(fOK)?"停止服務成功":"停止服務失敗");
pThis->m_outputDemo.PutLine(COutputDemo::Message,"-*-*-*-*-*-*-*-*-*-*-*-*-");
pThis->EnableButtons(1,1,1,1,1);
return 0;
}
void CfullServerWithRmtMonitorDemoDlg::EnableButtons(BOOL fRun,BOOL fStop,BOOL fPause,BOOL fState,BOOL fQuit)
{
GetDlgItem(IDC_START_SVR)->EnableWindow(fRun);
GetDlgItem(IDC_STOP_SVR)->EnableWindow(fStop);
GetDlgItem(IDC_PAUSE_SVR)->EnableWindow(fPause);
GetDlgItem(IDC_SVR_STATE)->EnableWindow(fState);
GetDlgItem(IDC_EXIT_NOW)->EnableWindow(fQuit);
}
void CfullServerWithRmtMonitorDemoDlg::OnBnClickedStartSvr()
{
DWORD dwS = m_svrDemo.GetServerState();
if(dwS ==0)
{
DWORD dwID;
HANDLE hT = CreateThread(NULL,0,StartServersThread,(LPVOID)this,0,&dwID);
if(hT)
{
CloseHandle(hT);
}
}
else
{
m_outputDemo.PutLine(COutputDemo::GeneralError,"服務已經在運行");
}
}
void CfullServerWithRmtMonitorDemoDlg::OnBnClickedStopSvr()
{
DWORD dwS = m_svrDemo.GetServerState();
if(dwS ==1)
{
m_outputDemo.SetRmtMonitor(NULL);
DWORD dwID;
HANDLE hT = CreateThread(NULL,0,StopServersThread,(LPVOID)this,0,&dwID);
if(hT)
CloseHandle(hT);
}
else
{
m_outputDemo.PutLine(COutputDemo::GeneralError,"服務沒有在運行");
}
}
void CfullServerWithRmtMonitorDemoDlg::OnBnClickedPauseSvr()
{
DWORD dwS = m_svrDemo.GetServerState();
if(dwS ==1)
{
if(m_svrDemo.PauseTCPSocketServer())
m_outputDemo.PutLine(COutputDemo::Success,"TCPSocketServer已經暫停");
else
m_outputDemo.PutLine(COutputDemo::GeneralError,"TCPSocketServer無法暫停,可能是TCPSocketServer服務未啟動");
}
else
{
m_outputDemo.PutLine(COutputDemo::GeneralError,"服務沒有在運行");
}
}
void CfullServerWithRmtMonitorDemoDlg::OnBnClickedResmueSvr()
{
DWORD dwS = m_svrDemo.GetServerState();
if(dwS ==1)
{
if(m_svrDemo.PauseTCPSocketServer())
m_outputDemo.PutLine(COutputDemo::Success,"TCPSocketServer已經恢復");
else
m_outputDemo.PutLine(COutputDemo::GeneralError,"TCPSocketServer無法恢復,可能是TCPSocketServer服務未啟動");
}
else
{
m_outputDemo.PutLine(COutputDemo::GeneralError,"服務沒有在運行");
}
}
void CfullServerWithRmtMonitorDemoDlg::OnBnClickedSvrState()
{
DWORD dwS = m_svrDemo.GetServerState();
CString szOut;
if(dwS==1)
{
char szTState[20]="";
enum CServerStatus::ParentThreadStatus eState = m_svrDemo.GetTCPSocketServerStatus();
CServerStatus::GetParentThreadStatusString(eState,szTState);
szOut.Format("服務正在運行,TCPSocketServer狀態:%s",szTState);
}
else
{
szOut.Format("服務未運行");
}
m_outputDemo.PutLine(COutputDemo::Message,"-*-*-*-*-*-*-*-*-*-*-*-*-");
m_outputDemo.PutLine(COutputDemo::Message,szOut);
m_outputDemo.PutLine(COutputDemo::Message,"-*-*-*-*-*-*-*-*-*-*-*-*-");
}
void CfullServerWithRmtMonitorDemoDlg::OnBnClickedExitNow()
{
DWORD dwS = m_svrDemo.GetServerState();
if(dwS ==1)
{
m_outputDemo.PutLine(COutputDemo::Message,"-*-*-*-*-*-*-*-*-*-*-*-*-");
m_outputDemo.PutLine(COutputDemo::GeneralWarn,"服務在運行時不允許退出,此時退出將會導致資源無法釋放,請先停止服務器運行");
m_outputDemo.PutLine(COutputDemo::Message,"-*-*-*-*-*-*-*-*-*-*-*-*-");
}
else
{
CDialog::OnOK();
}
}
void CfullServerWithRmtMonitorDemoDlg::OnOK()
{
// TODO: 在此添加專用代碼和/或調用基類
return;
// CDialog::OnOK();
}
void CfullServerWithRmtMonitorDemoDlg::OnCancel()
{
// TODO: 在此添加專用代碼和/或調用基類
OnBnClickedExitNow();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -