📄 remwiz.c
字号:
/******************************************************************************
Copyright (c) 1995-2000 Microsoft Corporation. All rights reserved.
remwiz.c : Remote networking wizard dialogs
******************************************************************************/
// ----------------------------------------------------------------
//
// IDD_RAS_WIZ_1
// ( Enter Name and Dial/Direct/Vpn)
// |
// +-------Dial?-------> IDD_RAS_WIZ_2
// | (Enter Modem Name, have Config+TCP settings)
// | |
// | |
// | IDD_RAS_WIZ_3
// | (Enter Phone Num, Fin)
// |
// |
// |
// +-------Direct?-----> IDD_RAS_WIZ_4
// | (Enter DevName, Fin)
// | (Config + TCP Settings)
// |
// |
// |
// +-------VPN?--------> IDD_RAS_WIZ_5
// (Enter DevName, Fin)
// (Config + TCP Settings)
//
//
//
//
//
// ----------------------------------------------------------------
#include <windows.h>
#include <tchar.h>
#include "string.h"
#include "memory.h"
#include "commctrl.h"
#include "remnet.h"
#include "resource.h"
#include "ipaddr.h"
#include "tapi.h"
#include "unimodem.h"
#include "dbt.h"
PBYTE v_pDevConfig;
DWORD v_dwDevConfigSize;
DWORD Device;
BOOL v_EnteredAsAWizard;
extern BOOL v_fPortrait;
extern const TCHAR szAppName[];
extern HINSTANCE v_hInst;
#define COUNTRY_CODE_SIZE 16
WNDPROC g_pEditProc;
//
// ----------------------------------------------------------------
//
// GetRasDevices
//
// Call's RasEnumDevices() to get an array of the Ras Device names
// and types.
//
// Returns the number of devices found.
//
// NOTE: Caller is responsible for freeing the pRasDevInfo data.
//
// Example usage:
//
// dwRasDevices = GetRasDevices (&pRasDevInfo);
// for (i=0; i < dwRasDevices; i++) {
// if (!_tcscmp (pRasDevInfo[i].szDeviceType, RASDT_Modem)) {
// _tcscpy (EditItem.Entry.szDeviceName, pRasDevInfo[0].szDeviceName);
// break;
// }
// }
// if (pRasDevInfo) {
// LocalFree (pRasDevInfo);
// }
//
// ----------------------------------------------------------------
DWORD
GetRasDevices (LPRASDEVINFO *pRasDevInfo)
{
DWORD cBytes, cNumDev, dwRetVal;
*pRasDevInfo = NULL;
cBytes = 0;
cNumDev = 0;
dwRetVal = RasEnumDevices (NULL, &cBytes, &cNumDev);
if (0 == dwRetVal) {
// Allocate a buffer
*pRasDevInfo = (LPRASDEVINFO) LocalAlloc (LPTR, cBytes);
if (pRasDevInfo) {
dwRetVal = RasEnumDevices (*pRasDevInfo, &cBytes, &cNumDev);
} else {
DEBUGMSG (ZONE_ERROR, (TEXT("Error %d doing LocalAlloc of RasDev's\r\n"),
GetLastError()));
LocalFree (*pRasDevInfo);
*pRasDevInfo = NULL;
cNumDev = 0;
}
} else {
DEBUGMSG (ZONE_ERROR, (TEXT("Error %d from RasEnumDevices()\r\n"), dwRetVal));
cNumDev = 0;
}
#ifdef DEBUG
DEBUGMSG (1, (TEXT("GetRasDevices: Found %d devices\r\n"), cNumDev));
for (cBytes=0; cBytes < cNumDev; cBytes++) {
DEBUGMSG (1, (TEXT("\tDev[%d] : Name='%s' Type='%s'\r\n"),
cBytes,
(*pRasDevInfo)[cBytes].szDeviceName,
(*pRasDevInfo)[cBytes].szDeviceType));
}
#endif
return cNumDev;
}
LONG EditFullWidthConversionSubclassProc(
HWND hwnd,
UINT nMsg,
WPARAM wparam,
LPARAM lparam)
{
TCHAR ch, chHW;
ASSERT (g_pEditProc);
switch(nMsg)
{
case WM_CHAR:
ch = (TCHAR)wparam;
LCMapString(LOCALE_USER_DEFAULT, LCMAP_HALFWIDTH,
&ch, 1, &chHW, 1);
wparam = (WPARAM)chHW;
break;
}
return CallWindowProc(g_pEditProc, hwnd, nMsg, wparam, lparam);
}
BOOL
GetDialUpSettings(HWND hDlg, TCHAR CountryCode[], BOOL Validate)
{
TCHAR *pGet, *pPut;
TCHAR szTemp[128];
UINT szTempSize = sizeof(szTemp) / sizeof(TCHAR);
TCHAR szFmtStr[128];
UINT cFmtStrSize = sizeof(szFmtStr) / sizeof(TCHAR);
// Area code
GetWindowText (GetDlgItem (hDlg, IDC_AREA_CODE),
EditItem.Entry.szAreaCode,
RAS_MaxAreaCode+1);
// Phone Number
GetWindowText (GetDlgItem (hDlg, IDC_PHONE_NUM),
EditItem.Entry.szLocalPhoneNumber,
RAS_MaxPhoneNumber+1);
// trim white space in phone number
pGet = pPut = EditItem.Entry.szLocalPhoneNumber;
while (*pPut != TEXT('\0'))
{
if (*pGet != TEXT(' '))
*pPut++ = *pGet;
pGet++;
}
if (Validate)
{
// Validate Phone...
if (TEXT('\0') == EditItem.Entry.szLocalPhoneNumber[0]) {
LoadString(v_hInst, IDS_PHONEREQ, szFmtStr, cFmtStrSize);
LoadString(v_hInst, (v_fPortrait) ? IDS_CONNECTIONS : IDS_REMNET, szTemp, szTempSize);
MessageBox (hDlg, szFmtStr, szTemp, MB_OK | MB_ICONWARNING);
// Will this make it blink?
SetFocus(GetDlgItem(hDlg, IDC_PHONE_NUM));
return FALSE;
}
}
// Country Code
GetWindowText (GetDlgItem (hDlg, IDC_COUNTRY),
CountryCode,
COUNTRY_CODE_SIZE);
if (CountryCode[0] == TEXT('\0'))
EditItem.Entry.dwCountryCode = 0;
else
EditItem.Entry.dwCountryCode = My_atoi(CountryCode);
// Country code check box
if (SendMessage(GetDlgItem(hDlg, IDC_FORCELD),
BM_GETCHECK, 0, 0)) {
EditItem.Entry.dwfOptions |= RASEO_UseCountryAndAreaCodes;
} else {
EditItem.Entry.dwfOptions &= ~(RASEO_UseCountryAndAreaCodes);
}
if (SendMessage(GetDlgItem(hDlg, IDC_FORCELOCAL),
BM_GETCHECK, 0, 0)) {
EditItem.Entry.dwfOptions |= RASEO_DialAsLocalCall;
} else {
EditItem.Entry.dwfOptions &= ~(RASEO_DialAsLocalCall);
}
// -- if they have checked the force local checkbox, make sure they have entered an area code
if (Validate)
{
if ((EditItem.Entry.dwfOptions & RASEO_DialAsLocalCall) &&
(TEXT('\0') == EditItem.Entry.szAreaCode[0]))
{
LoadString(v_hInst, IDS_AREAREQ, szFmtStr, cFmtStrSize);
LoadString(v_hInst, (v_fPortrait) ? IDS_CONNECTIONS : IDS_REMNET, szTemp, szTempSize);
MessageBox (hDlg, szFmtStr, szTemp, MB_OK | MB_ICONWARNING);
// Will this make it blink?
SetFocus(GetDlgItem(hDlg, IDC_AREA_CODE));
return FALSE;
}
}
return TRUE;
}
void
FixButtons(HWND hDlg, DWORD Dialog_IDD)
{
LONG dwStyle;
TCHAR szFmtStr[128];
UINT cFmtStrSize = sizeof(szFmtStr) / sizeof(TCHAR);
if (!v_EnteredAsAWizard)
{
dwStyle = GetWindowLong(hDlg, GWL_STYLE);
SetWindowLong(hDlg, GWL_STYLE, dwStyle | WS_SYSMENU);
dwStyle = GetWindowLong(hDlg, GWL_EXSTYLE);
SetWindowLong(hDlg, GWL_EXSTYLE, dwStyle | WS_EX_CAPTIONOKBTN);
// Not a wizard, so hide buttons
ShowWindow(GetDlgItem(hDlg, IDBACK), SW_HIDE);
ShowWindow(GetDlgItem(hDlg, IDFINISH), SW_HIDE);
// Rename dialog title
if (Dialog_IDD == v_DialogPages[DLG_PG_2])
{
LoadString(v_hInst, IDS_DIALUPTITLE, szFmtStr, cFmtStrSize);
SetWindowText(hDlg, szFmtStr);
}
if (Dialog_IDD == v_DialogPages[DLG_PG_4])
{
LoadString(v_hInst, IDS_DIRECTTITLE, szFmtStr, cFmtStrSize);
SetWindowText(hDlg, szFmtStr);
}
if (Dialog_IDD == v_DialogPages[DLG_PG_5])
{
LoadString(v_hInst, IDS_VPNTITLE, szFmtStr, cFmtStrSize);
SetWindowText(hDlg, szFmtStr);
}
}
}
VOID
NextPage (HWND hDlg, DWORD NextPage)
{
LV_ITEM lvi;
if (0 == NextPage) {
RasSetEntryProperties (NULL, EditItem.EntryName,
&(EditItem.Entry),
sizeof(EditItem.Entry), v_pDevConfig, v_dwDevConfigSize);
// Refresh the list?
InitListViewItems(v_hListWnd);
// Set this one as the selected one.
ListView_SetItemState (v_hListWnd, 0, 0, LVIS_SELECTED|LVIS_FOCUSED);
for (lvi.iItem = -1;
(-1 != (lvi.iItem = ListView_GetNextItem(v_hListWnd,
lvi.iItem, LVNI_ALL)));) {
if (0 == lvi.iItem) {
continue;
}
lvi.iSubItem = 0;
lvi.mask = LVIF_PARAM;
ListView_GetItem(v_hListWnd, &lvi);
if (!_tcscmp (EditItem.EntryName,
((PITEMINFO)lvi.lParam)->EntryName)) {
ListView_SetItemState (v_hListWnd,
lvi.iItem,
LVIS_SELECTED|LVIS_FOCUSED,
LVIS_SELECTED|LVIS_FOCUSED);
break;
}
}
// Peform Abort cleanup.
NextPage = (DWORD)-1;
}
if ((DWORD)-1 == NextPage) {
// Cancel...
// Free the Device config info
if (v_pDevConfig) {
LocalFree (v_pDevConfig);
v_pDevConfig = NULL;
v_dwDevConfigSize = 0;
}
// Bring the SIP down
PositionSIP(SIP_DOWN);
DestroyWindow (hDlg);
SetFocus (v_hListWnd);
v_hDialogWnd = NULL;
return;
}
// Must have a new page to display
v_hDialogWnd = CreateDialog (v_hInst,
MAKEINTRESOURCE(NextPage), v_hMainWnd,
ConnWizDlgProc);
DestroyWindow (hDlg);
}
VOID
DoNext (HWND hDlg)
{
DWORD i;
TCHAR szTemp[128];
TCHAR szFmtStr[128];
int nFormatId;
LPRASDEVINFO pRasDevInfo;
DWORD dwRasDevices;
if (v_WizDialog == v_DialogPages[DLG_PG_1]) {
// Validate the input.
GetWindowText (GetDlgItem (hDlg, IDC_REMNAME),
EditItem.EntryName, RAS_MaxEntryName+1);
if (i = RasValidateEntryName(NULL, EditItem.EntryName)) {
if (i == ERROR_ALREADY_EXISTS) {
nFormatId = IDS_ALREADY_EXISTS;
} else if (*EditItem.EntryName) {
nFormatId = IDS_BADNAME;
} else {
nFormatId = IDS_NULLNAME;
}
SetFocus (GetDlgItem(hDlg, IDC_REMNAME));
LoadString(v_hInst, nFormatId, szFmtStr, sizeof(szFmtStr) / sizeof(TCHAR));
LoadString(v_hInst, (v_fPortrait) ? IDS_CONNECTIONS : IDS_REMNET, szTemp,
sizeof(szTemp) / sizeof(TCHAR));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -