主要代码如下:
void CBDlg::OnButton1()
{
DEVMODE dm;
dm.dmSize = sizeof(DEVMODE) ;
EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dm);
if(dm.dmPelsHeight!=768||dm.dmPelsWidth!=1024)
{
// if(AfxMessageBox("为了达到最好的显示效果,建议您使用1024*768的分辨率,确定吗?",MB_YESNO)==IDYES)
{
LONG result;
dm.dmBitsPerPel = 16;
dm.dmPelsHeight = 768;
dm.dmPelsWidth = 1024;
dm.dmDisplayFrequency=85;
dm.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFREQUENCY;
result = ChangeDisplaySettings(&dm,0);
}
CDialog::OnOK();
}
}
void CBDlg::OnButton3()
{
DEVMODE dm;
dm.dmSize = sizeof(DEVMODE) ;
EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dm);
if(dm.dmPelsHeight!=600||dm.dmPelsWidth!=800)
{
// if(AfxMessageBox("为了达到最好的显示效果,建议您使用800*600的分辨率,确定吗?",MB_YESNO)==IDYES)
{
LONG result;
dm.dmBitsPerPel = 16;
dm.dmPelsHeight = 600;
dm.dmPelsWidth = 800;
dm.dmDisplayFrequency=85;
dm.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFREQUENCY;
result = ChangeDisplaySettings(&dm,0);
}
CDialog::OnOK();
}
}
void CBDlg::OnButton2()
{
this->RAS_Close();
this->RAS_Connect("校园网","free@free","free");
CDialog::OnOK();
}
void CBDlg::OnButton4()
{
this->RAS_Close();
this->RAS_Connect("外网","8619944745", "189479");
CDialog::OnOK();
}
void CBDlg::RAS_Connect(LPSTR lpszEntryName, LPSTR lpszUserName, LPSTR lpszPassword)
{
HRASCONN hRasConn = NULL;
RASDIALPARAMS rdParams; //拨号连接的信息
ZeroMemory(&rdParams, sizeof(RASDIALPARAMS));
rdParams.dwSize = sizeof(RASDIALPARAMS);
lstrcpy(rdParams.szEntryName, lpszEntryName); //连接名
lstrcpy(rdParams.szUserName, lpszUserName); //用户名
lstrcpy(rdParams.szPassword, lpszPassword); //密码
::RasDial(NULL, NULL, &rdParams, 0L, NULL , &hRasConn); //如果函数成功,则返回0
RASPPPIP raspppip; //获取拨号连接的IP地址
raspppip.dwSize=sizeof(RASPPPIP);
DWORD cb=sizeof(RASPPPIP);
::RasGetProjectionInfo(hRasConn,RASP_PppIp,&raspppip,&cb);
// MessageBox((CString)raspppip.szIpAddress);
}
void CBDlg::RAS_Close()
{
RASCONN ras[20];
DWORD dwSize, dwNumber, dwCount;
ras[0].dwSize=sizeof(RASCONN);
dwSize =sizeof(ras);
if (::RasEnumConnections(ras, &dwSize, &dwNumber)==0)
for (dwCount=0; dwCount
break;
}
BOOL CBDlg::GetConnectState()
{
LPRASCONN lpRasConn = NULL;
DWORD cbBuf = 0;
DWORD cConn = 0;
DWORD dwRet = 0;
HRASCONN hrasconn;
RASCONNSTATUS rasStatus;
UINT ndx;
// enumerate connections
cbBuf = sizeof(RASCONN);
if ( (lpRasConn = ( LPRASCONN ) malloc((UINT)cbBuf)) != NULL)
{
lpRasConn->dwSize = sizeof( RASCONN );
dwRet = RasEnumConnections( lpRasConn, &cbBuf, &cConn );
for (ndx = 0; ndx < cConn; ndx++)
{
// get to HRASCONN
hrasconn = lpRasConn[ndx].hrasconn;
// get connection status
rasStatus.dwSize = sizeof(RASCONNSTATUS);
dwRet = RasGetConnectStatus( hrasconn, &rasStatus );
if ( dwRet )
return 0;
else
{
if (rasStatus.rasconnstate == RASCS_Connected)
return 1;
else return 0;
}
}
}
else
{
return 0;
}
}