📄 pnaddwiz.c
字号:
RealizePalette (hDC);
EndPaint (hwnd, &ps);
}
break;
case PSM_QUERYSIBLINGS :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
// set default state
SendMessage (pahs->hwndIPAddress, PGP_IPM_CLEARADDRESS, 0, 0);
pahs->bIPValid = FALSE;
SendMessage (pahs->hwndSubnetMask, PGP_IPM_CLEARADDRESS, 0, 0);
pahs->bSubnetValid = FALSE;
return 0;
case WM_NOTIFY:
{
LPNMHDR pnmh = (LPNMHDR) lParam;
switch(pnmh->code) {
case PGP_IPN_INVALIDADDRESS :
case PGP_IPN_EMPTYADDRESS :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
if (pnmh->hwndFrom == pahs->hwndIPAddress)
pahs->bIPValid = FALSE;
else if (pnmh->hwndFrom == pahs->hwndSubnetMask)
pahs->bSubnetValid = FALSE;
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK);
break;
case PGP_IPN_VALIDADDRESS :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
if (pnmh->hwndFrom == pahs->hwndIPAddress)
pahs->bIPValid = TRUE;
else if (pnmh->hwndFrom == pahs->hwndSubnetMask)
pahs->bSubnetValid = TRUE;
if (pahs->bIPValid && pahs->bSubnetValid)
{
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK|PSWIZB_NEXT);
}
break;
case PSN_SETACTIVE:
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
SendDlgItemMessage (hwnd, IDC_WIZBITMAP, STM_SETIMAGE,
IMAGE_BITMAP, (LPARAM) pahs->hBitmap);
if (pahs->uHostType == WIZ_SUBNET)
{
if (pahs->bIPValid && pahs->bSubnetValid)
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK|PSWIZB_NEXT);
else
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK);
SetWindowLong (hwnd, DWL_MSGRESULT, 0L);
}
else
SetWindowLong (hwnd, DWL_MSGRESULT, -1L);
bReturnCode = TRUE;
break;
case PSN_WIZNEXT :
{
DWORD dwMask;
DWORD dwIP;
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
// get IP subnet
SendMessage (pahs->hwndSubnetMask,
PGP_IPM_GETADDRESS, 0, (LPARAM)&dwMask);
pahs->pheNew->ipMask = dwMask;
if (!PNIsSubnetMaskValid (dwMask))
{
PNMessageBox (hwnd, IDS_CAPTION, IDS_BADSUBNETMASK,
MB_OK | MB_ICONHAND);
SetWindowLong (hwnd, DWL_MSGRESULT, -1L);
bReturnCode = TRUE;
break;
}
// get IP address
SendMessage (pahs->hwndIPAddress,
PGP_IPM_GETADDRESS, 0, (LPARAM)&dwIP);
pahs->pheNew->ipAddress = dwIP;
if (PNIsHostAlreadyInList (hwnd, pahs->uHostType, dwIP, dwMask,
pahs->ppnconfig->pHostList,
pahs->ppnconfig->uHostCount, -1))
SetWindowLong (hwnd, DWL_MSGRESULT, -1L);
else
SetWindowLong (hwnd, DWL_MSGRESULT, 0L);
bReturnCode = TRUE;
break;
}
case PSN_QUERYCANCEL:
break;
}
break;
}
}
return bReturnCode;
}
// ______________________________________________
//
// Dialog procedure for asking user the IP address of host or gateway
static LRESULT WINAPI
sAddWizHostAddressDlgProc (
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
BOOL bReturnCode = FALSE;
PADDHOSTSTRUCT pahs = NULL;
switch (uMsg) {
case WM_INITDIALOG:
{
PROPSHEETPAGE* ppspMsgRec = (PROPSHEETPAGE *) lParam;
RECT rc;
pahs = (PADDHOSTSTRUCT) ppspMsgRec->lParam;
SetWindowLong (hwnd, GWL_USERDATA, (LPARAM)pahs);
// limit host name edit box text
SendDlgItemMessage (hwnd, IDC_HOSTNAME, EM_LIMITTEXT,
(WPARAM)(sizeof(pahs->szHostName)), 0);
// create IP edit control for address
GetWindowRect (GetDlgItem (hwnd, IDC_IPADDRESS), &rc);
MapWindowPoints (NULL, hwnd, (LPPOINT)&rc, 2);
pahs->hwndHostIPAddress = CreateWindowEx (
WS_EX_CLIENTEDGE,
WC_PGPIPADDRESS, "",
WS_CHILD|WS_VISIBLE|WS_TABSTOP,
rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
hwnd, NULL, g_hinst, NULL);
// set tab-order of control
SetWindowPos (pahs->hwndHostIPAddress,
GetDlgItem (hwnd, IDC_IPADDRESS),
0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
break;
}
case WM_DESTROY :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
DestroyWindow (pahs->hwndHostIPAddress);
break;
case WM_ACTIVATE :
InvalidateRect (hwnd, NULL, TRUE);
break;
case WM_PAINT :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
if (pahs->hPalette)
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint (hwnd, &ps);
SelectPalette (hDC, pahs->hPalette, FALSE);
RealizePalette (hDC);
EndPaint (hwnd, &ps);
}
break;
case PSM_QUERYSIBLINGS :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
pahs->dwFoundIPAddress = 0;
// set default state
SendMessage (pahs->hwndHostIPAddress, PGP_IPM_CLEARADDRESS, 0, 0);
SendMessage (pahs->hwndHostIPAddress,
EM_SETREADONLY, (WPARAM)FALSE, 0);
EnableWindow (pahs->hwndHostIPAddress, TRUE);
SetDlgItemText (hwnd, IDC_HOSTNAME, "");
SendDlgItemMessage (hwnd, IDC_HOSTNAME,
EM_SETREADONLY, (WPARAM)FALSE, 0);
EnableWindow (GetDlgItem (hwnd, IDC_HOSTNAME), TRUE);
return 0;
case WM_COMMAND :
{
if (LOWORD (wParam) == IDC_HOSTNAME)
{
if (HIWORD (wParam) == EN_CHANGE)
{
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
pahs->dwFoundIPAddress = 0;
if (GetWindowTextLength ((HWND)lParam) > 0)
{
SendMessage (pahs->hwndHostIPAddress, EM_SETREADONLY,
(WPARAM)TRUE, 0);
EnableWindow (pahs->hwndHostIPAddress, FALSE);
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK|PSWIZB_NEXT);
}
else
{
SendMessage (pahs->hwndHostIPAddress, EM_SETREADONLY,
(WPARAM)FALSE, 0);
EnableWindow (pahs->hwndHostIPAddress, TRUE);
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK);
}
}
}
break;
}
case WM_NOTIFY:
{
LPNMHDR pnmh = (LPNMHDR) lParam;
DWORD dw;
switch(pnmh->code) {
case PGP_IPN_EMPTYADDRESS :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
if (pnmh->hwndFrom == pahs->hwndHostIPAddress)
{
SendDlgItemMessage (hwnd, IDC_HOSTNAME, EM_SETREADONLY,
(WPARAM)FALSE, 0);
EnableWindow (GetDlgItem (hwnd, IDC_HOSTNAME), TRUE);
}
break;
case PGP_IPN_INVALIDADDRESS :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
if (pnmh->hwndFrom == pahs->hwndHostIPAddress)
{
SendDlgItemMessage (hwnd, IDC_HOSTNAME, EM_SETREADONLY,
(WPARAM)TRUE, 0);
EnableWindow (GetDlgItem (hwnd, IDC_HOSTNAME), FALSE);
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK);
}
break;
case PGP_IPN_VALIDADDRESS :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
if (pnmh->hwndFrom == pahs->hwndHostIPAddress)
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK|PSWIZB_NEXT);
break;
case PSN_SETACTIVE:
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
SendDlgItemMessage (hwnd, IDC_WIZBITMAP, STM_SETIMAGE,
IMAGE_BITMAP, (LPARAM) pahs->hBitmap);
switch (pahs->uHostType) {
case WIZ_HOST :
ShowWindow (GetDlgItem (hwnd, IDC_TEXTHOST), SW_SHOW);
ShowWindow (GetDlgItem (hwnd, IDC_TEXTGATEWAY), SW_HIDE);
SendMessage (pahs->hwndHostIPAddress,
PGP_IPM_GETADDRESS, 0, (LPARAM)&dw);
if ((dw != 0) ||
(GetWindowTextLength (
GetDlgItem (hwnd, IDC_HOSTNAME)) > 0) )
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK|PSWIZB_NEXT);
else
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK);
SetWindowLong (hwnd, DWL_MSGRESULT, 0L);
break;
case WIZ_GATEWAY :
ShowWindow (GetDlgItem (hwnd, IDC_TEXTHOST), SW_HIDE);
ShowWindow (GetDlgItem (hwnd, IDC_TEXTGATEWAY), SW_SHOW);
SendMessage (pahs->hwndHostIPAddress,
PGP_IPM_GETADDRESS, 0, (LPARAM)&dw);
if ((dw != 0) ||
(GetWindowTextLength (
GetDlgItem (hwnd, IDC_HOSTNAME)) > 0) )
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK|PSWIZB_NEXT);
else
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK);
SetWindowLong (hwnd, DWL_MSGRESULT, 0L);
break;
default :
SetWindowLong (hwnd, DWL_MSGRESULT, -1L);
break;
}
bReturnCode = TRUE;
break;
case PSN_WIZNEXT :
{
DWORD dw;
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
// get host name
GetDlgItemText (hwnd, IDC_HOSTNAME, pahs->szHostName,
sizeof(pahs->szHostName));
// else get IP address
if (pahs->szHostName[0] == 0)
SendMessage (pahs->hwndHostIPAddress,
PGP_IPM_GETADDRESS, 0, (LPARAM)&dw);
else
dw = 0;
pahs->pheNew->ipAddress = dw;
// set IP subnet
pahs->pheNew->ipMask = 0xFFFFFFFF;
if (PNIsHostAlreadyInList (hwnd, pahs->uHostType, dw, 0xFFFFFFFF,
pahs->ppnconfig->pHostList,
pahs->ppnconfig->uHostCount, -1))
SetWindowLong (hwnd, DWL_MSGRESULT, -1L);
else
SetWindowLong (hwnd, DWL_MSGRESULT, 0L);
bReturnCode = TRUE;
break;
}
case PSN_QUERYCANCEL:
break;
}
break;
}
}
return bReturnCode;
}
// ______________________________________________
//
// Dialog procedure for looking up IP and posting result
static LRESULT WINAPI
sAddWizAddressLookupDlgProc (
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
BOOL bReturnCode = FALSE;
PADDHOSTSTRUCT pahs = NULL;
switch (uMsg) {
case WM_INITDIALOG:
{
PROPSHEETPAGE* ppspMsgRec = (PROPSHEETPAGE *) lParam;
RECT rc;
pahs = (PADDHOSTSTRUCT) ppspMsgRec->lParam;
SetWindowLong (hwnd, GWL_USERDATA, (LPARAM)pahs);
// create IP edit control for address
GetWindowRect (GetDlgItem (hwnd, IDC_IPADDRESS), &rc);
MapWindowPoints (NULL, hwnd, (LPPOINT)&rc, 2);
pahs->hwndHostIPAddressLookup = CreateWindowEx (
WS_EX_STATICEDGE,
WC_PGPIPADDRESS, "",
WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_READONLY,
rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
hwnd, NULL, g_hinst, NULL);
// set tab-order of control
SetWindowPos (pahs->hwndHostIPAddressLookup,
GetDlgItem (hwnd, IDC_IPADDRESS),
0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
// disable window
EnableWindow (pahs->hwndHostIPAddressLookup, FALSE);
break;
}
case WM_TIMER :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
if (pahs->hwndThreadParent)
{
ShowWindow (GetDlgItem (hwnd, IDC_PROGRESS), SW_SHOW);
pahs->iStatusValue += pahs->iStatusDirection;
if (pahs->iStatusValue <= 0) {
pahs->iStatusValue = 0;
pahs->iStatusDirection = 1;
}
else if (pahs->iStatusValue >= NUMLEDS-1) {
pahs->iStatusValue = NUMLEDS-1;
pahs->iStatusDirection = -1;
}
InvalidateRect (hwnd, NULL, FALSE);
}
else
{
DWORD dw;
pahs->iStatusValue = -1;
pahs->iStatusDirection = 1;
pahs->hwndThreadParent = hwnd;
CreateThread (NULL, 0, sDNSLookupThread, (LPVOID)pahs, 0, &dw);
}
break;
case WM_APP :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
pahs->hwndThreadParent = NULL;
ShowWindow (GetDlgItem (hwnd, IDC_PROGRESS), SW_HIDE);
KillTimer (hwnd, TIMER_ID);
if (wParam)
{
CHAR sz1[256];
CHAR sz2[512];
ShowWindow (
GetDlgItem (hwnd, IDC_WORKING), SW_HIDE);
ShowWindow (
GetDlgItem (hwnd, IDC_IPADDRESSTEXT), SW_SHOW);
ShowWindow (
pahs->hwndHostIPAddressLookup, SW_SHOW);
SendMessage (pahs->hwndHostIPAddressLookup,
PGP_IPM_SETADDRESS, 0, (LPARAM)pahs->dwFoundIPAddress);
LoadString (g_hinst, IDS_HOSTFOUND, sz1, sizeof(sz1));
wsprintf (sz2, sz1, pahs->szHostName);
SetDlgItemText (hwnd, IDC_HOSTFOUND, sz2);
ShowWindow (GetDlgItem (hwnd, IDC_HOSTFOUND), SW_SHOW);
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK|PSWIZB_NEXT);
}
else
{
ShowWindow (
GetDlgItem (hwnd, IDC_WORKING), SW_HIDE);
ShowWindow (
GetDlgItem (hwnd, IDC_HOSTNOTFOUND), SW_SHOW);
}
break;
case WM_DESTROY :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
DestroyWindow (pahs->hwndHostIPAddressLookup);
break;
case WM_ACTIVATE :
InvalidateRect (hwnd, NULL, TRUE);
break;
case WM_PAINT :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
if (pahs->hPalette)
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint (hwnd, &ps);
SelectPalette (hDC, pahs->hPalette, FALSE);
RealizePalette (hDC);
EndPaint (hwnd, &ps);
}
sDrawSendStatus (GetDlgItem (hwnd, IDC_PROGRESS), pahs);
break;
case PSM_QUERYSIBLINGS :
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
// set default state
SendMessage (pahs->hwndHostIPAddressLookup, PGP_IPM_CLEARADDRESS, 0, 0);
SetDlgItemText (hwnd, IDC_HOSTFOUND, "");
return 0;
case WM_NOTIFY:
{
LPNMHDR pnmh = (LPNMHDR) lParam;
switch(pnmh->code) {
case PSN_SETACTIVE:
pahs = (PADDHOSTSTRUCT)GetWindowLong (hwnd, GWL_USERDATA);
SendDlgItemMessage (hwnd, IDC_WIZBITMAP, STM_SETIMAGE,
IMAGE_BITMAP, (LPARAM) pahs->hBitmap);
if ((pahs->szHostName[0] != 0) &&
(pahs->uHostType != WIZ_SUBNET))
{
if (pahs->dwFoundIPAddress == 0)
{
CHAR sz1[64];
CHAR sz2[320];
PostMessage (GetParent (hwnd),
PSM_SETWIZBUTTONS, 0, PSWIZB_BACK);
ShowWindow (
GetDlgItem (hwnd, IDC_HOSTFOUND), SW_HIDE);
ShowWindow (
GetDlgItem (hwnd, IDC_HOSTNOTFOUND), SW_HIDE);
ShowWindow (
GetDlgItem (hwnd, IDC_IPADDRESSTEXT), SW_HIDE);
ShowWindow (
pahs->hwndHostIPAddressLookup, SW_HIDE);
LoadString (g_hinst, IDS_DNSLOOKUP, sz1, sizeof(sz1));
wsprintf (sz2, sz1, pahs->szHostName);
SetDlgItemText (hwnd, IDC_WORKING, sz2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -