turn TRUE;
}
void CMy001Dlg::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 mo
del,
// this is
automatically done for you by the framework.
void CMy001Dlg::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 CMy001Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy001Dlg::OnOK()
{
}
void CMy001Dlg::OnCancel()
{
CDialog::OnCancel();
}
void CMy001Dlg::OnConnect()
{
CString port;
m_ServerPort.GetWindowText(port);
CString name;
m_ServerName.Get
WindowText(name);
if (port.IsEmpty()|| name.IsEmpty())
{
MessageBox("请设置
服务器信息");
return;
}
//设置非阻塞方式连接
unsigned long flag = 1;
ioctlsocket(m_
ClientSocket, FIONBIO, (unsigned long*)&flag);
sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(atof(port));
addr.sin_addr.S_un.S_addr = inet_addr(name);
connect(m_ClientSocket,(sockaddr*)&addr,sizeof(addr));
struct tim
eval timeout ;
fd_set sets;
FD_ZERO(&sets);
FD_SET(m_ClientSocket, &sets);
timeout.tv_sec = 1; //连接超时15秒
timeout.tv_usec =0;
int result = select(0, 0, &sets, 0, &timeout);
if (result <=0)
{
MessageBox("连接超时");
}
else
{
MessageBox("
连接成功");
}
//设置阻塞方式连接
flag =0;
ioctlsocket(m_ClientSocket, FIONBIO, (unsigned long*)&flag);
}
BOOL CMy001Dlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message==CM_SOCKETMESSAGE)
{
OnAccept();
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
//接受
客户端的连接
void CMy001Dlg::On
Accept()
{
m_AcceptSocket = accept(m_ServerSocket,NULL,NULL);
}