📄 initset.cpp
字号:
// InitSet.cpp : implementation file
//
#include "stdafx.h"
#include "ChineseChess.h"
#include "InitSet.h"
#include "ChineseChessDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInitSet dialog
CInitSet::CInitSet(CWnd* pParent /*=NULL*/)
: CDialog(CInitSet::IDD, pParent)
{
//{{AFX_DATA_INIT(CInitSet)
m_PlayerName = _T("zhou");
m_Port =8000;
//}}AFX_DATA_INIT
iGameType=0;//单机
bIsCreateGame=FALSE;
}
void CInitSet::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInitSet)
DDX_Control(pDX, IDCANCEL, m_BtnCancle);
DDX_Control(pDX, IDOK, m_BtnSure);
DDX_Control(pDX, IDC_IPADDRESS, m_IPAddress);
DDX_Control(pDX, IDC_BM_HEAD, m_Face);
DDX_Control(pDX, IDC_SCROLLBAR, m_Scroll);
DDX_Text(pDX, IDC_EDIT_PLAYERNAME, m_PlayerName);
DDX_Text(pDX, IDC_EDIT_PORT, m_Port);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInitSet, CDialog)
//{{AFX_MSG_MAP(CInitSet)
ON_BN_CLICKED(IDC_RADIO_NETBATTLE, OnRadioNetbattle)
ON_BN_CLICKED(IDC_RADIO_MANTOMACHINE, OnRadioMantomachine)
ON_BN_CLICKED(IDC_RADIO_CREATE, OnRadioCreate)
ON_BN_CLICKED(IDC_RADIO_JOIN, OnRadioJoin)
ON_WM_VSCROLL()
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_RADIO_JOINPLAYROOM, OnRadioJoinplayroom)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInitSet message handlers
void CInitSet::OnRadioNetbattle()
{
// TODO: Add your control notification handler code here
// GetDlgItem(IDC_RADIO_MANTOMACHINE)->EnableWindow(false);
iGameType=1;//二人对战
SetWindowPos(NULL,0,0,rectLarge.Width(),rectLarge.Height(),
SWP_NOMOVE | SWP_NOZORDER);
}
void CInitSet::OnRadioMantomachine()
{
// TODO: Add your control notification handler code here
//GetDlgItem(IDC_RADIO_NETBATTLE)->EnableWindow(FALSE);
SetWindowPos(NULL,0,0,rectSmall.Width(),rectSmall.Height(),
SWP_NOMOVE | SWP_NOZORDER);
}
void CInitSet::OnRadioCreate()
{
// TODO: Add your control notification handler code here
bIsCreateGame=TRUE;
GetDlgItem(IDC_IPADDRESS)->EnableWindow(false);
GetDlgItem(IDC_EDIT_PORT)->EnableWindow(false);
}
void CInitSet::OnRadioJoin()
{
// TODO: Add your control notification handler code here
bIsCreateGame=FALSE;
GetDlgItem(IDC_IPADDRESS)->EnableWindow(true);
GetDlgItem(IDC_EDIT_PORT)->EnableWindow(true);
}
BOOL CInitSet::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::Create(IDD, pParentWnd);
}
BOOL CInitSet::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_Brush[0].CreateSolidBrush(RGB(0,50,100));//Dlg
// m_Brush[1].CreateSolidBrush(RGB(255,0,0));//Button
m_Brush[2].CreateSolidBrush(RGB(0,50,100));//Static
m_nFace=0;
m_Scroll.SetScrollRange(0,6,true);//设置范围
CRect rectSeparator;
GetWindowRect(&rectLarge);
GetDlgItem(IDC_SEPARATOR)->GetWindowRect(&rectSeparator);
rectSmall.left=rectLarge.left;
rectSmall.top=rectLarge.top;
rectSmall.right=rectLarge.right;
rectSmall.bottom=rectSeparator.bottom;
SetWindowPos(NULL,0,0,rectSmall.Width(),rectSmall.Height(),
SWP_NOMOVE | SWP_NOZORDER);
m_Port=8000;
m_PlayerName="Zhou";
m_IPAddress.SetWindowText("127.0.0.1");
UpdateData(FALSE);
((CButton*)GetDlgItem(IDC_RADIO_NETBATTLE))->GetCheck();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
CScrollBar* CInitSet::GetScrollBarCtrl(int nBar) const
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::GetScrollBarCtrl(nBar);
}
void CInitSet::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
int Face[7]={IDB_FACE1,IDB_FACE2,IDB_FACE3,IDB_FACE4,IDB_FACE5,IDB_FACE6,IDB_FACE7};
if(nSBCode==SB_LINEDOWN&&m_nFace<6)
m_nFace++;
else if(nSBCode==SB_LINEUP&&m_nFace>0)
m_nFace--;
CWnd *pWnd=GetDlgItem(IDC_BM_HEAD);
CDC *pDC=pWnd->GetDC();
CChineseChessApp* pApp=(CChineseChessApp*)AfxGetApp();
CChineseChessDlg* pDlg=(CChineseChessDlg*)pApp->m_pMainWnd;
CDC* dlgDC=pDlg->GetDlgItem(IDC_B_BLACK)->GetDC();
CDC mDC;
mDC.CreateCompatibleDC(pDC);
CBitmap bmp;
bmp.LoadBitmap(Face[m_nFace]);
mDC.SelectObject(&bmp);
dlgDC->BitBlt(0,0,40,40,&mDC,0,0,SRCCOPY);
pDC->BitBlt(0,0,40,40,&mDC,0,0,SRCCOPY);
mDC.DeleteDC();
bmp.DeleteObject();
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CInitSet::OnOK()
{
// TODO: Add extra validation here
if (m_Port<=1024||m_Port>=65535)
{
AfxMessageBox("端口值应在 1024 - 65536 之间");
}
if(((CButton*)GetDlgItem(IDC_RADIO_JOIN))->GetCheck())//是客户端
{
m_IPAddress.GetWindowText(m_strIP);//获得主机IP
// m_pDlg->ConnectSocket(ipaddr,m_Port,FALSE,m_PlayerName);
}
else if(((CButton*)GetDlgItem(IDC_RADIO_CREATE))->GetCheck())//是服务器
{
// char ipaddr[20];
// m_pDlg->ConnectSocket(ipaddr,m_Port,TRUE,m_PlayerName);
}
CDialog::OnOK();
}
void CInitSet::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
HBRUSH CInitSet::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
pDC->SetBkMode(TRANSPARENT);
HBRUSH brush;
switch(nCtlColor)
{
case CTLCOLOR_DLG:
brush=m_Brush[0];
break;
case CTLCOLOR_BTN:
brush=m_Brush[1];
// pDC->SetTextColor(RGB(228,19,231));
break;
case CTLCOLOR_STATIC:
//pDC->SetBkMode(TRANSPARENT);
brush=m_Brush[2];
break;
default:
return hbr;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CInitSet::OnSetFont(CFont* pFont)
{
// TODO: Add your specialized code here and/or call the base class
//CFont
CDialog::OnSetFont(pFont);
}
void CInitSet::OnRadioJoinplayroom()
{
// TODO: Add your control notification handler code here
iGameType=2;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -