?? winwhois.c
字號:
#define WINDOWS
#include <windows.h>
#include <winsock.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <time.h>
#include <stdio.h>
#include <memory.h>
#include "winwhois.h"
#define NICHOST "rs.internic.net"
HANDLE hInst;
HANDLE saveinst;
char szQueryhost[128] = NICHOST;
char szHost [256];
char szServHost[128];
REQUEST FAR *HeadReq = NULL;
HANDLE hHeadReq = NULL;
HWND hDialog;
//
int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HWND hMainWindow;
saveinst = hInstance;
if (!hPrevInstance)
if (!InitApplication (hInstance))
return FALSE;
if (!InitInstance (hInstance, nCmdShow, &hMainWindow))
return FALSE;
LoadString (hInstance, IDC_WHOISLISTSERVER,
(LPSTR)szServHost, 128);
SendMessage (hMainWindow, WM_COMMAND, IDC_STARTDIALOG, 0);
while (GetMessage (&msg, 0, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return (msg.wParam);
}
BOOL InitApplication (HANDLE hInstCurrent)
{
WNDCLASS wc;
WNDCLASS windc;
memset(&windc, 0x00, sizeof(WNDCLASS));
memset(&wc, 0x00, sizeof(WNDCLASS));
windc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
windc.lpfnWndProc = QueryWndProc;
windc.cbClsExtra = 0;
windc.cbWndExtra = 0;
windc.hInstance = hInstCurrent;
windc.hIcon = LoadIcon (saveinst, "QMARK");
windc.hCursor = LoadCursor (NULL, IDC_ARROW);
windc.hbrBackground = GetStockObject (WHITE_BRUSH);
windc.lpszMenuName = NULL;
windc.lpszClassName = "PurposelessWindow";
if (!RegisterClass (&windc))
{
MessageBox (NULL, "Cannot start program",
"Whois", MB_OK|MB_ICONHAND);
return 0;
}
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstCurrent;
wc.hIcon = LoadIcon (saveinst, "QMARK");
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject (WHITE_BRUSH);
// Create brush for erasing background
wc.lpszMenuName = NULL;
wc.lpszClassName = "UselessWindow";
return (RegisterClass (&wc));
}
BOOL InitInstance (HANDLE hInstCurrent, int nCmdShow,
LPHANDLE lphMainWindow )
{
HWND hWnd;
hInst = hInstCurrent;
hWnd = CreateWindow ("UselessWindow",
"whois for Windows",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstCurrent,
NULL);
if (hWnd == NULL)
return FALSE;
*lphMainWindow = hWnd;
return TRUE;
}
LONG FAR APIENTRY MainWndProc (HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
FARPROC lpfnProcDialog;
WORD suword; WSADATA WSAData;
switch (message) {
case WM_COMMAND:
if (LOWORD(wParam) != IDC_STARTDIALOG)
return (DefWindowProc (hWnd, message, wParam, lParam));
else
{
suword = MAKEWORD (1,1);
WSAStartup (suword, &WSAData);
lpfnProcDialog = MakeProcInstance ((FARPROC) MainDialog,
hInst);
DialogBox (hInst,
"WinWhoIs",
hWnd,
lpfnProcDialog);
FreeProcInstance (lpfnProcDialog);
PostMessage (hWnd, WM_DESTROY, 0, 0);
break;
}
case WM_DESTROY:
WSACleanup ();
PostQuitMessage (0);
break;
default:
return (DefWindowProc (hWnd, message, wParam, lParam));
}
return 0;
}
BOOL FAR PASCAL ChangeHost (HWND hDlg, WORD message, WPARAM wParam, LPARAM lParam)
{
char szHost [128];
switch (message) {
case WM_INITDIALOG:
strcpy (szHost, szQueryhost);
SendDlgItemMessage (hDlg, IDC_HOSTINPUT, (UINT) WM_SETTEXT,
(WPARAM) 0,
(LPARAM) ((LPSTR) szHost));
SendDlgItemMessage (hDlg, IDC_HOSTINPUT, (UINT) EM_SETSEL,
(WPARAM) 0,
MAKELPARAM (0, -1));
SendMessage (GetDlgItem (hDlg, IDC_HOSTINPUT), EM_LIMITTEXT, 128, 0L);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_HOSTINPUT:
if (HIWORD (lParam) == EN_CHANGE) {
if (SendDlgItemMessage (hDlg, IDC_HOSTINPUT,
EM_LINELENGTH, 0, 0L))
EnableWindow (GetDlgItem (hDlg, IDC_CHANGEHOST), TRUE);
else
EnableWindow (GetDlgItem (hDlg, IDC_CHANGEHOST), FALSE);
return TRUE;
}
else return FALSE;
case IDC_CHANGEHOST:
SendDlgItemMessage (hDlg, IDC_HOSTINPUT, (UINT) WM_GETTEXT,
(WPARAM) 128,
(LPARAM) ((LPSTR) szHost));
SendDlgItemMessage (hDlg, IDC_HOSTINPUT, (UINT) EM_SETSEL,
0, MAKELPARAM (0,-1));
if (*szHost)
{
strcpy (szQueryhost, szHost);
}
else {
MessageBox (NULL, "No hostname specified!",
"WinWhoIs", MB_OK | MB_ICONHAND);
}
EndDialog (hDlg, TRUE);
return TRUE;
case IDCANCEL:
EndDialog (hDlg, TRUE);
}
}
return FALSE;
}
BOOL FAR PASCAL About (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (wParam == IDOK
|| wParam == IDCANCEL)
{
EndDialog (hDlg, TRUE);
return (TRUE);
}
break;
}
return FALSE;
}
void DoWhoIsQuery (HWND hDlg, LPSTR lpszName, LPSTR lpszQHost)
{
struct sockaddr_in;
HANDLE hWind;
REQUEST FAR *thisreq;
hWind = CreateWindow ("PurposelessWindow",
"Whois/Win query",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
hDlg,
NULL,
hInst,
NULL);
if (hWind == NULL)
{
MessageBox (NULL, "Could not start query",
"WinWhois", MB_OK|MB_ICONHAND);
return;
}
thisreq = HeadReq;
if (thisreq != NULL)
{
while (thisreq->NextReq != NULL)
{
thisreq = thisreq->NextReq;
}
thisreq->hNextReq = GlobalAlloc (GHND, sizeof (REQUEST));
thisreq->NextReq = (REQUEST FAR*)GlobalLock (thisreq->hNextReq);
thisreq = thisreq->NextReq;
}
else
{
hHeadReq = GlobalAlloc (GHND, sizeof (REQUEST));
HeadReq = (REQUEST FAR*)GlobalLock (hHeadReq);
thisreq = HeadReq;
}
thisreq->hWin = hWind;
thisreq->hHost = GlobalAlloc (GHND, 256);
thisreq->lpHost = GlobalLock (thisreq->hHost);
lstrcpy (thisreq->lpHost, lpszName);
thisreq->hQuery = GlobalAlloc (GHND, 128);
thisreq->lpQuery = GlobalLock (thisreq->hQuery);
lstrcpy (thisreq->lpQuery, lpszQHost);
thisreq->NextReq = NULL;
thisreq->hNextReq = NULL;
PostMessage (hWind, START_QUERY, 0, 0);
return;
}
BOOL FAR PASCAL MainDialog (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
hDialog = hDlg;
SendDlgItemMessage (hDlg, IDC_RESPONSES, EM_LIMITTEXT,0,0);
SendDlgItemMessage (hDlg, IDC_RESPONSES, EM_FMTLINES, 1, 0L);
EnableWindow (GetDlgItem (hDlg, IDC_MAKEQUERY), FALSE);
return TRUE;
}
case WM_CLOSE: {
EndDialog (hDlg, 0);
break;
}
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDM_ABOUT:
{
FARPROC lpfnAboutDialog;
lpfnAboutDialog = MakeProcInstance (About, hInst);
DialogBox (hInst,
"AboutBox",
hDlg,
lpfnAboutDialog);
FreeProcInstance (lpfnAboutDialog);
return TRUE;
}
case IDM_CHANGEHOST:
{
FARPROC lpfnChangeDialog;
lpfnChangeDialog = MakeProcInstance (ChangeHost, hInst);
DialogBox (hInst, "GetHostBox", hDlg, lpfnChangeDialog);
FreeProcInstance (lpfnChangeDialog);
return TRUE;
}
case IDM_CUT:
case IDM_COPY:
case IDM_CLEAR:
/* if the selection is empty, make it all... */
{
DWORD dwStartAndEnd;
WORD wStartChar;
WORD wEndChar;
dwStartAndEnd = SendDlgItemMessage (hDlg,
IDC_RESPONSES, EM_GETSEL, 0, 0L);
wStartChar = LOWORD (dwStartAndEnd);
wEndChar = HIWORD (dwStartAndEnd);
if (wStartChar == wEndChar)
{
SendDlgItemMessage (hDlg, IDC_RESPONSES,
EM_SETSEL, 0,
MAKELPARAM (0, -1));
dwStartAndEnd = SendDlgItemMessage (hDlg,
IDC_RESPONSES, EM_GETSEL, 0, 0L);
wStartChar = LOWORD (dwStartAndEnd);
wEndChar = HIWORD (dwStartAndEnd);
if (wStartChar == wEndChar)
break;
}
if (wParam == IDM_CUT)
SendDlgItemMessage (hDlg, IDC_RESPONSES,
WM_CUT, 0,0);
else if (wParam == IDM_COPY)
SendDlgItemMessage (hDlg, IDC_RESPONSES,
WM_COPY, 0, 0);
else
SendDlgItemMessage (hDlg, IDC_RESPONSES,
WM_CLEAR, 0, 0);
SetFocus (GetDlgItem (hDlg, IDC_NAMEINPUT));
return TRUE;
}
case IDC_HELP:
{
MessageBox (NULL, "Enter the name you wish to query in the "
"Name to Query field, and press return. "
"For help about whois, query on the name "
"\"help\".",
"WinWhoIs", MB_ICONINFORMATION | MB_OK);
SetFocus (GetDlgItem (hDlg, IDC_NAMEINPUT));
return TRUE;
}
case IDC_CLEAR:
ClearText (hDlg, IDC_RESPONSES);
SetFocus (GetDlgItem (hDlg, IDC_NAMEINPUT));
return TRUE;
case IDC_NAMEINPUT:
if (HIWORD (wParam) == EN_CHANGE) {
if (SendDlgItemMessage (hDlg, IDC_NAMEINPUT,
EM_LINELENGTH, 0, 0L))
EnableWindow (GetDlgItem (hDlg, IDC_MAKEQUERY),
TRUE);
else
EnableWindow (GetDlgItem (hDlg, IDC_MAKEQUERY),
FALSE);
return TRUE;
}
else
return FALSE;
case IDC_MAKEQUERY:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -