WEB开发网
开发学院软件开发VC 用VC编写C/S消息传送程序 阅读

用VC编写C/S消息传送程序

 2008-11-14 19:37:11 来源:WEB开发网   
核心提示: 6.在程序菜单项中添加"本机IP地址":void CServerView::OnIp(){int WSAReturn;WSAReturn=WSAStartup( 0x0101, &WSAData );if( WSAReturn == 0 ){gethostname( H

6.在程序菜单项中添加"本机IP地址":

void CServerView::OnIp()
{
 int WSAReturn;
 WSAReturn=WSAStartup( 0x0101, &WSAData );
 if( WSAReturn == 0 ){
  gethostname( Hostname, 260 );
  struct hostent *pHostEnt;
  pHostEnt = gethostbyname( Hostname);
  if( pHostEnt != NULL ){
   wsprintf( Hostaddress, "%d.%d.%d.%d", ( pHostEnt->h_addr_list[0][0] & 0x00ff ),
     ( pHostEnt->h_addr_list[0][1] & 0x00ff ),
     ( pHostEnt->h_addr_list[0][2] & 0x00ff ),
     ( pHostEnt->h_addr_list[0][3] & 0x00ff ) );
   CString out;
   out.Format(Hostaddress);
   AfxMessageBox(out);
  }
 }
}

7.在程序菜单中添加"发送消息":

void CServerView::OnSendmessage()
{
 // TODO: Add your command handler code here
 char msg[2000];
 Csend Sendmessage;
 if(Sendmessage.DoModal() ==IDOK&&!Sendmessage.m_Message.IsEmpty())
 {
  wsprintf(msg,"R: "+Sendmessage.m_Message);
  sendto(m_sock,msg,1024,0,(PSOCKADDR)&saClnt,saClntLen);
  m_data[count++]=Sendmessage.m_Message;
  flag=TRUE;
  InvalidateRect(NULL);
 }
}

8.为发送消息项添加一个对话框的类,名为send,有一个文本框,用来发送消息.并为文本框添加CString m_Message 变量,并在ServerView.cpp中添加#include "send.h"

上一页  1 2 3 4 5 6  下一页

Tags:VC 编写 消息

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接