记性不好,免得每次查找。
窗口居中
int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
SetWindowPos(NULL,cx/2 - 140,cy/2-125,280,205,0);
改变窗口大小
CRect rt;
GetClientRect(&rt);
if (rt.Height() <= 205)
{
GetWindowRect(&rt);
SetWindowPos(NULL,rt.left,rt.top,280,250,0);
}
else
{
GetWindowRect(&rt);
SetWindowPos(NULL,rt.left,rt.top,280,205,0);
}
写ini
::WritePrivateProfileString(_T("login"),_T("savepwd"),_T("1"),_T("D:\\cfg.ini"));
整形当做str写
读ini
CString strIP;
::GetPrivateProfileString(_T("login"),_T("ip0"),_T("255.255.255.255"),strIP.GetBuffer(20),20,_T("D:\\cfg.ini"));
int autoLogin =::GetPrivateProfileInt(_T("login"),_T("autologin"),0,_T("D:\\cfg.ini"));
设置文本框密码格式
edit->SetPasswordChar('*');
edit->SetPasswordChar(0);
edit->RedrawWindow(NULL,NULL);//切记
//将CString 型IP地址在IPAddressCtrl中显示
CString strIP=
"192.168.0.10"
;
DWORD
dwIP;
dwIP = inet_addr(strIP);
unsigned
char
*pIP = (unsigned
char
*)&dwIP;
m_ipAddr.SetAddress(*pIP, *(pIP+1), *(pIP+2), *(pIP+3));
//将IPAddressCtrl中的IP地址获得并转换成CString型
unsigned
char
*pIP;
CString strIP;
DWORD
dwIP;
m_ipAddr.GetAddress(dwIP);
pIP = (unsigned
char
*)&dwIP;
strIP.Format(
"%u.%u.%u.%u"
,*(pIP+3), *(pIP+2), *(pIP+1), *pIP);