📄 zhanguoclientdlg.cpp
字号:
// ZhanGuoClientDlg.cpp : 实现文件
//
#include "stdafx.h"
#include "ZhanGuoClient.h"
#include "ZhanGuoClientDlg.h"
#include "LoginDialog.h"
#include "SetDialog.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()
// CZhanGuoClientDlg 对话框
CZhanGuoClientDlg::CZhanGuoClientDlg(CWnd* pParent /*=NULL*/)
: CDialog(CZhanGuoClientDlg::IDD, pParent)
, m_Game(*this)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
//初始化临界区
InitializeCriticalSection(&m_logSC);
InitializeCriticalSection(&m_chtSC);
InitializeCriticalSection(&m_dbgSC);
}
CZhanGuoClientDlg::~CZhanGuoClientDlg()
{
//销毁临界区
DeleteCriticalSection(&m_logSC);
DeleteCriticalSection(&m_chtSC);
DeleteCriticalSection(&m_dbgSC);
}
void CZhanGuoClientDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT1, m_wndSystemLog);
DDX_Control(pDX, IDC_EDIT2, m_wndDebug);
DDX_Control(pDX, IDC_TAB1, m_sheetLeft);
DDX_Control(pDX, IDC_TAB3, m_sheetRight);
DDX_Control(pDX, IDC_TAB2, m_sheetMap);
}
BEGIN_MESSAGE_MAP(CZhanGuoClientDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_COMMAND(ID_LOGIN, &CZhanGuoClientDlg::OnLogin)
ON_COMMAND(ID_SET, &CZhanGuoClientDlg::OnSet)
ON_MESSAGE(WM_ADDLOG,OnAddLog) //系统信息
ON_MESSAGE(WM_DEBUGOUT,OnDebugOut) //调试信息
ON_MESSAGE(WM_ADDCHAT,OnAddChat) //聊天信息
ON_BN_CLICKED(IDC_BUTTON1, &CZhanGuoClientDlg::OnBnClickedButton1)
END_MESSAGE_MAP()
// CZhanGuoClientDlg 消息处理程序
BOOL CZhanGuoClientDlg::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: 在此添加额外的初始化代码
if (!m_wndtoolbar.CreateEx( this,TBSTYLE_FLAT , WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS,
CRect(4,4,0,0)) || !m_wndtoolbar.LoadToolBar(IDR_TOOLBAR1) )
{
TRACE0("failed to create toolbar\n");
return FALSE;
}
m_wndtoolbar.ShowWindow(SW_SHOW);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
//属性页控件相关操作
m_sheetLeft.AddPage("角色", &m_wndSelf, IDD_DLGSELF);
m_sheetLeft.AddPage("装备", &m_wndUseItem, IDD_DLGUSEITEM);
m_sheetLeft.AddPage("背包", &m_wndBag, IDD_DLGBAG);
m_sheetLeft.AddPage("技能", &m_wndMagics, IDD_DLGMAGICS);
m_sheetLeft.AddPage("仓库", &m_wndStore, IDD_DLGSTORE);
m_sheetLeft.Show();
m_sheetRight.AddPage("怪物", &m_WndMonster, IDD_DLGMONSTER);
m_sheetRight.AddPage("玩家", &m_WndActors, IDD_DLGACTORS);
m_sheetRight.AddPage("商人", &m_WndNPC, IDD_DLGNPC);
m_sheetRight.AddPage("地面", &m_WndGround, IDD_DLGGROUND);
m_sheetRight.Show();
m_sheetMap.AddPage("视图", &m_WndMap, IDD_MAPVIEW);
m_sheetMap.AddPage("地图全貌", &m_WndMini, IDD_MAPMINI);
m_sheetMap.Show();
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
void CZhanGuoClientDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CZhanGuoClientDlg::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 CZhanGuoClientDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
///////////////////////////////////////////////////////////////////////
// 函数名字 : OnLogin
// 功能描述 : 登录游戏对话框
// 参数 :
// 返回值 :
///////////////////////////////////////////////////////////////////////
void CZhanGuoClientDlg::OnLogin()
{
// TODO: 在此添加命令处理程序代码
CLoginDialog loginDialog;
if(loginDialog.DoModal()==IDOK)
m_Game.Login(loginDialog.ret_ServerAddress,loginDialog.ret_ServerName,
loginDialog.ret_ServerPort,loginDialog.ret_Account,loginDialog.ret_Password);
}
///////////////////////////////////////////////////////////////////////
// 函数名字 : OnSet
// 功能描述 : 挂机设置对话框
// 参数 :
// 返回值 :
///////////////////////////////////////////////////////////////////////
void CZhanGuoClientDlg::OnSet()
{
// TODO: 在此添加命令处理程序代码
CSetDialog setDialog;
setDialog.DoModal();
}
///////////////////////////////////////////////////////////////////////
// 函数名字 : AddLog
// 功能描述 : 系统信息
// 参数 : COLORREF crFont, const char *pMsg, ...
// 返回值 : void
///////////////////////////////////////////////////////////////////////
void CZhanGuoClientDlg::AddLog( COLORREF crFont, const char *pMsg, ... )
{
static char strbuf[BUFFER_SIZE];
va_list vList;
va_start( vList, pMsg );
vsprintf( strbuf, pMsg, vList );
va_end( vList );
_TLOGITEM *p=new _TLOGITEM;
p->time=CTime::GetCurrentTime();
p->text=strbuf;
p->crFont=crFont;
PostMessage(WM_ADDLOG,0,(LPARAM)p);
}
///////////////////////////////////////////////////////////////////////
// 函数名字 : OnAddLog
// 功能描述 : 编辑框控件--系统信息
// 参数 : WPARAM , LPARAM l
// 返回值 : void
///////////////////////////////////////////////////////////////////////
LRESULT CZhanGuoClientDlg::OnAddLog( WPARAM , LPARAM l )
{
_TLOGITEM *p=(_TLOGITEM*)l;
CRichEditCtrl&edit=m_wndSystemLog;//m_wndSystemLog.m_wndChild;
EnterCriticalSection(&m_logSC);
{
if ( edit.GetLineCount() > 1000 )
edit.SetWindowText("");
long s;
CHARFORMAT cf;
edit.GetDefaultCharFormat( cf );
cf.dwMask |= CFM_COLOR;
cf.crTextColor = crTime;
s = edit.GetTextLength();
edit.SetSel( s, -1 );
edit.SetSelectionCharFormat( cf );
edit.ReplaceSel( p->time.Format( "%H:%M:%S " ) );
edit.GetDefaultCharFormat( cf );
cf.dwMask |= CFM_COLOR;
cf.crTextColor = p->crFont;
s = edit.GetTextLength();
edit.SetSel( s, -1 );
edit.SetSelectionCharFormat( cf );
edit.ReplaceSel( p->text.c_str() );
edit.SendMessage( EM_SCROLL, SB_PAGEDOWN, 0 );
}
LeaveCriticalSection(&m_logSC);
delete p;
return 0;
}
///////////////////////////////////////////////////////////////////////
// 函数名字 : DebugOut
// 功能描述 : 调试信息
// 参数 : const char *pMsg, ..
// 返回值 : void
///////////////////////////////////////////////////////////////////////
void CZhanGuoClientDlg::DebugOut( const char *pMsg, ... )
{
#ifndef PUBLIC_EDTION
_TLOGDEBUG *p=new _TLOGDEBUG;
p->time=CTime::GetCurrentTime();
char strbuf[BUFFER_SIZE];
va_list vList;
va_start( vList, pMsg );
vsprintf( strbuf, pMsg, vList );
va_end( vList );
p->text=strbuf;
PostMessage(WM_DEBUGOUT,0,(LPARAM)p);
#endif // PUBLIC_EDTION
}
///////////////////////////////////////////////////////////////////////
// 函数名字 : OnDebugOut
// 功能描述 : 编辑框控件--调试信息
// 参数 : WPARAM , LPARAM l
// 返回值 : void
///////////////////////////////////////////////////////////////////////
LRESULT CZhanGuoClientDlg::OnDebugOut( WPARAM , LPARAM l )
{
#ifndef PUBLIC_EDTION
_TLOGDEBUG *p=(_TLOGDEBUG*)l;
CRichEditCtrl&edit=m_wndDebug;//m_wndDebug.m_wndChild;
EnterCriticalSection(&m_dbgSC);
{
if ( edit.GetLineCount() > 1000 )
edit.SetWindowText("");
long s;
CHARFORMAT cf;
edit.GetDefaultCharFormat( cf );
cf.dwMask |= CFM_COLOR;
cf.crTextColor = crTime;
s = edit.GetTextLength();
edit.SetSel( s, -1 );
edit.SetSelectionCharFormat( cf );
edit.ReplaceSel( p->time.Format( "%H:%M:%S " ) );
edit.GetDefaultCharFormat( cf );
cf.dwMask |= CFM_COLOR;
cf.crTextColor = crDebug;
s = edit.GetTextLength();
edit.SetSel( s, -1 );
edit.SetSelectionCharFormat( cf );
edit.ReplaceSel( p->text.c_str() );
edit.SendMessage( EM_SCROLL, SB_PAGEDOWN, 0 );
}
LeaveCriticalSection(&m_dbgSC);
delete p;
#endif // PUBLIC_EDTION
return 0;
}
///////////////////////////////////////////////////////////////////////
// 函数名字 : AddChat
// 功能描述 : 聊天信息
// 参数 : LPCTSTR txt, BYTE crFont, BYTE crBack
// 返回值 : void
///////////////////////////////////////////////////////////////////////
void CZhanGuoClientDlg::AddChat( LPCTSTR txt, BYTE crFont, BYTE crBack )
{
_TCHARITEM *p = new _TCHARITEM;
p->time=CTime::GetCurrentTime();
p->text=txt;
p->crFont=MirColorTable[crFont];
p->crBack=MirColorTable[crBack];
PostMessage(WM_ADDCHAT,0,(LPARAM)p);
}
///////////////////////////////////////////////////////////////////////
// 函数名字 : OnAddChat
// 功能描述 : 编辑框控件--聊天信息
// 参数 : WPARAM , LPARAM l
// 返回值 : void
///////////////////////////////////////////////////////////////////////
LRESULT CZhanGuoClientDlg::OnAddChat( WPARAM , LPARAM l )
{
_TCHARITEM *p = (_TCHARITEM*)l;
CRichEditCtrl & edit=m_wndView;//m_wndView->GetRichEditCtrl();
EnterCriticalSection(&m_chtSC);
{
if ( edit.GetLineCount() > 1000 )
edit.SetWindowText("");
long s;
CHARFORMAT2 cf2;
ZeroMemory(&cf2,sizeof(CHARFORMAT2));
edit.GetDefaultCharFormat(cf2);
cf2.dwMask|=CFM_COLOR;
cf2.crTextColor=crTime;
s=edit.GetTextLength();
edit.SetSel(s,-1);
edit.SetSelectionCharFormat(cf2);
edit.ReplaceSel(p->time.Format("%H:%M:%S "));
ZeroMemory(&cf2,sizeof(CHARFORMAT2));
edit.GetDefaultCharFormat(cf2);
cf2.dwMask|=CFM_COLOR|CFM_BACKCOLOR;
cf2.dwEffects&=~CFE_AUTOBACKCOLOR;
cf2.crBackColor=p->crBack;
cf2.crTextColor=p->crFont;
s=edit.GetTextLength();
edit.SetSel(s,-1);
edit.SetSelectionCharFormat(cf2);
edit.ReplaceSel(p->text.c_str());
edit.SendMessage(EM_SCROLL,SB_PAGEDOWN,0);
}
LeaveCriticalSection(&m_chtSC);
delete p;
return 0;
}
//测试按钮
void CZhanGuoClientDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
AddLog(crGreen,"半月开启\r\n");
}
////////////////////////////////////////////////////////////////////////////
//列表更新
//更新玩家
void CZhanGuoClientDlg::UpdateActors(DWORD id, bool update)
{
//
}
//更新物品
void CZhanGuoClientDlg::UpdateBag( const _TCLIENTITEM &ci, bool isAdd )
{
//
}
//更新装备
void CZhanGuoClientDlg::UpdateUseItem(void)
{
//
}
//更新地面
void CZhanGuoClientDlg::UpdateGround( const _TDROPEDITEM &, bool )
{
//
}
//更新角色
void CZhanGuoClientDlg::UpdateSelfInfo()
{
//
}
//更新坐标
void CZhanGuoClientDlg::UpdateSelfPos()
{
//
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -