Class CSocket derives from CAsyncSocket and inherits its
encapsulation of the Windows Sockets
API,因此这个软件使用的是异步(非阻塞)方式实现文件的传输

相信QQ2004大家玩过吧!其中对好友的IP和哪个地方的显示是不是很爽的啊。哪就跟我来让我看来看究竟。以下为实现原理。

CWindow::GetDlgItem

This method retrieves the specified child window.

The GetDlgItem method only works for immediate child controls of a
dialog box—it does not search through nested dialog
boxes.用这个获取指定子窗口,以便对其设置状

澳门新萄京官方网站,==========================================

   首先载入Winsock动态库,代码如下:

Use the GetLocalName method to retrieve the local name of the file.

The gethostname function returns
the standard host name for the local machine.

int CIPAddressDlg::StartUp()
{

GetLocalHostAddressesRetrieves the local addresses being used to host the session.

The gethostbyname function retrieves host information corresponding
to a host name from a host database.
首先载入Winsock动态库,代码如下:

int CIPAddressDlg::StartUp()
{
 WORD wVersionRequested;
 WSADATA wsaData;
 int err;

 wVersionReuqested=MAKEWORD(2,0);
 err=WSAStartup(wVersionReuqested, &wsaData);
 if(err!=0)
 {
  return err;
 }
 if(LOBYTE(wsaData.wVersion)!=2||HIBYTE(wsaData.wVersion)!=0)
 {
  WSACleanup();
  return WSAVERNOTSUPPORTED;
 }
 return 0;
}
 

  以下的GetLocalHostName()函数为现实获取计算机名称,

int CIPAddressDlg::GetLocalHostName(CString&sHostName)
{
 char szHostName[256];
 int nRectCode;
 nRectCode=gethostname(szHostName,sizeofa(szHostName));
 if(nRectCode!=0)
 {
  sHostName=_T(“Not available”);
  return WSAGetLastError();
 }
 sHostName=szHostName;
 return 0;
}

  然后调用GetIPAddress来获取IP地址

int CIPAddressDlg::GetIPAddress(const CString& sHostName,
CString&sIPAddress)
{
 struct hostent FAR *lpHostEnt=gethostbyname(sHostName);
 if(lpHostEnt==NELL)
 {
  sIPAddress=_T(“”);
  return WSAGetLastError();
 }
 LPSTR lpAddr=lpHostEnt->h_adr_list[0];
 if(lpAddr)
 {
  struct in_addr inAddr;
  memmove (&inAddr,lpAddr, 4);
  sIPAddress=inet_ntoa (inAddr);
  if(sIPAddress.IsEmpty())
   sIPAddress=_T(“Not available”);
 }
 return 0;
}

  WORD wVersionRequested;
  WSADATA wsaData;
  int err;

  wVersionReuqested = MAKEWORD(2, 0);
  err = WSAStartup(wVersionReuqested, &wsaData);

  if (err != 0)
  {
    return err;
  }
  if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 0)
  {
    WSACleanup();
    return WSAVERNOTSUPPORTED;
  }
  return 0;
}

以下的GetLocalHostName()函数为现实获取计算机名称,

int CIPAddressDlg::GetLocalHostName(CString &sHostName)
{

  char szHostName[256];

  int nRectCode;

  nRectCode = gethostname(szHostName, sizeofa(szHostName));

  if (nRectCode != 0)

  {

    sHostName = _T(“Not available”);

    return WSAGetLastError();

  }

  sHostName = szHostName;

  return 0;

网站地图xml地图