📄 weiqiserverdlg.cpp
字号:
// WeiQiServerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "WeiQiServer.h"
#include "WeiQiServerDlg.h"
#include "ClientSocket.h"
#include "Server.h"
#include "Game.h"
#include "Player.h"
#include "Top10Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CWeiQiServerDlg dialog
CWeiQiServerDlg::CWeiQiServerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWeiQiServerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWeiQiServerDlg)
m_Port = 829;
m_GameNum = 0;
m_RegNum = 0;
m_ClientNum = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_pServer=new CServer(this);
}
void CWeiQiServerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWeiQiServerDlg)
DDX_Control(pDX, IDC_LIST_PLAYER, m_PlayerList);
DDX_Control(pDX, IDC_LIST_GAME, m_GameList);
DDX_Text(pDX, IDC_EDIT_PORT, m_Port);
DDX_Text(pDX, IDC_EDIT_GAMENUM, m_GameNum);
DDX_Text(pDX, IDC_EDIT_REGNUM, m_RegNum);
DDX_Text(pDX, IDC_EDIT_PERSONNUM, m_ClientNum);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWeiQiServerDlg, CDialog)
//{{AFX_MSG_MAP(CWeiQiServerDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
ON_BN_CLICKED(IDC_BUTTON_INFO, OnButtonInfo)
ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
ON_BN_CLICKED(IDC_BUTTON_SHUTDOWN, OnButtonShutdown)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON_TOP10, OnButtonTop10)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWeiQiServerDlg message handlers
BOOL CWeiQiServerDlg::OnInitDialog()
{
CDialog::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);
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);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
ExtendDlg(IDC_SEPARATE,FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CWeiQiServerDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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.
void CWeiQiServerDlg::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
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CWeiQiServerDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CWeiQiServerDlg::OnButtonStart()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_pServer->m_Port=m_Port;
m_pServer->StartServer();
}
void CWeiQiServerDlg::OnButtonInfo()
{
// TODO: Add your control notification handler code here
static BOOL Expand = TRUE;
ExtendDlg(IDC_SEPARATE,Expand);
Expand=!Expand;
}
void CWeiQiServerDlg::ExtendDlg(int nResourceID, BOOL bExpand)
{
static CRect rcLarge;
static CRect rcSmall;
CString sExpand;
if(rcLarge.IsRectNull())
{
CRect rcLandmark;
CWnd* pWndLandmark=GetDlgItem(nResourceID);
GetWindowRect(rcLarge);
pWndLandmark->GetWindowRect(rcLandmark);
rcSmall=rcLarge;
rcSmall.right=rcLandmark.left;
}
if(bExpand)
{
SetWindowPos(NULL,0,0,rcLarge.Width(),rcLarge.Height(),
SWP_NOMOVE|SWP_NOZORDER);
sExpand=_T("关闭信息");
EnableVisibleChildren();
}
else
{
SetWindowPos(NULL,0,0,rcSmall.Width(),rcSmall.Height(),
SWP_NOMOVE|SWP_NOZORDER);
sExpand=_T("更多信息");
EnableVisibleChildren();
}
SetDlgItemText(IDC_BUTTON_INFO,sExpand);
}
void CWeiQiServerDlg::EnableVisibleChildren()
{
CWnd* pWndCtrl=GetWindow(GW_CHILD);
CRect rcRest;
CRect rcControl;
CRect rcShow;
GetWindowRect(rcShow);
while(pWndCtrl!=NULL)
{
pWndCtrl->GetWindowRect(rcControl);
if(rcRest.IntersectRect(rcShow,rcControl))
pWndCtrl->EnableWindow(TRUE);
else
pWndCtrl->EnableWindow(FALSE);
pWndCtrl=pWndCtrl->GetWindow(GW_HWNDNEXT);
}
}
void CWeiQiServerDlg::OnButtonExit()
{
// TODO: Add your control notification handler code here
OnOK();
}
void CWeiQiServerDlg::OnButtonShutdown()
{
// TODO: Add your control notification handler code here
m_pServer->ShutDownServer();
}
void CWeiQiServerDlg::FlashGame()
{
m_GameList.ResetContent();
POSITION p=m_pServer->m_GameList.GetHeadPosition();
int n=m_pServer->m_GameList.GetCount();
for(int i=0;i<n;i++)
m_GameList.AddString(((CGame*)m_pServer->m_GameList.GetNext(p))->m_GameName);
}
void CWeiQiServerDlg::FlashPlayer()
{
m_PlayerList.ResetContent();
POSITION p=m_pServer->m_LogInList.GetHeadPosition();
int n=m_pServer->m_LogInList.GetCount();
for(int i=0;i<n;i++)
m_PlayerList.AddString(((CClientSocket*)m_pServer->m_LogInList.GetNext(p))->m_pPlayer->m_PlayerName);
}
void CWeiQiServerDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
m_pServer->ShutDownServer();
}
void CWeiQiServerDlg::OnButtonTop10()
{
// TODO: Add your control notification handler code here
CTop10Dlg dlg(m_pServer);
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -