📄 gui.c
字号:
#include <windowsx.h>#include <stdio.h>#include <string.h>#include <ctype.h>#include <windows.h>#include <resolv.h>#include "res.h"#include "resource.h"//#include "gui.h"//#include "dialog.h"HINSTANCE hInstance, hInstance2;extern void PrintHelp();HWND gDlg;char *current_string;int current_lines = 0;int oldlines = 0;char current_qtype[30];char current_class[10];char current_nameserver[200];BOOLEAN nameserver_set = FALSE;BOOLEAN changing_size = FALSE;BOOLEAN locallserver = FALSE;HCURSOR hStdCursor, hWaitCursor;RECT savedlargerc, savedsmallrc;int current_servers = 1;BOOLEAN bFirst = TRUE;#define maxservers 100char szServers[MAXSERVERS][200];#define MAXTYPES 13LPSTR szTypes[MAXTYPES]={ "A", "ANY", "CNAME", "HINFO", "MX", "PX", "NS", "PTR", "SOA", "TXT", "WKS", "SRV", "NAPTR" };#define MAXROOTS 11LPSTR szRoots[MAXROOTS]={ "a.root-servers.net.", "b.root-servers.net.", "c.root-servers.net.", "d.root-servers.net.", "e.root-servers.net.", "f.root-servers.net.", "g.root-servers.net.", "h.root-servers.net.", "i.root-servers.net.", "j.root-servers.net.", "k.root-servers.net." }; #define MAXCLASSES 4LPSTR szClasses[MAXCLASSES]={ "IN", "ANY", "HESIOD", "CHAOS" }; char filestring[100000]; int selarray[5000];//HANDLE outputfile;FILE *outputfile;BOOLEAN editednameserver = FALSE;BOOLEAN editeddomain = FALSE;BOOLEAN editedquery = FALSE;BOOLEAN enlarging = FALSE;char Query [NAME_LEN];char Domain [NAME_LEN];char text[10000];char qtype[30];long current_extent = 0;void PrintToBox();long WGetListboxStringExtent(HWND hList, LPSTR psz){ TEXTMETRIC tm; HDC hDC; HFONT hFont; long wExtent; SIZE mysize; /* * Make sure we are using the correct font. */ hDC=GetDC(hList); hFont=(HFONT)SendMessage(hList, WM_GETFONT, 0, 0L); if (hFont!=NULL) SelectObject(hDC, hFont); GetTextMetrics(hDC, &tm); /* * Add one average text width to insure that we see the end of the * string when scrolled horizontally. */ GetTextExtentPoint32(hDC,psz,lstrlen(psz)+tm.tmAveCharWidth,&mysize); wExtent=mysize.cx; ReleaseDC(hList, hDC); return wExtent;}void checkhscroll(char *string) { long newextent = WGetListboxStringExtent(gDlg,string); if (newextent > current_extent) { // set it SendDlgItemMessage(gDlg, IDC_OUTPUT, LB_SETHORIZONTALEXTENT, (WPARAM)newextent,0); current_extent = newextent; } }void opentempfile(){outputfile = fopen("nslookup.tmp","w+");}void bringtoend(loc) int loc; { SendDlgItemMessage(gDlg, IDC_OUTPUT, LB_SETTOPINDEX, (DWORD)(WPARAM)loc,0); }void processtempfile(){ int count; FILE *tfile; fflush(outputfile); fclose(outputfile); tfile = fopen("nslookup.tmp","r"); count = fread(filestring,sizeof(char),100000,tfile); filestring[count] = '\0'; PrintToBox(filestring,count); PrintToBox("\n-------------------------------------------------------------------\n",0); fclose(outputfile); SetCursor(hStdCursor); opentempfile();}void process_query_button(HWND hDlg) { int i = 0; oldlines = current_lines; editedquery = FALSE; // ls command if (strncmp(Query,"ls ",3) == 0) { char option[100]; char name[200]; char cmd[10]; char dummy1[50]; char dummy2[50]; strcpy(text,"> "); strcat(text,Query); strcat(text,"\n\n"); PrintToBox(text,0); // now check if the second parameter is a -x and if so call listhostsbytype i = sscanf(Query, "%s %s %s %s %s", cmd, option, name,dummy1,dummy2); SetCursor(hWaitCursor); if ((i >= 3) && (strncmp(option,"-t",2) == 0)) ListHostsByType(Query,0); else ListHosts(Query,0); processtempfile(); } // finger command else if (strncmp(Query,"finger ",7) == 0) { strcpy(text,"> "); strcat(text,Query); strcat(text,"\n\n"); PrintToBox(text,0); SetCursor(hWaitCursor); Finger(Query,0); processtempfile(); } else // regular lookup query { strcpy(text,"> "); strcat(text,Query); strcat(text," ["); strcat(text,current_qtype); strcat(text," "); strcat(text,current_class); strcat(text,"]\n\n"); PrintToBox(text,0); SetCursor(hWaitCursor); LookupHost((char*)Query, 0); processtempfile(); } bringtoend(oldlines);}void process_domain_changes(HWND hDlg){ int i = 0; editeddomain = FALSE; i = GetDlgItemText(hDlg, IDC_DOMAIN, (LPTSTR)Domain, NAME_LEN); if (i != 0) { sprintf(Query,"do=%s",Domain); SetOption(Query); } } void process_nameserver_addition(name) char *name; { int index; int location = SendDlgItemMessage(gDlg,IDC_NAMESERVER,CB_FINDSTRING,(WPARAM)-1,(LPARAM)(LPCTSTR)name); /* add new server to array if not already in list */ if (location == CB_ERR) { // printf("*added a string to the server list = %s pos %d\n",name,current_servers); strcpy(szServers[current_servers],name); ++current_servers; } /* now reset the list */ SendDlgItemMessage(gDlg, IDC_NAMESERVER, CB_RESETCONTENT,(WPARAM)0,(LPARAM)0); index = SendDlgItemMessage (gDlg, IDC_NAMESERVER, CB_ADDSTRING, 0, (DWORD)(LPCSTR)current_nameserver); for(index=1;index<=current_servers; index++) SendDlgItemMessage(gDlg,IDC_NAMESERVER,CB_ADDSTRING,0,(LONG)(LPSTR)szServers[index-1]); SendDlgItemMessage (gDlg, IDC_NAMESERVER, CB_SETCURSEL, 0, 0); } void process_nameserver_changes(HWND hDlg){ /* lgk new code here to add old to end of list and make new one 1st */ /* first see if old server is already in the list.. if so we don't need to add it if not add it to the list before setting the new server */ int i = 0; editednameserver = FALSE; oldlines = current_lines; i = GetDlgItemText(hDlg, IDC_NAMESERVER, (LPTSTR)text, NAME_LEN); if (i != 0) { SetCursor(hWaitCursor); if (IsDlgButtonChecked(hDlg, IDC_LSERVER)) { strcpy(Query,"lserver "); strcat(Query,text); SetDefaultServer(Query,1); } else { strcpy(Query,"server "); strcat(Query,text); SetDefaultServer(Query,0); } nameserver_set = TRUE; strcpy(current_nameserver,text); process_nameserver_addition(current_nameserver); processtempfile(); bringtoend(oldlines); }}void centerdialog(HWND hDlg) { RECT rc; GetWindowRect(hDlg, &rc); SetWindowPos(hDlg, NULL, ((GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2), ((GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 2), 0, 0, SWP_NOSIZE | SWP_NOACTIVATE); }void restore_dialog(HWND hDlg, BOOLEAN large) { if (large) { SetWindowPos(hDlg,NULL,savedlargerc.left,savedlargerc.top,0,0,SWP_NOSIZE | SWP_NOACTIVATE); } else { if (savedsmallrc.left == -1) // override to center small dialog first time centerdialog(hDlg); else SetWindowPos(hDlg,NULL,savedsmallrc.left,savedsmallrc.top,0,0,SWP_NOSIZE | SWP_NOACTIVATE); } }// gets info from aboutdialogboxBOOL CALLBACK aboutDialogFunc( hDlg, uMsg, wParam, lParam)HWND hDlg;UINT uMsg;WPARAM wParam;LPARAM lParam; { switch (uMsg) { case WM_INITDIALOG: // We need to initialize stuff in the dialog box... return (TRUE); case WM_DESTROY: break; case WM_COMMAND: switch (GET_WM_COMMAND_ID(wParam, lParam)) { case IDOK: EndDialog(hDlg, TRUE); break; } default: return(FALSE); } return(TRUE);}// gets info from dialogboxBOOL CALLBACK lpDialogFunc( hDlg, uMsg, wParam, lParam)HWND hDlg;UINT uMsg;WPARAM wParam;LPARAM lParam;{ extern char rootServerName [NAME_LEN]; extern char defaultServer[NAME_LEN]; extern int queryClass; extern int queryType; extern struct __res_state _res; int tabstops = 5; int i, index, len; switch (uMsg) { case WM_INITDIALOG: // We need to initialize stuff in the dialog box... if (!changing_size) { gDlg = hDlg; // lgk new code to center dialog centerdialog(hDlg); strcpy(szServers[0],defaultServer); strcpy(current_nameserver,defaultServer); index = SendDlgItemMessage (hDlg, IDC_NAMESERVER, CB_ADDSTRING, 0, (DWORD)(LPCSTR)defaultServer); SendDlgItemMessage (hDlg, IDC_NAMESERVER, CB_SETCURSEL, 0, 0); for(index=1;index<=current_servers;index++) SendDlgItemMessage(hDlg,IDC_NAMESERVER,CB_ADDSTRING,0,(LONG)(LPSTR)szServers[index-1]); SetDlgItemText(hDlg, IDC_DOMAIN, (LPTSTR)_res.defdname); SetDlgItemInt(hDlg,IDC_PORT,nsport,FALSE); SetDlgItemInt(hDlg,IDC_RETRY,_res.retry,FALSE); SetDlgItemInt(hDlg,IDC_TIMEOUT,_res.retrans,FALSE); CheckDlgButton(hDlg,IDC_LSERVER,0); CheckDlgButton(hDlg,IDC_VC,0); CheckDlgButton(hDlg,IDC_RECURSE,1); CheckDlgButton(hDlg,IDC_IGNORE,0); SendDlgItemMessage(hDlg, IDC_OUTPUT, LB_INITSTORAGE, 10000,(DWORD) 100000); strcpy(current_qtype,"A"); strcpy(current_class,"IN"); for(index=0;index<MAXTYPES;index++) SendDlgItemMessage(hDlg,IDC_QueryType,CB_ADDSTRING,0,(LONG)(LPSTR)szTypes[index]); for(index=0;index<MAXCLASSES;index++) SendDlgItemMessage(hDlg,IDC_CLASS,CB_ADDSTRING,0,(LONG)(LPSTR)szClasses[index]); for(index=0;index<MAXROOTS;index++) SendDlgItemMessage(hDlg,IDC_ROOTSERVER,CB_ADDSTRING,0,(LONG)(LPSTR)szRoots[index]); SendDlgItemMessage (hDlg, IDC_QueryType, CB_SETCURSEL, 0, 0); SendDlgItemMessage (hDlg, IDC_CLASS, CB_SETCURSEL, 0, 0); SendDlgItemMessage (hDlg, IDC_ROOTSERVER, CB_SETCURSEL, 0, 0); opentempfile(); savedsmallrc.left = -1; } else // changing size don't reinit stuff { gDlg = hDlg; restore_dialog(hDlg,enlarging); index = SendDlgItemMessage (hDlg, IDC_NAMESERVER, CB_ADDSTRING, 0, (DWORD)(LPCSTR)current_nameserver); SendDlgItemMessage (hDlg, IDC_NAMESERVER, CB_SETCURSEL, 0, 0); for(index=1;index<=current_servers;index++) SendDlgItemMessage(hDlg,IDC_NAMESERVER,CB_ADDSTRING,0,(LONG)(LPSTR)szServers[index-1]); SetDlgItemText(hDlg, IDC_DOMAIN, (LPTSTR)_res.defdname); SetDlgItemInt(hDlg,IDC_PORT,nsport,FALSE); SetDlgItemInt(hDlg,IDC_RETRY,_res.retry,FALSE); SetDlgItemInt(hDlg,IDC_TIMEOUT,_res.retrans,FALSE); CheckDlgButton(hDlg,IDC_LSERVER,locallserver); CheckDlgButton(hDlg,IDC_VC,(_res.options & RES_USEVC)); CheckDlgButton(hDlg,IDC_DEBUG,(_res.options & RES_DEBUG)); CheckDlgButton(hDlg,IDC_RECURSE,(_res.options & RES_RECURSE)); CheckDlgButton(hDlg,IDC_D2,(_res.options & RES_DEBUG2)); CheckDlgButton(hDlg,IDC_IGNORE,(_res.options & RES_IGNTC)); SendDlgItemMessage(hDlg, IDC_OUTPUT, LB_INITSTORAGE, 10000,(DWORD) 100000); for(index=0;index<MAXTYPES;index++) SendDlgItemMessage(hDlg,IDC_QueryType,CB_ADDSTRING,0,(LONG)(LPSTR)szTypes[index]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -