int GetAddress( BYTE& nField0, BYTE& nField1, BYTE& nField2, BYTE& nField3 );int GetAddress( DWORD& dwAddress );Return ValueThe number of non-blank fields in the IP Address Control.ParametersnField0A reference to the field 0 value from a packed IP address. nField1A reference to the field 1 value from a packed IP address.nField2A reference to the field 2 value from a packed IP address.nField3A reference to the field 3 value from a packed IP address.dwAddressA reference to the address of a DWORD value that receives the IP address. See Res for a table that shows how dwAddress is filled.ResThis member function implements the behavior of the Win32 messageIPM_GETADDRESS, as described in the Platform SDK.In the first prototype above, the numbers in fields 0 through 3 of the control, read left to right respectively, populate the four parameters. In the second prototype above, dwAddress is populated as follows.Field Bits containing the field value 0 24 through 31 1 16 through 23 2 8 through 15 3 0 through 7
m_strIp=pApp->GetProfileString("Login Information","Server Ip"); m_strUserName=pApp->GetProfileString("Login Information","User Name"); m_iPhotoNumber=pApp->GetProfileInt("Login Information","PhotoNumber",0); m_ctrCombobox.SetCurSel(m_iPhotoNumber); m_CtrIp.SetWindowText(m_strIp); UpdateData(FALSE); // TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } BOOL CDlgLoginServer::PreTranslateMessage(MSG* pMsg) { if (pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN) { if(GetFocus()->GetDlgCtrlID()!=IDOK) { NextDlgCtrl(); return TRUE; } }
0 24 through 31
1 16 through 23
2 8 through 15
3 0 through 7
void CDlgLoginServer::OnOK()
{
UpdateData(TRUE);
m_strUserName.TrimLeft();
m_strUserName.TrimRight();
if(m_strUserName.IsEmpty())
{
MessageBox("没有输入登陆用户名!");
GetDlgItem(IDC_USERNAME)->SetFocus();
}
else
{
if(m_strUserName=="所有人")
{
MessageBox("不能使用这个名字!");
m_strUserName="";
UpdateData(FALSE);
GetDlgItem(IDC_USERNAME)->SetFocus();
}
else
{
m_CtrIp.GetWindowText(m_strIp);
m_iPhotoNumber=m_ctrCombobox.GetCurSel();
CTalkClientApp* pApp=(CTalkClientApp*)AfxGetApp();
pApp->WriteProfileString("Login Information","Server Ip",m_strIp);
pApp->WriteProfileString("Login Information","User Name",m_strUserName);
pApp->WriteProfileInt("Login Information","PhotoNumber",m_iPhotoNumber);
CDialog::OnOK();
}
}
}BOOL CDlgLoginServer::OnInitDialog()
{
CDialog::OnInitDialog();
CTalkClientApp* pApp=(CTalkClientApp*)AfxGetApp();
//m_ctrCombobox.set
m_ctrCombobox.SetImageList(&(pApp->m_imgList));
COMBOBOXEXITEM insItem;
for(int i=0;i<100;i++)
{
insItem.mask=CBEIF_IMAGE|CBEIF_TEXT|CBEIF_SELECTEDIMAGE ;
insItem.iItem=i;
insItem.iImage=i;
insItem.iSelectedImage=i;
insItem.pszText="";
m_ctrCombobox.InsertItem(&insItem);
}
m_strIp=pApp->GetProfileString("Login Information","Server Ip");
m_strUserName=pApp->GetProfileString("Login Information","User Name");
m_iPhotoNumber=pApp->GetProfileInt("Login Information","PhotoNumber",0);
m_ctrCombobox.SetCurSel(m_iPhotoNumber);
m_CtrIp.SetWindowText(m_strIp);
UpdateData(FALSE);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CDlgLoginServer::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
{
if(GetFocus()->GetDlgCtrlID()!=IDOK)
{
NextDlgCtrl();
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}CString CDlgLoginServer::GetIp()
{
return (m_strIp);
}CString CDlgLoginServer::GetUserNameStr()
{
return (m_strUserName);
}int CDlgLoginServer::GetPhotoNumber()
{
return (m_iPhotoNumber);
}
BYTE nArrIP[4];
m_Ip.GetAddress(nArrIP[0],nArrIP[1],nArrIP[2],nArrIP[3]);
CString str;
str.Format("%d.%d.%d.%d",nArrIP[0],nArrIP[1],nArrIP[2],nArrIP[3]);