📄 connectdlg.cpp
字号:
// ConnectDlg.cpp : implementation file
//
#include "stdafx.h"
#include "WeiQiClient.h"
#include "ConnectDlg.h"
#include "Client.h"
#include "WeiQiSocket.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CConnectDlg dialog
CConnectDlg::CConnectDlg(CClient* pClient,CWnd* pParent /*=NULL*/)
: CDialog(CConnectDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CConnectDlg)
m_IPEdit = _T("");
m_PortEdit = 0;
//}}AFX_DATA_INIT
m_pClient=pClient;
}
void CConnectDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CConnectDlg)
DDX_Text(pDX, IDC_EDIT_IP, m_IPEdit);
DDX_Text(pDX, IDC_EDIT_PORT, m_PortEdit);
DDX_Control(pDX,IDC_BUTTON_CONNECT,m_ConnectButton);
DDX_Control(pDX,IDC_BUTTON_CANCEL,m_ExitButton);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CConnectDlg, CDialog)
//{{AFX_MSG_MAP(CConnectDlg)
ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
ON_BN_CLICKED(IDOK, OnButtonConnect)
ON_BN_CLICKED(IDC_BUTTON_CONNECT, OnButtonConnect)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConnectDlg message handlers
void CConnectDlg::OnButtonCancel()
{
// TODO: Add your control notification handler code here
OnCancel();
}
void CConnectDlg::OnButtonConnect()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CWeiQiSocket* pSocket=new CWeiQiSocket(m_pClient);
if(pSocket->Create())
{
if(pSocket->Connect((LPCSTR)m_IPEdit,m_PortEdit))
m_pClient->m_pSocket=pSocket;
else
{
MessageBox(_T("连接服务器失败"));
delete pSocket;
m_ConnectButton.Restart();
return;
}
}
else
{
MessageBox(_T("创建Socket失败"));
delete pSocket;
m_ConnectButton.Restart();
return;
}
OnOK();
}
BOOL CConnectDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_ConnectButton.LoadButtonBmp(IDB_BITMAPCONNECT1,IDB_BITMAPCONNECT2,IDB_BITMAPCONNECT3,IDB_BITMAPCONNECTBK);
m_ExitButton.LoadButtonBmp(IDB_BITMAPEXIT1,IDB_BITMAPEXIT2,IDB_BITMAPEXIT3,IDB_BITMAPCONNECTBK);
m_Tip.Create(this);
m_Tip.AddTool(&m_ConnectButton,_T("连接"));
m_Tip.AddTool(&m_ExitButton,_T("退出"));
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CConnectDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
m_Tip.RelayEvent(pMsg);
if(pMsg->message==WM_KEYDOWN&&pMsg->wParam==13)
{
OnButtonConnect();
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -