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.用这个获取指定子窗口,以便对其设置状
Use the GetLocalName method to retrieve the local name of the file.
The gethostname function returns the standard host name for the local machine.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;
}